Refactored communication with partner app to use custom objects + error handling BOD-83 BOD-138 BOD-139

This commit is contained in:
Patrick Fic
2020-06-02 17:46:51 -07:00
parent 6060def9f4
commit 59f21b95b1
12 changed files with 176 additions and 55 deletions

View File

@@ -44,7 +44,7 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
let PartnerResponse;
try {
PartnerResponse = await axios.post(
"http://localhost:1337/qb/",
"http://e9c5a8ed9079.ngrok.io/qb/",
QbXmlResponse.data,
{
headers: {
@@ -62,26 +62,40 @@ export function JobsCloseExportButton({ bodyshop, jobId, disabled }) {
}
console.log("PartnerResponse", PartnerResponse);
const jobUpdateResponse = await updateJob({
variables: {
jobId: jobId,
job: {
status: bodyshop.md_ro_statuses.default_exported || "Exported*",
date_exported: new Date(),
},
},
});
if (!!!jobUpdateResponse.errors) {
notification["success"]({
message: t("jobs.successes.exported"),
});
//Check to see if any of them failed. If they didn't don't execute the update.
const failedTransactions = PartnerResponse.data.filter((r) => !r.success);
if (failedTransactions.length > 0) {
//Uh oh. At least one was no good.
failedTransactions.map((ft) =>
notification["error"]({
message: t("jobs.errors.exporting", {
error: ft.errorMessage || "",
}),
})
);
} else {
notification["error"]({
message: t("jobs.errors.exporting", {
error: JSON.stringify(jobUpdateResponse.error),
}),
const jobUpdateResponse = await updateJob({
variables: {
jobId: jobId,
job: {
status: bodyshop.md_ro_statuses.default_exported || "Exported*",
date_exported: new Date(),
},
},
});
if (!!!jobUpdateResponse.errors) {
notification["success"]({
message: t("jobs.successes.exported"),
});
} else {
notification["error"]({
message: t("jobs.errors.exporting", {
error: JSON.stringify(jobUpdateResponse.error),
}),
});
}
}
setLoading(false);