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!

added a new route to get an extension

Yevhenii K227f41ff0091
diff --git a/src/marketplace/extensions/dtos/get-extension-params.dto.ts b/src/marketplace/extensions/dtos/get-extension-params.dto.ts
new file mode 100644
index 000000000..6ee0adc0c
--- /dev/null
+++ b/src/marketplace/extensions/dtos/get-extension-params.dto.ts
@@ -0,0 +1,6 @@
+import { IsNumberString } from 'class-validator'
+
+export class GetExtensionParams {
+ @IsNumberString()
+ readonly extensionId!: number
+}
diff --git a/src/marketplace/extensions/extension.entity.ts b/src/marketplace/extensions/extension.entity.ts
index 702880d4c..4e720083f 100644
--- a/src/marketplace/extensions/extension.entity.ts
+++ b/src/marketplace/extensions/extension.entity.ts
@@ -1,4 +1,10 @@
-import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm'
+import {
+ Column,
+ CreateDateColumn,
+ Entity,
+ PrimaryGeneratedColumn,
+ UpdateDateColumn,
+} from 'typeorm'
import { ExtensionStatus } from './enums/extension-status.enum'
@Entity()
@@ -24,4 +30,10 @@ export class Extension {
default: ExtensionStatus.PENDING,
})
status: string
+
+ @CreateDateColumn()
+ createdAt: Date
+
+ @UpdateDateColumn()
+ updatedAt: Date
}
diff --git a/src/marketplace/extensions/extensions.controller.ts b/src/marketplace/extensions/extensions.controller.ts
index 333cbc787..23342ffbe 100644
--- a/src/marketplace/extensions/extensions.controller.ts
+++ b/src/marketplace/extensions/extensions.controller.ts
@@ -2,12 +2,16 @@ import {
Body,
ConflictException,
Controller,
+ Get,
+ NotFoundException,
+ Param,
Post,
UsePipes,
ValidationPipe,
} from '@nestjs/common'
-import { ApiTags } from '@nestjs/swagger'
+import { ApiParam, ApiTags } from '@nestjs/swagger'
import { AddExtension } from './dtos/add-extension.dto'
+import { GetExtensionParams } from './dtos/get-extension-params.dto'
import { Extension } from './extension.entity'
import { ExtensionsService } from './extensions.service'
import { ISaveExtension } from './interfaces/save-extension.interface'
@@ -25,6 +29,23 @@ import { ISaveExtension } from './interfaces/save-extension.interface'
export class ExtensionsController {
constructor(private readonly extensionsService: ExtensionsService) {}
+ @ApiParam({
+ name: 'extensionId',
+ description: 'Extension ID',
+ example: '1',
+ type: String,
+ })
+ @Get(':extensionId')
+ async getExtension(@Param() params: GetExtensionParams): Promise<Extension> {
+ const extension = await this.extensionsService.findById(params.extensionId)
+
+ if (!extension) {
+ throw new NotFoundException('Extension not found.')
+ }
+
+ return extension
+ }
+
@Post()
async addExtension(
@Body() body: AddExtension,
diff --git a/src/marketplace/extensions/extensions.service.ts b/src/marketplace/extensions/extensions.service.ts
index 3f0c25702..95a0e9bcc 100644
--- a/src/marketplace/extensions/extensions.service.ts
+++ b/src/marketplace/extensions/extensions.service.ts
@@ -24,7 +24,11 @@ export class ExtensionsService {
return this.extensionRepository.create(extension)
}
- async save(category: ISaveExtension): Promise<ISaveExtension & Extension> {
- return await this.extensionRepository.save(category)
+ async save(extension: ISaveExtension): Promise<ISaveExtension & Extension> {
+ return await this.extensionRepository.save(extension)
+ }
+
+ async findById(id: number): Promise<Extension> {
+ return await this.findOne({ where: { id } })
}
}