IO-2222 Service Side Generation of part price changes.
This commit is contained in:
45
server/ccc/partspricechange.js
Normal file
45
server/ccc/partspricechange.js
Normal 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));
|
||||
}
|
||||
};
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}`;
|
||||
|
||||
Reference in New Issue
Block a user