📈 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 a new route to update the extension
Yevhenii Ka18677f24ae8
diff --git a/src/marketplace/categories/categories.controller.ts b/src/marketplace/categories/categories.controller.tsindex 50a70a781..d24673d34 100644--- a/src/marketplace/categories/categories.controller.ts+++ b/src/marketplace/categories/categories.controller.ts@@ -26,7 +26,7 @@ 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 './pipes/body-validation.pipe'+import { BodyValidationPipe } from '../common/pipes/body-validation.pipe'@ApiTags('categories')@UsePipes(diff --git a/src/marketplace/categories/pipes/body-validation.pipe.ts b/src/marketplace/common/pipes/body-validation.pipe.tssimilarity index 100%rename from src/marketplace/categories/pipes/body-validation.pipe.tsrename to src/marketplace/common/pipes/body-validation.pipe.tsdiff --git a/src/marketplace/extensions/dtos/update-extension-params.dto.ts b/src/marketplace/extensions/dtos/update-extension-params.dto.tsnew file mode 100644index 000000000..ede34938f--- /dev/null+++ b/src/marketplace/extensions/dtos/update-extension-params.dto.ts@@ -0,0 +1,6 @@+import { IsNumberString } from 'class-validator'++export class UpdateExtensionParams {+ @IsNumberString()+ readonly extensionId!: number+}diff --git a/src/marketplace/extensions/dtos/update-extension.dto.ts b/src/marketplace/extensions/dtos/update-extension.dto.tsnew file mode 100644index 000000000..cb860ebce--- /dev/null+++ b/src/marketplace/extensions/dtos/update-extension.dto.ts@@ -0,0 +1,52 @@+import { ApiProperty } from '@nestjs/swagger'+import {+ IsOptional,+ IsString,+ Matches,+ MaxLength,+ MinLength,+} from 'class-validator'++export class UpdateExtension {+ @ApiProperty({+ description: 'Extension title',+ example: '', // TODO: Add example+ maxLength: 255,+ minLength: 1,+ type: String,+ })+ @IsString()+ @IsOptional()+ @MinLength(1)+ @MaxLength(255)+ readonly title!: string++ @ApiProperty({+ default: null,+ description: 'Extension description',+ example: '', // Add example+ maxLength: 1024,+ minLength: 1,+ nullable: true,+ required: false,+ type: String,+ })+ @IsString()+ @IsOptional()+ @MinLength(1)+ @MaxLength(1024)+ readonly description?: string | null++ @ApiProperty({+ description: 'Extension version',+ example: '1.0.0',+ maxLength: 255,+ minLength: 5,+ type: String,+ })+ @IsString()+ @IsOptional()+ @Matches(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/)+ @MaxLength(255)+ readonly version!: string+}diff --git a/src/marketplace/extensions/extensions.controller.ts b/src/marketplace/extensions/extensions.controller.tsindex feecdcece..c9ba1edd2 100644--- a/src/marketplace/extensions/extensions.controller.ts+++ b/src/marketplace/extensions/extensions.controller.ts@@ -6,6 +6,7 @@ import {Get,NotFoundException,Param,+ Patch,Post,Query,UsePipes,@@ -19,6 +20,9 @@ import { GetAllExtensionsQueries } from './dtos/get-all-extensions-queries.dto'import { Extension } from './extension.entity'import { ExtensionsService } from './extensions.service'import { ISaveExtension } from './interfaces/save-extension.interface'+import { UpdateExtensionParams } from './dtos/update-extension-params.dto'+import { UpdateExtension } from './dtos/update-extension.dto'+import { BodyValidationPipe } from '../common/pipes/body-validation.pipe'@ApiTags('extensions')@UsePipes(@@ -92,6 +96,28 @@ export class ExtensionsController {return await this.extensionsService.save(extensionInstance)}+ @ApiParam({+ name: 'extensionId',+ description: 'Extension ID',+ example: '1',+ type: String,+ })+ @Patch(':extensionId')+ async updateExtension(+ @Param() params: UpdateExtensionParams,+ @Body(new BodyValidationPipe()) body: UpdateExtension,+ ): Promise<UpdateExtension> {+ const extension = await this.extensionsService.findById(params.extensionId)++ if (!extension) {+ throw new NotFoundException('Extension not found.')+ }++ await this.extensionsService.update(extension.id, body)++ return body+ }+@ApiParam({name: 'extensionId',description: 'Extension ID',diff --git a/src/marketplace/extensions/extensions.service.ts b/src/marketplace/extensions/extensions.service.tsindex 1b11faae6..850e2e57b 100644--- a/src/marketplace/extensions/extensions.service.ts+++ b/src/marketplace/extensions/extensions.service.ts@@ -4,6 +4,7 @@ import { FindManyOptions, FindOneOptions, Repository } from 'typeorm'import { Extension } from './extension.entity'import { ICreateExtension } from './interfaces/create-extension.interface'import { ISaveExtension } from './interfaces/save-extension.interface'+import { IUpdateExtension } from './interfaces/update-extension.interface'@Injectable()export class ExtensionsService {@@ -32,6 +33,10 @@ export class ExtensionsService {return await this.findOne({ where: { id } })}+ async update(id: number, extension: IUpdateExtension) {+ await this.extensionRepository.update({ id }, extension)+ }+async delete(id: number): Promise<void> {await this.extensionRepository.delete({ id })}diff --git a/src/marketplace/extensions/interfaces/update-extension.interface.ts b/src/marketplace/extensions/interfaces/update-extension.interface.tsnew file mode 100644index 000000000..d2a590be1--- /dev/null+++ b/src/marketplace/extensions/interfaces/update-extension.interface.ts@@ -0,0 +1,5 @@+export interface IUpdateExtension {+ title?: string+ description?: string | null+ version?: string+}