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!

Revert "(marketplace - extensions) adding and updating extension categories"

Andrii Rd1560ad4a05d
diff --git a/src/analytics/analytics.service.ts b/src/analytics/analytics.service.ts
index eafed64b0..a84724908 100644
--- a/src/analytics/analytics.service.ts
+++ b/src/analytics/analytics.service.ts
@@ -34,10 +34,7 @@ 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'
@@ -467,10 +464,7 @@ 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 5697ffc35..8dc843b9a 100644
--- a/src/app.module.ts
+++ b/src/app.module.ts
@@ -23,12 +23,10 @@ import { MarketplaceModule } from './marketplace/marketplace.module'
import { Category } from './marketplace/categories/category.entity'
import { Extension } from './marketplace/extensions/extension.entity'
-let entities = []
+const entities = [User, ActionToken, Project, ProjectShare, Category]
if (process.env.ACTIVATE_MARKETPLACE) {
- entities = [User, ActionToken, Project, ProjectShare, Extension, Category]
-} else {
- entities = [User, ActionToken, Project, ProjectShare]
+ entities.push(Extension)
}
const modules = [
diff --git a/src/common/utils.ts b/src/common/utils.ts
index 727343714..3b8148a1e 100644
--- a/src/common/utils.ts
+++ b/src/common/utils.ts
@@ -117,6 +117,7 @@ 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%
@@ -144,11 +145,7 @@ 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/categories.controller.ts b/src/marketplace/categories/categories.controller.ts
index 6f6992a81..d24673d34 100644
--- a/src/marketplace/categories/categories.controller.ts
+++ b/src/marketplace/categories/categories.controller.ts
@@ -25,6 +25,7 @@ import { GetAllCategoriesQueries } from './dtos/get-all-categories-queries.dto'
import { GetCategoryParams } from './dtos/get-category-params.dto'
import { UpdateCategoryParams } from './dtos/update-category-params.dto'
import { UpdateCategory } from './dtos/update-category.dto'
+import { ISaveCategory } from './interfaces/save-category.interface'
import { BodyValidationPipe } from '../common/pipes/body-validation.pipe'
@ApiTags('categories')
@@ -75,10 +76,7 @@ export class CategoriesController {
})
@Get(':categoryId')
async getCategory(@Param() params: GetCategoryParams): Promise<Category> {
- const category = await this.categoriesService.findOne({
- where: { id: params.categoryId },
- relations: ['extensions'],
- })
+ const category = await this.categoriesService.findById(params.categoryId)
if (!category) {
throw new NotFoundException('Category not found.')
@@ -90,7 +88,9 @@ export class CategoriesController {
@UseGuards(RolesGuard)
@Roles(UserType.ADMIN)
@Post()
- async createCategory(@Body() body: CreateCategory): Promise<Category> {
+ async createCategory(
+ @Body() body: CreateCategory,
+ ): Promise<ISaveCategory & Category> {
const title = await this.categoriesService.findTitle(body.title)
if (title) {
@@ -98,12 +98,8 @@ export class CategoriesController {
}
const categoryInstance = this.categoriesService.create(body)
- const createdCategory = await this.categoriesService.save(categoryInstance)
- return await this.categoriesService.findOne({
- where: { id: createdCategory.id },
- relations: ['extensions'],
- })
+ return await this.categoriesService.save(categoryInstance)
}
@ApiParam({
diff --git a/src/marketplace/categories/category.entity.ts b/src/marketplace/categories/category.entity.ts
index 359ef29a3..8b966306e 100644
--- a/src/marketplace/categories/category.entity.ts
+++ b/src/marketplace/categories/category.entity.ts
@@ -1,11 +1,4 @@
-import {
- Column,
- Entity,
- JoinTable,
- ManyToMany,
- PrimaryGeneratedColumn,
-} from 'typeorm'
-import { Extension } from '../extensions/extension.entity'
+import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'
@Entity()
export class Category {
@@ -17,8 +10,4 @@ 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 cc8b7af39..4e720083f 100644
--- a/src/marketplace/extensions/extension.entity.ts
+++ b/src/marketplace/extensions/extension.entity.ts
@@ -2,12 +2,9 @@ import {
Column,
CreateDateColumn,
Entity,
- JoinTable,
- ManyToMany,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm'
-import { Category } from '../categories/category.entity'
import { ExtensionStatus } from './enums/extension-status.enum'
@Entity()
@@ -39,8 +36,4 @@ export class Extension {
@UpdateDateColumn()
updatedAt: Date
-
- @ManyToMany(() => Category, category => category.extensions)
- @JoinTable()
- categories: Category[]
}