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!

saving an extension in the database

Yevhenii Kulisidi17b3b0ff43a1
diff --git a/src/marketplace/extensions/entities/extension.entity.ts b/src/marketplace/extensions/entities/extension.entity.ts
index 5b10b22e3..0a28bb861 100644
--- a/src/marketplace/extensions/entities/extension.entity.ts
+++ b/src/marketplace/extensions/entities/extension.entity.ts
@@ -24,6 +24,9 @@ export class Extension {
@ManyToOne(() => User, user => user.ownedExtensions)
owner: User
+ @Column()
+ ownerId: string
+
@Column('varchar')
name: string
diff --git a/src/marketplace/extensions/extensions.controller.ts b/src/marketplace/extensions/extensions.controller.ts
index 7190357e5..258a36330 100644
--- a/src/marketplace/extensions/extensions.controller.ts
+++ b/src/marketplace/extensions/extensions.controller.ts
@@ -454,7 +454,11 @@ export class ExtensionsController {
},
@CurrentUserId() userId: string,
): Promise<unknown> {
- return
+ // TODO: Add upload files to CDN
+ return await this.extensionsService.createExtension({
+ ownerId: userId,
+ ...body,
+ })
}
@ApiParam({
diff --git a/src/marketplace/extensions/extensions.service.ts b/src/marketplace/extensions/extensions.service.ts
index b3af9728c..5dc2a4874 100644
--- a/src/marketplace/extensions/extensions.service.ts
+++ b/src/marketplace/extensions/extensions.service.ts
@@ -9,6 +9,7 @@ import { ICreateExtension } from './interfaces/create-extension.interface'
import { ISaveExtension } from './interfaces/save-extension.interface'
import { User } from '../../user/entities/user.entity'
import { IUpdateExtension } from './interfaces/update-extension.interface'
+import { CreateExtensionType } from './types'
@Injectable()
export class ExtensionsService {
@@ -164,4 +165,8 @@ export class ExtensionsService {
relations,
})
}
+
+ async createExtension(extension: CreateExtensionType): Promise<Extension> {
+ return await this.extensionRepository.save(extension)
+ }
}
diff --git a/src/marketplace/extensions/types/create-extension.type.ts b/src/marketplace/extensions/types/create-extension.type.ts
new file mode 100644
index 000000000..fdf85c969
--- /dev/null
+++ b/src/marketplace/extensions/types/create-extension.type.ts
@@ -0,0 +1,4 @@
+import { Extension } from '../entities/extension.entity'
+
+export type CreateExtensionType = Pick<Extension, 'ownerId' | 'name'> &
+ Partial<Pick<Extension, 'description' | 'price'>>
diff --git a/src/marketplace/extensions/types/index.ts b/src/marketplace/extensions/types/index.ts
new file mode 100644
index 000000000..f1ba5950c
--- /dev/null
+++ b/src/marketplace/extensions/types/index.ts
@@ -0,0 +1 @@
+export * from './create-extension.type'