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!

fixed categories

Blue Mouse516eaf21a5f6
diff --git a/src/marketplace/categories/category.entity.ts b/src/marketplace/categories/category.entity.ts
index d51a5e2e9..0aadecf6f 100644
--- a/src/marketplace/categories/category.entity.ts
+++ b/src/marketplace/categories/category.entity.ts
@@ -1,14 +1,14 @@
-import { Column, Entity, ManyToMany, PrimaryGeneratedColumn } from 'typeorm'
+import { Column, Entity, OneToMany, PrimaryGeneratedColumn } from 'typeorm'
import { Extension } from '../extensions/entities/extension.entity'
@Entity()
export class Category {
@PrimaryGeneratedColumn('increment')
- id!: number
+ id: number
@Column({ type: 'varchar', unique: true })
- name!: string
+ name: string
- @ManyToMany(() => Extension, extension => extension.categories)
- extensions!: Extension[] | []
+ @OneToMany(() => Extension, extension => extension.category)
+ extensions: Extension[] | []
}
diff --git a/src/marketplace/extensions/dtos/create-extension.dto.ts b/src/marketplace/extensions/dtos/create-extension.dto.ts
index 93d032c1e..7cc6782f4 100644
--- a/src/marketplace/extensions/dtos/create-extension.dto.ts
+++ b/src/marketplace/extensions/dtos/create-extension.dto.ts
@@ -62,12 +62,11 @@ export class CreateExtension {
@ApiProperty({
default: [],
- description: 'Extension categories ids',
- example: [1, 2, 3],
- isArray: true,
+ description: 'Extension category ID',
+ example: 1,
required: false,
type: Array<number>,
})
@IsOptional()
- readonly categoriesIds?: number[]
+ readonly categoryID?: number
}
diff --git a/src/marketplace/extensions/entities/extension.entity.ts b/src/marketplace/extensions/entities/extension.entity.ts
index cbbf36fc8..51a56d161 100644
--- a/src/marketplace/extensions/entities/extension.entity.ts
+++ b/src/marketplace/extensions/entities/extension.entity.ts
@@ -3,7 +3,6 @@ import {
CreateDateColumn,
Entity,
JoinTable,
- ManyToMany,
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
@@ -59,8 +58,8 @@ export class Extension {
@UpdateDateColumn()
updatedAt: Date
- @ManyToMany(() => Category, category => category.extensions)
- categories: Category[] | []
+ @ManyToOne(() => Category, category => category.extensions)
+ category: Category
@OneToMany(
() => ExtensionToUser,
diff --git a/src/marketplace/extensions/extensions.controller.ts b/src/marketplace/extensions/extensions.controller.ts
index e35429018..60c392ebd 100644
--- a/src/marketplace/extensions/extensions.controller.ts
+++ b/src/marketplace/extensions/extensions.controller.ts
@@ -122,7 +122,7 @@ export class ExtensionsController {
skip: queries.offset || 0,
take: queries.limit > 100 ? 25 : queries.limit || 25,
},
- ['owner', 'users'],
+ ['owner', 'users', 'category'],
)
// temporary fix; the usersQuantity should be counted via .count() method of typeorm
@@ -188,13 +188,13 @@ export class ExtensionsController {
throw new ForbiddenException('You must be logged in to access this route.')
}
- const [extensions, count] = await this.extensionsService.findAndCount({
+ let [extensions, count] = await this.extensionsService.findAndCount({
skip: queries.offset || 0,
take: queries.limit > 100 ? 25 : queries.limit || 25,
where: {
owner: userId,
},
- })
+ }, ['category'])
return { extensions, count }
}
@@ -241,7 +241,7 @@ export class ExtensionsController {
if (queries.category) {
const [extensions, count] = await getRepository(Extension)
.createQueryBuilder('extension')
- .leftJoin('extension.categories', 'category')
+ .leftJoin('extension.category', 'category')
.where('extension.name LIKE :term', { term: `%${queries.term}%` })
.andWhere('category.name = :category', { category: queries.category })
.skip(queries.offset || 0)
@@ -300,7 +300,7 @@ export class ExtensionsController {
where: {
id: params.extensionId,
},
- relations: ['categories'],
+ relations: ['category'],
})
if (!extension) {
@@ -367,8 +367,8 @@ export class ExtensionsController {
mainImage: mainImageURL,
additionalImages: additionalImageFilenames,
fileURL,
- categories: body.categoriesIds
- ? await this.categoriesService.findByIds(body.categoriesIds)
+ category: body.categoryID
+ ? await this.categoriesService.findById(body.categoryID)
: undefined,
})
diff --git a/src/marketplace/extensions/interfaces/create-extension.interface.ts b/src/marketplace/extensions/interfaces/create-extension.interface.ts
index f63254aa9..3676b9dae 100644
--- a/src/marketplace/extensions/interfaces/create-extension.interface.ts
+++ b/src/marketplace/extensions/interfaces/create-extension.interface.ts
@@ -10,5 +10,5 @@ export interface ICreateExtension {
mainImage?: string | null
additionalImages?: string[] | []
fileURL?: string
- categories?: Category[]
+ category?: Category
}
diff --git a/src/marketplace/extensions/interfaces/save-extension.interface.ts b/src/marketplace/extensions/interfaces/save-extension.interface.ts
index cffa22ff1..b99e4ba9d 100644
--- a/src/marketplace/extensions/interfaces/save-extension.interface.ts
+++ b/src/marketplace/extensions/interfaces/save-extension.interface.ts
@@ -7,5 +7,5 @@ export interface ISaveExtension {
price?: number
mainImage?: string | null
additionalImages?: string[] | []
- categories?: Category[]
+ category?: Category
}