Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

entities update and format some files

Yevhenii Kulisidi599d19a38f11
diff --git a/src/analytics/analytics.service.ts b/src/analytics/analytics.service.ts
index a84724908..eafed64b0 100644
--- a/src/analytics/analytics.service.ts
+++ b/src/analytics/analytics.service.ts
@@ -34,7 +34,10 @@ import {
isSelfhosted,
REDIS_SESSION_SALT_KEY,
} from '../common/constants'
-import { getProjectsClickhouse, calculateRelativePercentage } from '../common/utils'
+import {
+ getProjectsClickhouse,
+ calculateRelativePercentage,
+} from '../common/utils'
import { PageviewsDTO } from './dto/pageviews.dto'
import { EventsDTO } from './dto/events.dto'
import { ProjectService } from '../project/project.service'
@@ -464,7 +467,10 @@ export class AnalyticsService {
thisWeekUnique,
lastWeekUnique,
percChange: calculateRelativePercentage(lastWeekPV, thisWeekPV),
- percChangeUnique: calculateRelativePercentage(lastWeekUnique, thisWeekUnique),
+ percChangeUnique: calculateRelativePercentage(
+ lastWeekUnique,
+ thisWeekUnique,
+ ),
}
} catch {
throw new InternalServerErrorException(
diff --git a/src/app.module.ts b/src/app.module.ts
index 8dc843b9a..5697ffc35 100644
--- a/src/app.module.ts
+++ b/src/app.module.ts
@@ -23,10 +23,12 @@ import { MarketplaceModule } from './marketplace/marketplace.module'
import { Category } from './marketplace/categories/category.entity'
import { Extension } from './marketplace/extensions/extension.entity'
-const entities = [User, ActionToken, Project, ProjectShare, Category]
+let entities = []
if (process.env.ACTIVATE_MARKETPLACE) {
- entities.push(Extension)
+ entities = [User, ActionToken, Project, ProjectShare, Extension, Category]
+} else {
+ entities = [User, ActionToken, Project, ProjectShare]
}
const modules = [
diff --git a/src/common/utils.ts b/src/common/utils.ts
index 3b8148a1e..727343714 100644
--- a/src/common/utils.ts
+++ b/src/common/utils.ts
@@ -117,7 +117,6 @@ const updateProjectClickhouse = async (project: object) => {
return await clickhouse.query(query).toPromise()
}
-
/**
* Calculates in percent, the change between 2 numbers.
* e.g from 1000 to 500 = 50%
@@ -145,7 +144,11 @@ const getPercentageChange = (oldVal: number, newVal: number, round = 2) => {
* @param newVal The value that changed
* @param round Numbers after floating point
*/
-const calculateRelativePercentage = (oldVal: number, newVal: number, round = 2) => {
+const calculateRelativePercentage = (
+ oldVal: number,
+ newVal: number,
+ round = 2,
+) => {
if (oldVal === newVal) return 0
if (oldVal === 0) return 100
if (newVal === 0) return -100
diff --git a/src/marketplace/categories/category.entity.ts b/src/marketplace/categories/category.entity.ts
index 8b966306e..359ef29a3 100644
--- a/src/marketplace/categories/category.entity.ts
+++ b/src/marketplace/categories/category.entity.ts
@@ -1,4 +1,11 @@
-import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'
+import {
+ Column,
+ Entity,
+ JoinTable,
+ ManyToMany,
+ PrimaryGeneratedColumn,
+} from 'typeorm'
+import { Extension } from '../extensions/extension.entity'
@Entity()
export class Category {
@@ -10,4 +17,8 @@ export class Category {
@Column({ type: 'text', nullable: true, default: null })
description!: string | null
+
+ @ManyToMany(() => Extension, extension => extension.categories)
+ @JoinTable()
+ extensions: Extension[]
}
diff --git a/src/marketplace/extensions/extension.entity.ts b/src/marketplace/extensions/extension.entity.ts
index 83fb510bc..cc8b7af39 100644
--- a/src/marketplace/extensions/extension.entity.ts
+++ b/src/marketplace/extensions/extension.entity.ts
@@ -40,7 +40,7 @@ export class Extension {
@UpdateDateColumn()
updatedAt: Date
- @ManyToMany(() => Category)
+ @ManyToMany(() => Category, category => category.extensions)
@JoinTable()
categories: Category[]
}