📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Added ability to add a category to extensions
Yevhenii Kulisidi51f1a9352137
diff --git a/src/marketplace/categories/categories.service.ts b/src/marketplace/categories/categories.service.tsindex 3953f4a97..ecc012abc 100644--- a/src/marketplace/categories/categories.service.ts+++ b/src/marketplace/categories/categories.service.ts@@ -50,4 +50,8 @@ export class CategoriesService {async findByIds(ids: number[]): Promise<Category[]> {return await this.categoryRepository.findByIds(ids)}++ async getCategoryById(id: number) {+ return await this.categoryRepository.findOne({ where: { id } })+ }}diff --git a/src/marketplace/extensions/dtos/create-extension.dto.ts b/src/marketplace/extensions/dtos/create-extension.dto.tsindex 0ab1c272d..b69ce1f9a 100644--- a/src/marketplace/extensions/dtos/create-extension.dto.ts+++ b/src/marketplace/extensions/dtos/create-extension.dto.ts@@ -26,6 +26,10 @@ export class CreateExtensionBodyDto {@IsNumberString()readonly price?: string+ @IsOptional()+ @IsNumberString()+ readonly categoryId?: string+@IsOptional()@IsFile()@MaxFileSize(10 * 1024 * 1024)diff --git a/src/marketplace/extensions/extensions.controller.ts b/src/marketplace/extensions/extensions.controller.tsindex a7227ee2a..55db1fba9 100644--- a/src/marketplace/extensions/extensions.controller.ts+++ b/src/marketplace/extensions/extensions.controller.ts@@ -370,6 +370,16 @@ export class ExtensionsController {@Body() body: CreateExtensionBodyDto,@CurrentUserId() userId: string,): Promise<Extension> {+ if (body.categoryId) {+ const category = await this.categoriesService.getCategoryById(+ Number(body.categoryId),+ )++ if (!category) {+ throw new BadRequestException('Category not found.')+ }+ }+return await this.extensionsService.createExtension({ownerId: userId,...body,@@ -393,6 +403,16 @@ export class ExtensionsController {throw new NotFoundException('Extension not found.')}+ if (body.categoryId) {+ const category = await this.categoriesService.getCategoryById(+ Number(body.categoryId),+ )++ if (!category) {+ throw new BadRequestException('Category not found.')+ }+ }+if (Object.keys(body).length === 0) {throw new BadRequestException('Extension body is required.')}diff --git a/src/marketplace/extensions/extensions.service.ts b/src/marketplace/extensions/extensions.service.tsindex 3d56456cd..46852ed50 100644--- a/src/marketplace/extensions/extensions.service.ts+++ b/src/marketplace/extensions/extensions.service.ts@@ -184,6 +184,7 @@ export class ExtensionsService {? ExtensionStatus.PENDING: ExtensionStatus.NO_EXTENSION_UPLOADED,price: extension.price && Number(extension.price),+ category: { id: extension.categoryId && Number(extension.categoryId) },mainImage:extension.mainImage &&(@@ -274,6 +275,7 @@ export class ExtensionsService {? ExtensionStatus.PENDING: _extension.status,price: extension.price ? Number(extension.price) : _extension.price,+ category: { id: extension.categoryId && Number(extension.categoryId) },mainImage: extension.mainImage? (await this.cdnService.uploadFile(extension.mainImage)diff --git a/src/marketplace/extensions/types/create-extension.type.ts b/src/marketplace/extensions/types/create-extension.type.tsindex a815cd72c..2c8d4724d 100644--- a/src/marketplace/extensions/types/create-extension.type.ts+++ b/src/marketplace/extensions/types/create-extension.type.ts@@ -5,6 +5,7 @@ export type CreateExtensionType = {name: stringdescription?: stringprice?: string+ categoryId?: stringmainImage?: Express.Multer.FileadditionalImages?: Express.Multer.File[]extensionScript?: Express.Multer.File