IO-2222 Service Side Generation of part price changes.

This commit is contained in:
Patrick Fic
2023-03-16 13:33:20 -07:00
parent c11cef4119
commit 4e2ad3bc62
9 changed files with 200 additions and 18 deletions

View File

@@ -0,0 +1,45 @@
const path = require("path");
const _ = require("lodash");
const logger = require("../utils/logger");
const queries = require("../graphql-client/queries");
const GraphQLClient = require("graphql-request").GraphQLClient;
const moment = require("moment-timezone");
require("dotenv").config({
path: path.resolve(
process.cwd(),
`.env.${process.env.NODE_ENV || "development"}`
),
});
exports.generatePpc = async (req, res) => {
const { jobid } = req.body;
const BearerToken = req.headers.authorization;
logger.log("generate-ppc", "DEBUG", req.user.email, jobid, null);
const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
headers: {
Authorization: BearerToken,
},
});
try {
const { jobs_by_pk: job } = await client
.setHeaders({ Authorization: BearerToken })
.request(queries.GET_JOB_FOR_PPC, {
jobid: jobid,
});
const ReturnVal = {
...job,
trans_type: "P",
create_dt: moment().tz(job.bodyshop.timezone).format("yyyyMMDD"),
create_tm: moment().tz(job.bodyshop.timezone).format("HHmmSS"),
incl_est: true,
joblines: job.joblines.map((jl) => ({ ...jl, tran_code: 2 })),
};
res.json(ReturnVal);
} catch (error) {
res.status(400).Send(JSON.stringify(error));
}
};

View File

@@ -1718,3 +1718,19 @@ query GET_PBS_AP_ALLOCATIONS($billids: [uuid!]) {
}
}
`;
exports.GET_JOB_FOR_PPC = `query GET_JOB_FOR_PPC($jobid: uuid!) {
jobs_by_pk(id: $jobid) {
id
ciecaid
ro_number
joblines(where: {removed: {_eq: false}}) {
id
act_price
unq_seq
}
bodyshop {
timezone
}
}
}`;