diff --git a/app/api/entities.v2/model/Entity.ts b/app/api/entities.v2/model/Entity.ts index a4cbbf6d92..7b7d1b35d0 100644 --- a/app/api/entities.v2/model/Entity.ts +++ b/app/api/entities.v2/model/Entity.ts @@ -62,8 +62,8 @@ export class Entity { ); } - changePropertyValue(property: Property, value: string) { - if (property.type === 'text') { + setPropertyValue(property: Property, value: string) { + if (property.type === 'text' || property.type === 'markdown') { const isTitleProperty = property instanceof CommonProperty && property.name === 'title'; const { metadata } = this; if (!(property instanceof CommonProperty)) { @@ -80,17 +80,17 @@ export class Entity { ); } - throw new Error('types other than string are not implemented yet'); + throw new Error('types other than string/markdown are not implemented yet'); } getPropertyValue(property: Property): string { - if (property.type === 'text') { + if (property.type === 'text' || property.type === 'markdown') { const isTitleProperty = property instanceof CommonProperty && property.name === 'title'; if (isTitleProperty) return this.title; return this.metadata[property.name][0].value as string; } - throw new Error('types other than string are not implemented yet'); + throw new Error('types other than string/markdown are not implemented yet'); } } diff --git a/app/api/externalIntegrations.v2/automaticTranslation/RequestEntityTranslation.ts b/app/api/externalIntegrations.v2/automaticTranslation/RequestEntityTranslation.ts index 62f04ffbdd..f5c15fb11b 100644 --- a/app/api/externalIntegrations.v2/automaticTranslation/RequestEntityTranslation.ts +++ b/app/api/externalIntegrations.v2/automaticTranslation/RequestEntityTranslation.ts @@ -78,7 +78,7 @@ export class RequestEntityTranslation { await entities.forEach(async fetchedEntity => { if (languagesTo.includes(fetchedEntity.language as LanguageISO6391)) { await this.entitiesDS.updateEntity( - fetchedEntity.changePropertyValue(property, pendingText) + fetchedEntity.setPropertyValue(property, pendingText) ); this.logger.info( `[AT] - Pending translation saved on DB - ${property.name}: ${pendingText}` diff --git a/app/api/externalIntegrations.v2/automaticTranslation/SaveEntityTranslations.ts b/app/api/externalIntegrations.v2/automaticTranslation/SaveEntityTranslations.ts index 5876c6e566..80cf65a391 100644 --- a/app/api/externalIntegrations.v2/automaticTranslation/SaveEntityTranslations.ts +++ b/app/api/externalIntegrations.v2/automaticTranslation/SaveEntityTranslations.ts @@ -48,7 +48,7 @@ export class SaveEntityTranslations { } if (translation?.success && property) { const textTranslated = `${SaveEntityTranslations.AITranslatedText} ${translation.text}`; - await this.entitiesDS.updateEntity(entity.changePropertyValue(property, textTranslated)); + await this.entitiesDS.updateEntity(entity.setPropertyValue(property, textTranslated)); this.logger.info( `[AT] - Property saved on DB - ${JSON.stringify({ entityId: entity._id, language: entity.language, [property.name]: translation.text })}` diff --git a/app/api/externalIntegrations.v2/automaticTranslation/specs/RequestEntityTranslation.spec.ts b/app/api/externalIntegrations.v2/automaticTranslation/specs/RequestEntityTranslation.spec.ts index 263112c455..eada1fafdd 100644 --- a/app/api/externalIntegrations.v2/automaticTranslation/specs/RequestEntityTranslation.spec.ts +++ b/app/api/externalIntegrations.v2/automaticTranslation/specs/RequestEntityTranslation.spec.ts @@ -18,11 +18,16 @@ import { ATTaskMessage, RequestEntityTranslation } from '../RequestEntityTransla const factory = getFixturesFactory(); const fixtures: DBFixture = { templates: [ - factory.template('template1', [factory.property('text1'), factory.property('empty_text')]), + factory.template('template1', [ + factory.property('text1'), + factory.property('text2', 'markdown'), + factory.property('empty_text'), + ]), ], entities: [ ...factory.entityInMultipleLanguages(['en', 'es', 'pt'], 'entity1', 'template1', { text1: [{ value: 'original text1' }], + text2: [{ value: 'markdown text' }], empty_text: [{ value: '' }], }), ], @@ -39,7 +44,11 @@ const fixtures: DBFixture = { templates: [ { template: factory.idString('template1'), - properties: [factory.idString('text1'), factory.idString('empty_text')], + properties: [ + factory.idString('text1'), + factory.idString('text2'), + factory.idString('empty_text'), + ], commonProperties: [factory.commonPropertiesTitleId('template1')], }, ], @@ -112,7 +121,7 @@ describe('RequestEntityTranslation', () => { }); it('should send a task to the automatic translation service queue', () => { - expect(taskManager.startTask).toHaveBeenCalledTimes(2); + expect(taskManager.startTask).toHaveBeenCalledTimes(3); expect(taskManager.startTask).toHaveBeenCalledWith({ key: ['tenant', 'entity1', factory.commonPropertiesTitleId('template1').toString()], @@ -127,6 +136,13 @@ describe('RequestEntityTranslation', () => { language_from: 'en', languages_to: ['es', 'pt'], }); + + expect(taskManager.startTask).toHaveBeenCalledWith({ + key: ['tenant', 'entity1', factory.property('text2')._id?.toString()], + text: 'markdown text', + language_from: 'en', + languages_to: ['es', 'pt'], + }); }); });