📈 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
Merge branch 'main' into refactoring/marketplace
Andrii R05d6b25cf40c
diff --cc src/marketplace/extensions/extensions.service.tsindex 34c02edfc,59f7ccb05..71f0b2911--- a/src/marketplace/extensions/extensions.service.ts+++ b/src/marketplace/extensions/extensions.service.ts@@@ -177,174 -165,24 +177,194 @@@ export class ExtensionsService})}+ async createExtension(extension: CreateExtensionType) {+ return await this.extensionRepository.save({+ owner: { id: extension.ownerId },+ name: extension.name,+ description: extension.description,+ status: extension.extensionScript+ ? ExtensionStatus.PENDING+ : ExtensionStatus.NO_EXTENSION_UPLOADED,+ price: extension.price && Number(extension.price),+ category: { id: extension.categoryId && Number(extension.categoryId) },+ mainImage:+ extension.mainImage &&+ (+ await this.cdnService.uploadFile(extension.mainImage)+ ).filename,+ additionalImages: extension.additionalImages+ ? [+ ...(await Promise.all(+ extension.additionalImages.map(+ async image =>+ (+ await this.cdnService.uploadFile(image)+ ).filename,+ ),+ )),+ ]+ : [],+ fileURL:+ extension.extensionScript &&+ (+ await this.cdnService.uploadFile(extension.extensionScript)+ ).filename,+ version: DEFAULT_EXTENSION_VERSION,+ })+ }++ async findUserExtension(extensionId: string, userId: string) {+ const user = await this.userService.findUserById(userId)++ if (!user) return null++ if (user.roles.includes(UserType.ADMIN)) {+ return await this.extensionRepository.findOne({+ where: { id: extensionId },+ })+ }++ return await this.extensionRepository.findOne({+ where: { id: extensionId, owner: { id: userId } },+ })+ }++ async updateExtension(+ extensionId: string,+ extension: UpdateExtensionType,+ extensionVersion: string,+ ) {+ const _extension = await this.extensionRepository.findOne({+ where: { id: extensionId },+ })++ const additionalImages = [..._extension.additionalImages]++ if (extension.additionalImages) {+ additionalImages.push(+ ...(await Promise.all(+ extension.additionalImages.map(+ async image => (await this.cdnService.uploadFile(image)).filename,+ ),+ )),+ )+ }++ if (extension.additionalImagesToDelete) {+ extension.additionalImagesToDelete.forEach(async image => {+ const index = additionalImages.indexOf(image)++ if (index > -1) {+ additionalImages.splice(index, 1)+ }++ if (additionalImages.includes(image)) {+ await this.cdnService.deleteFile(image)+ }+ })+ }++ await this.extensionRepository.update(+ { id: extensionId },+ {+ name: extension.name ? extension.name : _extension.name,+ description: extension.description+ ? extension.description+ : _extension.description,+ version: extension.version+ ? this.extensionVersion(extensionVersion, extension.version)+ : _extension.version,+ status: extension.extensionScript+ ? 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)+ ).filename+ : _extension.mainImage,+ additionalImages,+ fileURL: extension.extensionScript+ ? (+ await this.cdnService.uploadFile(extension.extensionScript)+ ).filename+ : _extension.fileURL,+ },+ )++ return await this.extensionRepository.findOne({+ where: { id: extensionId },+ })+ }++ extensionVersion(+ extensionVersion: string,+ versionType: ExtensionVersionType,+ ) {+ const versionTypes: VersionTypes = {+ major: [1, 0, 0],+ minor: [0, 1, 0],+ patch: [0, 0, 1],+ }++ const updateVersion: number[] = extensionVersion.split('.').map(Number)+ const versionUpdate: number[] = versionTypes[versionType]++ updateVersion[0] += versionUpdate[0]+ updateVersion[1] += versionUpdate[1]+ updateVersion[2] += versionUpdate[2]++ const newVersion: string = updateVersion.join('.')++ return newVersion+ }++ async searchExtension(data: SearchExtensionQueries) {+ return await this.extensionRepository.findAndCount({+ skip: data.offset || 0,+ take: data.limit > 100 ? 100 : data.limit || 10,+ where: {+ name: Like(`%${data.term}%`),+ },+ order: {+ createdAt:+ data.sortBy && data.sortBy === 'createdAt' ? 'DESC' : undefined,+ updatedAt:+ data.sortBy && data.sortBy === 'updatedAt' ? 'DESC' : undefined,+ },+ relations: ['owner', 'users', 'category'],+ })+ }++ async getExtensions(data: GetAllExtensionsQueries) {+ return await this.extensionRepository.findAndCount({+ skip: data.offset || 0,+ take: data.limit > 100 ? 100 : data.limit || 10,+ where: {+ status: ExtensionStatus.ACCEPTED,+ },+ relations: ['owner', 'users', 'category'],+ })+++ async find(options: FindManyOptions<Extension>): Promise<Extension[]> {+ return await this.extensionRepository.find(options)+ }++ async getExtensionInstallCount(+ extensionId: string,+ twoWeeksAgo?: Date,+ ): Promise<number> {+ const query = this.extensionToProjectRepository+ .createQueryBuilder('extensionToProject')+ .where('extensionToProject.extensionId = :extensionId', { extensionId })++ if (twoWeeksAgo) {+ query.andWhere('extensionToProject.createdAt > :twoWeeksAgo', {+ twoWeeksAgo,+ })+ }++ return await query.getCount()}}