From 8326c8c121985958fd81dcf15c12cf93f03d628a Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Wed, 8 Jan 2025 18:02:11 +0100 Subject: [PATCH] fix: update attachment and i18n services --- api/src/attachment/services/attachment.service.ts | 15 ++++++++------- api/src/i18n/services/i18n.service.ts | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/api/src/attachment/services/attachment.service.ts b/api/src/attachment/services/attachment.service.ts index 81fff5bb..1ad83a1b 100644 --- a/api/src/attachment/services/attachment.service.ts +++ b/api/src/attachment/services/attachment.service.ts @@ -83,7 +83,8 @@ export class AttachmentService extends BaseService { if (this.getStoragePlugin()) { try { const pict = foreign_id + '.jpeg'; - const picture = await this.getStoragePlugin()?.downloadProfilePic(pict); + const picture = + await this.getStoragePlugin()?.downloadProfilePic?.(pict); return picture; } catch (err) { this.logger.error('Error downloading profile picture', err); @@ -117,7 +118,7 @@ export class AttachmentService extends BaseService { buffer: Buffer.isBuffer(data) ? data : await data.buffer(), } as Express.Multer.File; try { - await this.getStoragePlugin()?.uploadAvatar(picture); + await this.getStoragePlugin()?.uploadAvatar?.(picture); this.logger.log( `Profile picture uploaded successfully to ${ this.getStoragePlugin()?.name @@ -167,7 +168,7 @@ export class AttachmentService extends BaseService { if (this.getStoragePlugin()) { for (const file of files?.file) { - const dto = await this.getStoragePlugin()?.upload(file); + const dto = await this.getStoragePlugin()?.upload?.(file); if (dto) { const uploadedFile = await this.create(dto); uploadedFiles.push(uploadedFile); @@ -204,14 +205,14 @@ export class AttachmentService extends BaseService { file: Buffer | Readable | Express.Multer.File, metadata: AttachmentMetadataDto, rootDir = config.parameters.uploadDir, - ): Promise { + ): Promise { if (this.getStoragePlugin()) { - const storedDto = await this.getStoragePlugin().store( + const storedDto = await this.getStoragePlugin()?.store?.( file, metadata, rootDir, ); - return await this.create(storedDto); + return storedDto ? await this.create(storedDto) : undefined; } else { const uniqueFilename = generateUniqueFilename(metadata.name); const filePath = resolve(join(rootDir, sanitizeFilename(uniqueFilename))); @@ -289,7 +290,7 @@ export class AttachmentService extends BaseService { async readAsBuffer( attachment: Attachment, rootDir = config.parameters.uploadDir, - ): Promise { + ): Promise { if (this.getStoragePlugin()) { return await this.getStoragePlugin()?.readAsBuffer?.(attachment); } else { diff --git a/api/src/i18n/services/i18n.service.ts b/api/src/i18n/services/i18n.service.ts index 60ded192..89ba07b6 100644 --- a/api/src/i18n/services/i18n.service.ts +++ b/api/src/i18n/services/i18n.service.ts @@ -30,12 +30,12 @@ export class I18nService< ): IfAnyOrNever { options = { ...options, - lang: options.lang || this.i18nOptions.fallbackLanguage, - defaultValue: options.defaultValue || key, + lang: options?.lang || this.i18nOptions.fallbackLanguage, + defaultValue: options?.defaultValue || key, }; let { lang } = options; - lang = this.resolveLanguage(lang); + lang = this.resolveLanguage(lang!); // Translate block message, button text, ... if (lang in this.dynamicTranslations) {