Skip to content

Commit

Permalink
fix: post data
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelB committed Nov 23, 2020
1 parent fb97fef commit 1cbc217
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
4 changes: 3 additions & 1 deletion 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",
"node-fetch": "^2.6.1",
"nodegit": "0.27.0",
"semver": "^7.3.2",
"unist-util-parents": "^1.0.3",
Expand All @@ -15,11 +16,12 @@
"@babel/preset-env": "^7.12.1",
"@shared/types": "1.0.0",
"@socialgouv/contributions-data-types": "^3.0.0",
"@socialgouv/datafiller-data-types": "^2.6.0",
"@socialgouv/eslint-config-recommended": "^1.46.0",
"@socialgouv/fiches-travail-data-types": "^4.6.0",
"@socialgouv/datafiller-data-types": "^2.6.0",
"@types/jest": "^26.0.15",
"@types/node": "^14.14.6",
"@types/node-fetch": "^2.5.7",
"@types/nodegit": "^0.26.12",
"@types/semver": "^7.3.4",
"@types/unist": "^2.0.3",
Expand Down
13 changes: 10 additions & 3 deletions targets/alert-cli/src/exportContributionAlerts.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import fetch from "node-fetch";

const contribApi =
"https://contributions-api.codedutravail.fabrique.social.gouv.fr/alerts";

Expand All @@ -11,7 +13,7 @@ export async function exportContributionAlerts(changes) {
));
const contributions = dilaAlertChanges.flatMap((alert) => {
const targetedContribs = alert.documents.filter(
(targetDoc) => targetDoc.document.type == "contributions"
(targetDoc) => targetDoc.document.source == "contributions"
);
if (targetedContribs.length === 0) {
return [];
Expand All @@ -27,6 +29,11 @@ export async function exportContributionAlerts(changes) {
}));
});
});
console.log(JSON.stringify(contributions, null, 2));
return contributions;
await fetch(contribApi, {
body: JSON.stringify(contributions),
headers: {
"Content-Type": "application/json",
},
method: "POST",
});
}
2 changes: 1 addition & 1 deletion targets/alert-cli/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type AstChanges = {
}

type Changes = AstChanges & {
documents: { document: DocumentInfo, reference: ParseDilaReference[] }[]
documents: { document: DocumentInfo, references: ParseDilaReference[] }[]
}

type DilaAlertChanges = {
Expand Down
19 changes: 18 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3302,6 +3302,14 @@
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.0.tgz#69a23a3ad29caf0097f06eda59b361ee2f0639f6"
integrity sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=

"@types/node-fetch@^2.5.7":
version "2.5.7"
resolved "https://registry.yarnpkg.com/@types/node-fetch/-/node-fetch-2.5.7.tgz#20a2afffa882ab04d44ca786449a276f9f6bbf3c"
integrity sha512-o2WVNf5UhWRkxlf6eq+jMZDu7kjgpgJfl4xVNlvryc95O/6F2ld8ztKX+qu+Rjyet93WAWm5LjeX9H5FGkODvw==
dependencies:
"@types/node" "*"
form-data "^3.0.0"

"@types/node@*", "@types/node@>= 8", "@types/node@^14.14.6":
version "14.14.6"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.6.tgz#146d3da57b3c636cc0d1769396ce1cfa8991147f"
Expand Down Expand Up @@ -5084,7 +5092,7 @@ columnify@^1.5.4:
strip-ansi "^3.0.0"
wcwidth "^1.0.0"

combined-stream@^1.0.6, combined-stream@~1.0.6:
combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6:
version "1.0.8"
resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f"
integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==
Expand Down Expand Up @@ -7306,6 +7314,15 @@ forever-agent@~0.6.1:
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
integrity sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=

form-data@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-3.0.0.tgz#31b7e39c85f1355b7139ee0c647cf0de7f83c682"
integrity sha512-CKMFDglpbMi6PyN+brwB9Q/GOw0eAnsrEZDgcsH5Krhz5Od/haKHAX0NmQfha2zPPz0JpWzA7GJHGSnvCRLWsg==
dependencies:
asynckit "^0.4.0"
combined-stream "^1.0.8"
mime-types "^2.1.12"

form-data@~2.3.2:
version "2.3.3"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.3.tgz#dcce52c05f644f298c6a7ab936bd724ceffbf3a6"
Expand Down

0 comments on commit 1cbc217

Please sign in to comment.