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(alerts): fix format of alert sent to contribution api #267

Merged
merged 2 commits into from Jan 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 6 additions & 15 deletions targets/alert-cli/src/exportContributionAlerts.js
Expand Up @@ -21,17 +21,20 @@ export async function exportContributionAlerts(changes) {
return targetedContribs.flatMap(({ references, document: contrib }) => {
return references.map((reference) => ({
answer_id: contrib.id,
cid: reference.dila_cid,
id: reference.dila_id,
dila_cid: reference.dila_cid,
dila_container_id: reference.dila_container_id,
dila_id: reference.dila_id,
value: computeDiff(reference, alert),
version: alert.ref,
}));
});
});
console.log(`Sending ${contributions} contrib alert(s) to contribution api`);
await fetch(contribApiUrl, {
body: JSON.stringify(contributions),
headers: {
"Content-Type": "application/json",
Prefer: "merge-duplicates",
},
method: "POST",
});
Expand All @@ -42,18 +45,7 @@ export async function exportContributionAlerts(changes) {
* @param {import("@shared/types").ParseDilaReference} reference
* @param {alerts.DilaAlertChanges} nodes
*/
function computeDiff(reference, { added, removed, modified }) {
const addedNode = added.find((node) => node.data.cid === reference.dila_cid);
if (addedNode) {
return { type: "added" };
}
const removedNode = removed.find(
(node) => node.data.cid === reference.dila_cid
);
if (removedNode) {
return { type: "removed" };
}

function computeDiff(reference, { modified }) {
const modifiedNode = modified.find(
(node) => node.data.cid === reference.dila_cid
);
Expand Down Expand Up @@ -86,6 +78,5 @@ function computeDiff(reference, { added, removed, modified }) {
previous: modifiedNode.previous.data.etat,
},
texts,
type: "modified",
};
}