Skip to content

Commit

Permalink
fix: send diff payload
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelB committed Nov 23, 2020
1 parent 1cbc217 commit 52e493e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
1 change: 1 addition & 0 deletions targets/alert-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"@shared/graphql-client": "1.0.0",
"@socialgouv/cdtn-slugify": "^4.35.0",
"@socialgouv/cdtn-sources": "^4.35.0",
"@types/node-fetch": "^2.5.7",
"node-fetch": "^2.6.1",
"nodegit": "0.27.0",
"semver": "^7.3.2",
Expand Down
33 changes: 32 additions & 1 deletion targets/alert-cli/src/exportContributionAlerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export async function exportContributionAlerts(changes) {
answer_id: contrib.id,
cid: reference.dila_cid,
id: reference.dila_id,
value: nodes.find((node) => node.data.cid === reference.dila_cid),
value: computeDiff(
nodes.find((node) => node.data.cid === reference.dila_cid)
),
version: alert.ref,
}));
});
Expand All @@ -37,3 +39,32 @@ export async function exportContributionAlerts(changes) {
method: "POST",
});
}

/**
*
* @param {alerts.DilaNodeForDiff} node
*/
function computeDiff(node) {
const textFieldname =
node.context.containerId === "LEGITEXT000006072050" ? "texte" : "content";
const content = node.data[textFieldname] || "";
const previousContent = node.previous?.data[textFieldname] || "";
const showDiff = content !== previousContent;
const showNotaDiff = node.previous.data.nota !== node.data.nota;
const texts = [];
if (showDiff) {
texts.push({ current: content, previous: previousContent });
}

if (showNotaDiff) {
texts.push({
current: node.data.nota,
previous: node.previous.data.nota,
});
}

return {
etat: { current: node.data.etat, previous: node.previous.data.etat },
texts,
};
}
4 changes: 4 additions & 0 deletions targets/alert-cli/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ type DilaNodeWithContext = DilaNode & {
}
}

type DilaNodeForDiff = DilaNodeWithContext & {
previous: DilaNodeWithContext
}

type FicheVddIndex = {
id: string
date: string
Expand Down

0 comments on commit 52e493e

Please sign in to comment.