Skip to content

Commit

Permalink
fix(translation): Allow multiple translation values with same quantit…
Browse files Browse the repository at this point in the history
…y string and key
  • Loading branch information
kwiky committed Jan 3, 2024
1 parent ba8eb22 commit 57b250b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
3 changes: 1 addition & 2 deletions src/data/database/postgres-unique-keys.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ export enum PostgresUniqueKeys {
UserEmail = "UQ_user_email",
LanguageInProject = "UQ_language_in_project",
TranslationKeyInGroup = "UQ_translationkey_in_group",
TranslationValueInProject = "UQ_translationvalue_in_project",
GroupInProject = "UQ_group_in_project",
UserInProject = "UQ_user_in_project",
GuestInProject = "UQ_guest_in_project"
}
}
20 changes: 13 additions & 7 deletions src/translation/translation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,20 @@ export default class TranslationService {
updateValueDto: UpdateValueDto
): Promise<TranslationValue> {
const value = await this.getValue(userId, projectId, translationKeyId, valueId);

const lastModifiedValue = (await this.translationValueRepository.find({
where: {
keyId: value.keyId,
languageId: value.languageId,
quantityString: value.quantityString
},
order: {
updatedAt: "DESC"
}
}))[0];
// If current translation is in status MODIFIED, we can update it
if (value.status === TranslationStatus.MODIFIED) {
value.name = updateValueDto.name;
return await this.translationValueRepository.save(value);
if (lastModifiedValue.status === TranslationStatus.MODIFIED) {
lastModifiedValue.name = updateValueDto.name;
return await this.translationValueRepository.save(lastModifiedValue);
} else {
// If current translation is not in status MODIFIED, we need to create a new one
const newValue = new TranslationValue();
Expand Down Expand Up @@ -371,9 +380,6 @@ export default class TranslationService {
const value = await this.translationValueRepository.findOne({
where: {
id: valueId
},
order: {
createdAt: "DESC"
}
});
if (!value || value.keyId !== key.id) {
Expand Down
1 change: 0 additions & 1 deletion src/translation/translation_value.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import TranslationStatus from "./translation_status.enum";
export const TranslationValuesTableName: string = "translation_values";

@Entity(TranslationValuesTableName)
@Unique(PostgresUniqueKeys.TranslationValueInProject, ["key", "quantityString", "language"])
export default class TranslationValue {
@PrimaryGeneratedColumn()
@ApiProperty()
Expand Down

0 comments on commit 57b250b

Please sign in to comment.