Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement Entity set/get property value for markdown type #7361

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/api/entities.v2/model/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 })}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: '' }],
}),
],
Expand All @@ -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')],
},
],
Expand Down Expand Up @@ -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()],
Expand All @@ -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'],
});
});
});

Expand Down
Loading