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

fix(server): 🐛 remove administrationName from added sections if null #2500

Merged
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
28 changes: 28 additions & 0 deletions apps/server/src/typegoose/Traductions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,25 @@ const trad_avancement: RecursivePartial<TranslationContent> = {
validatorId: new ObjectId("656076dbaf8df7a3f7bceeb4"),
};

const trad_added_adminName: TranslationContent = {
//@ts-ignore
content: {
titreInformatif: "abc",
titreMarque: "def",
abstract: "tyui",
what: "WHAT",
how: { "my-uuid-v4-key": { title: "title", text: "text" } },
next: {
"my-uuid-v4-key": { title: "title", text: "text" },
"my-uuid-v4-key-2": { title: "title", text: "text" },
"my-uuid-v4-key-3": { title: "title", text: "text" },
},
},

created_at: new Date(),
validatorId: new ObjectId("656076dbaf8df7a3f7bceeb4"),
};

describe("Traductions", () => {
describe("diff", () => {
it("should return empty array", () => {
Expand Down Expand Up @@ -153,6 +172,15 @@ describe("Traductions", () => {
removed: ["content.next.my-uuid-v4-key.title", "content.next.my-uuid-v4-key.text"],
});
});
it("should not return administrationName ", () => {
const newTradAdded = JSON.parse(JSON.stringify(trad_added_adminName));
newTradAdded.content = { ...newTradAdded.content, administrationName: null };
expect(Traductions.diff(trad_added_adminName, newTradAdded)).toEqual({
modified: [],
added: [],
removed: [],
});
});
});

describe("computeFinished", () => {
Expand Down
4 changes: 3 additions & 1 deletion apps/server/src/typegoose/Traductions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export class Traductions extends Base {
const originKeys = keys(origin);
const compareToKeys = keys(compareTo);
// ces champs devront être traduits impérativement => to review
const added = difference(compareToKeys, originKeys);
const added = difference(compareToKeys, originKeys).filter(
(key: keyof TranslationContent) => get(compareTo, key) !== null,
);
// les champs supprimés peuvent être traités automatiquement sans re-traduction
const removed = difference(originKeys, compareToKeys);

Expand Down
22 changes: 22 additions & 0 deletions migrations/1733826190794_RemoveStuckedToReview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MigrationInterface } from "mongo-migrate-ts";
import { Db } from "mongodb";

export class Migration1733826190794 implements MigrationInterface {
public async up(db: Db): Promise<void | never> {
const trads = await db.collection("traductions").find({ toReview: "content.administrationName" }).toArray();
for (const trad of trads) {
const dispositif = await db.collection("dispositifs").findOne({ _id: trad.dispositifId });
if (dispositif && dispositif.translations.fr.content.administrationName === null) {
//@ts-ignore
await db
.collection("traductions")
.updateOne(
{ _id: trad._id },
{ $pull: { toReview: "content.administrationName", toReviewCache: "content.administrationName" } },
);
}
}
}

public async down(db: Db): Promise<void | never> {}
}
Loading