Merge remote-tracking branch 'origin/master-AIO' into feature/IO-2776-cdk-fortellis
This commit is contained in:
@@ -919,16 +919,16 @@ exports.default = function ({ bodyshop, jobs_by_pk, qbo = false, items, taxCodes
|
||||
FullName: responsibilityCenters.ttl_tax_adjustment?.accountitem
|
||||
},
|
||||
Desc: "Tax Adjustment",
|
||||
Quantity: 1,
|
||||
//Quantity: 1,
|
||||
Amount: Dinero(jobs_by_pk.job_totals.totals?.ttl_tax_adjustment).toFormat(DineroQbFormat),
|
||||
SalesTaxCodeRef: InstanceManager({
|
||||
imex: {
|
||||
FullName: "E"
|
||||
},
|
||||
rome: {
|
||||
FullName: bodyshop.md_responsibility_centers.taxes.itemexemptcode || "NON"
|
||||
}
|
||||
})
|
||||
// SalesTaxCodeRef: InstanceManager({
|
||||
// imex: {
|
||||
// FullName: "E"
|
||||
// },
|
||||
// rome: {
|
||||
// FullName: bodyshop.md_responsibility_centers.taxes.itemexemptcode || "NON"
|
||||
// }
|
||||
// })
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
37
server/data/analytics/documents.js
Normal file
37
server/data/analytics/documents.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const logger = require("../../utils/logger");
|
||||
const { client } = require('../../graphql-client/graphql-client');
|
||||
const { INSERT_MEDIA_ANALYTICS, GET_BODYSHOP_BY_ID } = require("../../graphql-client/queries");
|
||||
|
||||
const documentAnalytics = async (req, res) => {
|
||||
try {
|
||||
const { data } = req.body;
|
||||
|
||||
//Check if the bodyshopid is real as a "security" measure
|
||||
if (!data.bodyshopid) {
|
||||
throw new Error("No bodyshopid provided in data");
|
||||
}
|
||||
|
||||
const { bodyshops_by_pk } = await client.request(GET_BODYSHOP_BY_ID, {
|
||||
id: data.bodyshopid
|
||||
});
|
||||
|
||||
if (!bodyshops_by_pk) {
|
||||
throw new Error("Invalid bodyshopid provided in data");
|
||||
}
|
||||
|
||||
await client.request(INSERT_MEDIA_ANALYTICS, {
|
||||
mediaObject: data
|
||||
});
|
||||
|
||||
res.json({ status: "success" })
|
||||
} catch (error) {
|
||||
logger.log("document-analytics-error", "ERROR", req?.user?.email, null, {
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
});
|
||||
res.status(500).json({ error: error.message, stack: error.stack });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
exports.default = documentAnalytics;
|
||||
@@ -277,6 +277,7 @@ const GenerateDetailLines = (line) => {
|
||||
line_desc: line.line_desc ? line.line_desc.replace(NON_ASCII_REGEX, "") : null,
|
||||
oem_partno: line.oem_partno ? line.oem_partno.replace(NON_ASCII_REGEX, "") : null,
|
||||
alt_partno: line.alt_partno ? line.alt_partno.replace(NON_ASCII_REGEX, "") : null,
|
||||
op_code: line.lbr_op || null,
|
||||
op_code_desc: generateOpCodeDescription(line.lbr_op),
|
||||
lbr_ty: generateLaborType(line.mod_lbr_ty),
|
||||
lbr_hrs: line.mod_lb_hrs || 0,
|
||||
|
||||
@@ -336,6 +336,7 @@ const GenerateDetailLines = (line) => {
|
||||
line_desc: line.line_desc ? line.line_desc.replace(NON_ASCII_REGEX, "") : null,
|
||||
oem_partno: line.oem_partno ? line.oem_partno.replace(NON_ASCII_REGEX, "") : null,
|
||||
alt_partno: line.alt_partno ? line.alt_partno.replace(NON_ASCII_REGEX, "") : null,
|
||||
op_code: line.lbr_op || null,
|
||||
op_code_desc: line.op_code_desc ? line.op_code_desc.replace(NON_ASCII_REGEX, "") : null,
|
||||
lbr_ty: generateLaborType(line.mod_lbr_ty),
|
||||
lbr_hrs: line.mod_lb_hrs || 0,
|
||||
|
||||
@@ -8,4 +8,5 @@ exports.podium = require("./podium").default;
|
||||
exports.emsUpload = require("./emsUpload").default;
|
||||
exports.carfax = require("./carfax").default;
|
||||
exports.carfaxRps = require("./carfax-rps").default;
|
||||
exports.vehicletype = require("./vehicletype/vehicletype").default;
|
||||
exports.vehicletype = require("./vehicletype/vehicletype").default;
|
||||
exports.documentAnalytics = require("./analytics/documents").default;
|
||||
@@ -47,11 +47,6 @@ const logEmail = async (req, email) => {
|
||||
const sendServerEmail = async ({ subject, text, to = [] }) => {
|
||||
if (process.env.NODE_ENV === undefined) return;
|
||||
|
||||
let sentTo = ["support@imexsystems.ca"];
|
||||
if (to?.length) {
|
||||
sentTo = [...sentTo, ...to];
|
||||
}
|
||||
|
||||
try {
|
||||
mailer.sendMail(
|
||||
{
|
||||
@@ -59,7 +54,7 @@ const sendServerEmail = async ({ subject, text, to = [] }) => {
|
||||
imex: `ImEX Online API - ${process.env.NODE_ENV} <noreply@imex.online>`,
|
||||
rome: `Rome Online API - ${process.env.NODE_ENV} <noreply@romeonline.io>`
|
||||
}),
|
||||
to: sentTo,
|
||||
to: ["support@imexsystems.ca", ...to],
|
||||
subject: subject,
|
||||
text: text,
|
||||
ses: {
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
const logger = require("../utils/logger");
|
||||
|
||||
const GraphQLClient = require("graphql-request").GraphQLClient;
|
||||
|
||||
//New bug introduced with Graphql Request.
|
||||
@@ -14,17 +12,18 @@ const client = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||
});
|
||||
|
||||
const rpsClient =
|
||||
process.env.RPS_GRAPHQL_ENDPOINT && process.env.RPS_HASURA_ADMIN_SECRET ?
|
||||
new GraphQLClient(process.env.RPS_GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
"x-hasura-admin-secret": process.env.RPS_HASURA_ADMIN_SECRET
|
||||
}
|
||||
}) : null;
|
||||
process.env.RPS_GRAPHQL_ENDPOINT && process.env.RPS_HASURA_ADMIN_SECRET
|
||||
? new GraphQLClient(process.env.RPS_GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
"x-hasura-admin-secret": process.env.RPS_HASURA_ADMIN_SECRET
|
||||
}
|
||||
})
|
||||
: null;
|
||||
|
||||
if (!rpsClient) {
|
||||
//System log to disable RPS functions
|
||||
logger.log(`RPS secrets are not set. Client is not configured.`, "WARN", "redis", "api", {
|
||||
});
|
||||
|
||||
console.log(`RPS secrets are not set. Client is not configured.`, "WARN", "redis", "api", {});
|
||||
}
|
||||
|
||||
const unauthorizedClient = new GraphQLClient(process.env.GRAPHQL_ENDPOINT);
|
||||
|
||||
@@ -904,6 +904,7 @@ exports.CARFAX_QUERY = `query CARFAX_EXPORT($start: timestamptz, $bodyshopid: uu
|
||||
line_desc
|
||||
mod_lb_hrs
|
||||
mod_lbr_ty
|
||||
lbr_op
|
||||
oem_partno
|
||||
op_code_desc
|
||||
part_type
|
||||
@@ -2901,6 +2902,7 @@ exports.GET_BODYSHOP_BY_ID = `
|
||||
intellipay_config
|
||||
state
|
||||
notification_followers
|
||||
timezone
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -2992,6 +2994,7 @@ query GET_JOBID_BY_MERCHANTID_RONUMBER($merchantID: String!, $roNumber: String!)
|
||||
id
|
||||
intellipay_config
|
||||
email
|
||||
timezone
|
||||
}
|
||||
}
|
||||
}`;
|
||||
@@ -3001,6 +3004,7 @@ query GET_BODYSHOP_BY_MERCHANTID($merchantID: String!) {
|
||||
bodyshops(where: {intellipay_merchant_id: {_eq: $merchantID}}) {
|
||||
id
|
||||
email
|
||||
timezone
|
||||
}
|
||||
}`;
|
||||
|
||||
@@ -3147,3 +3151,12 @@ exports.DELETE_PHONE_NUMBER_OPT_OUT = `
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
exports.INSERT_MEDIA_ANALYTICS = `
|
||||
mutation INSERT_MEDIA_ANALYTICS($mediaObject: media_analytics_insert_input!) {
|
||||
insert_media_analytics_one(object: $mediaObject) {
|
||||
id
|
||||
}
|
||||
}
|
||||
`
|
||||
@@ -7,7 +7,8 @@ const {
|
||||
CREATE_SHOP,
|
||||
DELETE_VENDORS_BY_SHOP,
|
||||
DELETE_SHOP,
|
||||
CREATE_USER
|
||||
CREATE_USER,
|
||||
UPDATE_BODYSHOP_BY_ID
|
||||
} = require("../partsManagement.queries");
|
||||
|
||||
/**
|
||||
@@ -131,6 +132,61 @@ const insertUserAssociation = async (uid, email, shopId) => {
|
||||
return resp.insert_users_one;
|
||||
};
|
||||
|
||||
/**
|
||||
* PATCH handler for updating bodyshop fields.
|
||||
* Allows patching: shopname, address1, address2, city, state, zip_post, country, email, timezone, phone, logo_img_path
|
||||
* @param req
|
||||
* @param res
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const patchPartsManagementProvisioning = async (req, res) => {
|
||||
const { id } = req.params;
|
||||
const allowedFields = [
|
||||
"shopname",
|
||||
"address1",
|
||||
"address2",
|
||||
"city",
|
||||
"state",
|
||||
"zip_post",
|
||||
"country",
|
||||
"email",
|
||||
"timezone",
|
||||
"phone",
|
||||
"logo_img_path"
|
||||
];
|
||||
const updateFields = {};
|
||||
for (const field of allowedFields) {
|
||||
if (req.body[field] !== undefined) {
|
||||
updateFields[field] = req.body[field];
|
||||
}
|
||||
}
|
||||
if (Object.keys(updateFields).length === 0) {
|
||||
return res.status(400).json({ error: "No valid fields provided for update." });
|
||||
}
|
||||
// Check that the bodyshop has an external_shop_id before allowing patch
|
||||
try {
|
||||
// Fetch the bodyshop by id
|
||||
const shopResp = await client.request(
|
||||
`query GetBodyshop($id: uuid!) { bodyshops_by_pk(id: $id) { id external_shop_id } }`,
|
||||
{ id }
|
||||
);
|
||||
if (!shopResp.bodyshops_by_pk?.external_shop_id) {
|
||||
return res.status(400).json({ error: "Cannot patch: bodyshop does not have an external_shop_id." });
|
||||
}
|
||||
} catch (err) {
|
||||
return res.status(500).json({ error: "Failed to validate bodyshop external_shop_id.", detail: err });
|
||||
}
|
||||
try {
|
||||
const resp = await client.request(UPDATE_BODYSHOP_BY_ID, { id, fields: updateFields });
|
||||
if (!resp.update_bodyshops_by_pk) {
|
||||
return res.status(404).json({ error: "Bodyshop not found." });
|
||||
}
|
||||
return res.json(resp.update_bodyshops_by_pk);
|
||||
} catch (err) {
|
||||
return res.status(500).json({ error: "Failed to update bodyshop.", detail: err });
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Handles provisioning a new shop for parts management.
|
||||
* @param req
|
||||
@@ -259,4 +315,4 @@ const partsManagementProvisioning = async (req, res) => {
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = partsManagementProvisioning;
|
||||
module.exports = { partsManagementProvisioning, patchPartsManagementProvisioning };
|
||||
|
||||
@@ -298,6 +298,25 @@ const UPDATE_JOBLINE_BY_PK = `
|
||||
}
|
||||
`;
|
||||
|
||||
const UPDATE_BODYSHOP_BY_ID = `
|
||||
mutation UpdateBodyshopById($id: uuid!, $fields: bodyshops_set_input!) {
|
||||
update_bodyshops_by_pk(pk_columns: { id: $id }, _set: $fields) {
|
||||
id
|
||||
shopname
|
||||
address1
|
||||
address2
|
||||
city
|
||||
state
|
||||
zip_post
|
||||
country
|
||||
email
|
||||
timezone
|
||||
phone
|
||||
logo_img_path
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
module.exports = {
|
||||
GET_BODYSHOP_STATUS,
|
||||
GET_VEHICLE_BY_SHOP_VIN,
|
||||
@@ -329,5 +348,6 @@ module.exports = {
|
||||
DELETE_PARTS_ORDERS_BY_JOB_IDS,
|
||||
UPSERT_JOBLINES,
|
||||
GET_JOBLINE_IDS_BY_JOBID_UNQSEQ,
|
||||
UPDATE_JOBLINE_BY_PK
|
||||
UPDATE_JOBLINE_BY_PK,
|
||||
UPDATE_BODYSHOP_BY_ID
|
||||
};
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
openapi: 3.0.3
|
||||
info:
|
||||
title: Parts Management Provisioning API
|
||||
description: API endpoint to provision a new shop and user in the Parts Management system.
|
||||
version: 1.0.0
|
||||
|
||||
paths:
|
||||
/parts-management/provision:
|
||||
post:
|
||||
summary: Provision a new parts management shop and user
|
||||
operationId: partsManagementProvisioning
|
||||
tags:
|
||||
- Parts Management
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required:
|
||||
- external_shop_id
|
||||
- shopname
|
||||
- address1
|
||||
- city
|
||||
- state
|
||||
- zip_post
|
||||
- country
|
||||
- email
|
||||
- phone
|
||||
- userEmail
|
||||
properties:
|
||||
external_shop_id:
|
||||
type: string
|
||||
description: External shop ID (must be unique)
|
||||
shopname:
|
||||
type: string
|
||||
address1:
|
||||
type: string
|
||||
address2:
|
||||
type: string
|
||||
nullable: true
|
||||
city:
|
||||
type: string
|
||||
state:
|
||||
type: string
|
||||
zip_post:
|
||||
type: string
|
||||
country:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
phone:
|
||||
type: string
|
||||
userEmail:
|
||||
type: string
|
||||
format: email
|
||||
userPassword:
|
||||
type: string
|
||||
description: Optional password for the new user. If provided, the password is set directly, and no password reset link is sent. Must be at least 6 characters.
|
||||
nullable: true
|
||||
logoUrl:
|
||||
type: string
|
||||
format: uri
|
||||
nullable: true
|
||||
timezone:
|
||||
type: string
|
||||
nullable: true
|
||||
vendors:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
street1:
|
||||
type: string
|
||||
nullable: true
|
||||
street2:
|
||||
type: string
|
||||
nullable: true
|
||||
city:
|
||||
type: string
|
||||
nullable: true
|
||||
state:
|
||||
type: string
|
||||
nullable: true
|
||||
zip:
|
||||
type: string
|
||||
nullable: true
|
||||
country:
|
||||
type: string
|
||||
nullable: true
|
||||
email:
|
||||
type: string
|
||||
format: email
|
||||
nullable: true
|
||||
discount:
|
||||
type: number
|
||||
nullable: true
|
||||
due_date:
|
||||
type: string
|
||||
format: date
|
||||
nullable: true
|
||||
cost_center:
|
||||
type: string
|
||||
nullable: true
|
||||
favorite:
|
||||
type: array
|
||||
items:
|
||||
type: string
|
||||
nullable: true
|
||||
phone:
|
||||
type: string
|
||||
nullable: true
|
||||
active:
|
||||
type: boolean
|
||||
nullable: true
|
||||
dmsid:
|
||||
type: string
|
||||
nullable: true
|
||||
responses:
|
||||
'200':
|
||||
description: Shop and user successfully created
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
shop:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
format: uuid
|
||||
shopname:
|
||||
type: string
|
||||
user:
|
||||
type: object
|
||||
properties:
|
||||
id:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
resetLink:
|
||||
type: string
|
||||
format: uri
|
||||
nullable: true
|
||||
description: Password reset link for the user. Only included if userPassword is not provided in the request.
|
||||
'400':
|
||||
description: Bad request (missing or invalid fields)
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
error:
|
||||
type: string
|
||||
'500':
|
||||
description: Internal server error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
error:
|
||||
type: string
|
||||
@@ -48,7 +48,9 @@ const handleCommentBasedPayment = async (values, decodedComment, logger, logMeta
|
||||
payer: "Customer",
|
||||
type: getPaymentType(ipMapping, values.cardtype),
|
||||
jobid: p.jobid,
|
||||
date: moment(Date.now()),
|
||||
date: moment()
|
||||
.tz(bodyshop?.bodyshops_by_pk?.timezone ?? "UTC")
|
||||
.format("YYYY-MM-DD"),
|
||||
payment_responses: {
|
||||
data: {
|
||||
amount: values.total,
|
||||
|
||||
@@ -97,7 +97,9 @@ const handleInvoiceBasedPayment = async (values, logger, logMeta, res) => {
|
||||
payer: "Customer",
|
||||
type: getPaymentType(ipMapping, values.cardtype),
|
||||
jobid: job.id,
|
||||
date: moment(Date.now())
|
||||
date: moment()
|
||||
.tz(bodyshop?.timezone ?? "UTC")
|
||||
.format("YYYY-MM-DD")
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -405,7 +405,7 @@ function GenerateCostingData(job) {
|
||||
) {
|
||||
const discountRate =
|
||||
Math.abs(job.parts_tax_rates[val.part_type.toUpperCase()].prt_discp) > 1
|
||||
? job.parts_tax_rates_rates[val.part_type.toUpperCase()].prt_discp
|
||||
? job.parts_tax_rates[val.part_type.toUpperCase()].prt_discp
|
||||
: job.parts_tax_rates[val.part_type.toUpperCase()].prt_discp * 100;
|
||||
const disc = partsAmount.percentage(discountRate).multiply(-1);
|
||||
partsAmount = partsAmount.add(disc);
|
||||
|
||||
@@ -24,7 +24,7 @@ exports.totalsSsu = async function (req, res) {
|
||||
const BearerToken = req.BearerToken;
|
||||
const client = req.userGraphQLClient;
|
||||
|
||||
logger.log("job-totals-ssu-USA", "DEBUG", req?.user?.email, id);
|
||||
logger.log("job-totals-ssu-USA", "debug", req?.user?.email, id);
|
||||
|
||||
try {
|
||||
const job = await client.setHeaders({ Authorization: BearerToken }).request(queries.GET_JOB_BY_PK, {
|
||||
@@ -49,7 +49,7 @@ exports.totalsSsu = async function (req, res) {
|
||||
|
||||
res.status(200).send();
|
||||
} catch (error) {
|
||||
logger.log("job-totals-ssu-USA-error", "ERROR", req?.user?.email, id, {
|
||||
logger.log("job-totals-ssu-USA-error", "error", req?.user?.email, id, {
|
||||
jobid: id,
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
@@ -95,7 +95,7 @@ async function TotalsServerSide(req, res) {
|
||||
ret.totals.subtotal = ret.totals.subtotal.add(ret.totals.ttl_adjustment);
|
||||
ret.totals.total_repairs = ret.totals.total_repairs.add(ret.totals.ttl_adjustment);
|
||||
ret.totals.net_repairs = ret.totals.net_repairs.add(ret.totals.ttl_adjustment);
|
||||
logger.log("job-totals-USA-ttl-adj", "DEBUG", null, job.id, {
|
||||
logger.log("job-totals-USA-ttl-adj", "debug", null, job.id, {
|
||||
adjAmount: ttlDifference
|
||||
});
|
||||
}
|
||||
@@ -116,7 +116,7 @@ async function TotalsServerSide(req, res) {
|
||||
ret.totals.ttl_tax_adjustment = Dinero({ amount: Math.round(ttlTaxDifference * 100) });
|
||||
ret.totals.total_repairs = ret.totals.total_repairs.add(ret.totals.ttl_tax_adjustment);
|
||||
ret.totals.net_repairs = ret.totals.net_repairs.add(ret.totals.ttl_tax_adjustment);
|
||||
logger.log("job-totals-USA-ttl-tax-adj", "DEBUG", null, job.id, {
|
||||
logger.log("job-totals-USA-ttl-tax-adj", "debug", null, job.id, {
|
||||
adjAmount: ttlTaxDifference
|
||||
});
|
||||
}
|
||||
@@ -124,7 +124,7 @@ async function TotalsServerSide(req, res) {
|
||||
|
||||
return ret;
|
||||
} catch (error) {
|
||||
logger.log("job-totals-ssu-USA-error", "ERROR", req.user?.email, job.id, {
|
||||
logger.log("job-totals-ssu-USA-error", "error", req.user?.email, job.id, {
|
||||
jobid: job.id,
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
@@ -142,7 +142,7 @@ async function Totals(req, res) {
|
||||
const logger = req.logger;
|
||||
const client = req.userGraphQLClient;
|
||||
|
||||
logger.log("job-totals-ssu-USA", "DEBUG", req.user.email, job.id, {
|
||||
logger.log("job-totals-ssu-USA", "debug", req.user.email, job.id, {
|
||||
jobid: job.id,
|
||||
id: id
|
||||
});
|
||||
@@ -159,7 +159,7 @@ async function Totals(req, res) {
|
||||
|
||||
res.status(200).json(ret);
|
||||
} catch (error) {
|
||||
logger.log("job-totals-ssu-USA-error", "ERROR", req.user.email, job.id, {
|
||||
logger.log("job-totals-ssu-USA-error", "error", req.user.email, job.id, {
|
||||
jobid: job.id,
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
@@ -240,7 +240,7 @@ async function AtsAdjustmentsIfRequired({ job, client, user }) {
|
||||
job.joblines.push(newAtsLine);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.log("job-totals-ssu-ats-error", "ERROR", user?.email, job.id, {
|
||||
logger.log("job-totals-ssu-ats-error", "error", user?.email, job.id, {
|
||||
jobid: job.id,
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
@@ -258,7 +258,7 @@ async function AtsAdjustmentsIfRequired({ job, client, user }) {
|
||||
job.joblines[atsLineIndex].act_price = atsAmount;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.log("job-totals-ssu-ats-error", "ERROR", user?.email, job.id, {
|
||||
logger.log("job-totals-ssu-ats-error", "error", user?.email, job.id, {
|
||||
jobid: job.id,
|
||||
atsLineIndex: atsLineIndex,
|
||||
atsAmount: atsAmount,
|
||||
@@ -381,7 +381,7 @@ async function CalculateRatesTotals({ job, client }) {
|
||||
|
||||
if (item.mod_lbr_ty) {
|
||||
//Check to see if it has 0 hours and a price instead.
|
||||
if (item.lbr_op === "OP14" && item.act_price > 0 && (!item.part_type || item.mod_lb_hrs === 0)) {
|
||||
if (item.lbr_op === "OP14" && item.act_price > 0 && (!item.part_type || item.mod_lb_hrs === 0) && !IsAdditionalCost(item)) {
|
||||
//Scenario where SGI may pay out hours using a part price.
|
||||
if (!ret[item.mod_lbr_ty.toLowerCase()].total) {
|
||||
ret[item.mod_lbr_ty.toLowerCase()].base = Dinero();
|
||||
@@ -1055,7 +1055,7 @@ function CalculateTaxesTotals(job, otherTotals) {
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
logger.log("job-totals-USA Key with issue", "error", null, job.id, {
|
||||
logger.log("job-totals-USA Key with issue", "warn", null, job.id, {
|
||||
key: key,
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
|
||||
@@ -23,7 +23,7 @@ exports.totalsSsu = async function (req, res) {
|
||||
const BearerToken = req.BearerToken;
|
||||
const client = req.userGraphQLClient;
|
||||
|
||||
logger.log("job-totals-ssu", "DEBUG", req.user.email, id, null);
|
||||
logger.log("job-totals-ssu", "debug", req.user.email, id, null);
|
||||
|
||||
try {
|
||||
const job = await client.setHeaders({ Authorization: BearerToken }).request(queries.GET_JOB_BY_PK, {
|
||||
@@ -49,7 +49,7 @@ exports.totalsSsu = async function (req, res) {
|
||||
|
||||
res.status(200).send();
|
||||
} catch (error) {
|
||||
logger.log("job-totals-ssu-error", "ERROR", req.user.email, id, {
|
||||
logger.log("job-totals-ssu-error", "error", req.user.email, id, {
|
||||
jobid: id,
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
@@ -73,7 +73,7 @@ async function TotalsServerSide(req, res) {
|
||||
|
||||
return ret;
|
||||
} catch (error) {
|
||||
logger.log("job-totals-ssu-error", "ERROR", req?.user?.email, job.id, {
|
||||
logger.log("job-totals-ssu-error", "error", req?.user?.email, job.id, {
|
||||
jobid: job.id,
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
@@ -91,7 +91,7 @@ async function Totals(req, res) {
|
||||
const logger = req.logger;
|
||||
const client = req.userGraphQLClient;
|
||||
|
||||
logger.log("job-totals-ssu", "DEBUG", req.user.email, job.id, {
|
||||
logger.log("job-totals-ssu", "debug", req.user.email, job.id, {
|
||||
jobid: job.id,
|
||||
id: id
|
||||
});
|
||||
@@ -108,7 +108,7 @@ async function Totals(req, res) {
|
||||
|
||||
res.status(200).json(ret);
|
||||
} catch (error) {
|
||||
logger.log("job-totals-ssu-error", "ERROR", req.user.email, job.id, {
|
||||
logger.log("job-totals-ssu-error", "error", req.user.email, job.id, {
|
||||
jobid: job.id,
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
@@ -189,7 +189,7 @@ async function AtsAdjustmentsIfRequired({ job, client, user }) {
|
||||
job.joblines.push(newAtsLine);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.log("job-totals-ssu-ats-error", "ERROR", user?.email, job.id, {
|
||||
logger.log("job-totals-ssu-ats-error", "error", user?.email, job.id, {
|
||||
jobid: job.id,
|
||||
error: error.message,
|
||||
stack: error.stack
|
||||
@@ -207,7 +207,7 @@ async function AtsAdjustmentsIfRequired({ job, client, user }) {
|
||||
job.joblines[atsLineIndex].act_price = atsAmount;
|
||||
}
|
||||
} catch (error) {
|
||||
logger.log("job-totals-ssu-ats-error", "ERROR", user?.email, job.id, {
|
||||
logger.log("job-totals-ssu-ats-error", "error", user?.email, job.id, {
|
||||
jobid: job.id,
|
||||
atsLineIndex: atsLineIndex,
|
||||
atsAmount: atsAmount,
|
||||
@@ -315,7 +315,7 @@ function CalculateRatesTotals(ratesList) {
|
||||
if (item.mod_lbr_ty) {
|
||||
//Check to see if it has 0 hours and a price instead.
|
||||
//Extend for when there are hours and a price.
|
||||
if (item.lbr_op === "OP14" && item.act_price > 0 && (!item.part_type || item.mod_lb_hrs === 0)) {
|
||||
if (item.lbr_op === "OP14" && item.act_price > 0 && (!item.part_type || item.mod_lb_hrs === 0) && !IsAdditionalCost(item)) {
|
||||
//Scenario where SGI may pay out hours using a part price.
|
||||
if (!ret[item.mod_lbr_ty.toLowerCase()].total) {
|
||||
ret[item.mod_lbr_ty.toLowerCase()].total = Dinero();
|
||||
|
||||
40
server/job/patchJobStatus.js
Normal file
40
server/job/patchJobStatus.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const client = require("../graphql-client/graphql-client").client;
|
||||
const { UPDATE_JOB_BY_ID } = require("../integrations/partsManagement/partsManagement.queries");
|
||||
|
||||
/**
|
||||
* PATCH handler to update job status (parts management only)
|
||||
* @param req
|
||||
* @param res
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
module.exports = async (req, res) => {
|
||||
const { id } = req.params;
|
||||
const { status } = req.body;
|
||||
if (!status) {
|
||||
return res.status(400).json({ error: "Missing required field: status" });
|
||||
}
|
||||
try {
|
||||
// Fetch job to get shopid
|
||||
const jobResp = await client.request(`query GetJob($id: uuid!) { jobs_by_pk(id: $id) { id shopid } }`, { id });
|
||||
const job = jobResp.jobs_by_pk;
|
||||
if (!job) {
|
||||
return res.status(404).json({ error: "Job not found" });
|
||||
}
|
||||
// Fetch bodyshop to check external_shop_id
|
||||
const shopResp = await client.request(
|
||||
`query GetBodyshop($id: uuid!) { bodyshops_by_pk(id: $id) { id external_shop_id } }`,
|
||||
{ id: job.shopid }
|
||||
);
|
||||
if (!shopResp.bodyshops_by_pk || !shopResp.bodyshops_by_pk.external_shop_id) {
|
||||
return res.status(400).json({ error: "Cannot patch: parent bodyshop does not have an external_shop_id." });
|
||||
}
|
||||
// Update job status
|
||||
const updateResp = await client.request(UPDATE_JOB_BY_ID, { id, job: { status } });
|
||||
if (!updateResp.update_jobs_by_pk) {
|
||||
return res.status(404).json({ error: "Job not found after update" });
|
||||
}
|
||||
return res.json(updateResp.update_jobs_by_pk);
|
||||
} catch (err) {
|
||||
return res.status(500).json({ error: "Failed to update job status.", detail: err });
|
||||
}
|
||||
};
|
||||
@@ -92,7 +92,7 @@ const loadAppQueue = async ({ pubClient, logger, redisHelpers, ioRedis }) => {
|
||||
"consolidate-notifications",
|
||||
{ jobId, recipients },
|
||||
{
|
||||
jobId: `consolidate:${jobId}`,
|
||||
jobId: `consolidate-${jobId}`,
|
||||
delay: APP_CONSOLIDATION_DELAY,
|
||||
attempts: 3,
|
||||
backoff: LOCK_EXPIRATION
|
||||
@@ -288,7 +288,7 @@ const dispatchAppsToQueue = async ({ appsToDispatch }) => {
|
||||
await appQueue.add(
|
||||
"add-notification",
|
||||
{ jobId, bodyShopId, key, variables, recipients, body, jobRoNumber },
|
||||
{ jobId: `${jobId}:${Date.now()}` }
|
||||
{ jobId: `${jobId}-${Date.now()}` }
|
||||
);
|
||||
devDebugLogger(`Added notification to queue for jobId ${jobId} with ${recipients.length} recipients`);
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ const loadEmailQueue = async ({ pubClient, logger }) => {
|
||||
"consolidate-emails",
|
||||
{ jobId, jobRoNumber, bodyShopName, bodyShopTimezone },
|
||||
{
|
||||
jobId: `consolidate:${jobId}`,
|
||||
jobId: `consolidate-${jobId}`,
|
||||
delay: EMAIL_CONSOLIDATION_DELAY,
|
||||
attempts: 3,
|
||||
backoff: LOCK_EXPIRATION
|
||||
@@ -252,7 +252,7 @@ const dispatchEmailsToQueue = async ({ emailsToDispatch, logger }) => {
|
||||
await emailAddQueue.add(
|
||||
"add-email-notification",
|
||||
{ jobId, jobRoNumber, bodyShopName, bodyShopTimezone, body, recipients },
|
||||
{ jobId: `${jobId}:${Date.now()}` }
|
||||
{ jobId: `${jobId}-${Date.now()}` }
|
||||
);
|
||||
devDebugLogger(`Added email notification to queue for jobId ${jobId} with ${recipients.length} recipients`);
|
||||
}
|
||||
|
||||
@@ -19,11 +19,15 @@ if (typeof VSSTA_INTEGRATION_SECRET === "string" && VSSTA_INTEGRATION_SECRET.len
|
||||
if (typeof PARTS_MANAGEMENT_INTEGRATION_SECRET === "string" && PARTS_MANAGEMENT_INTEGRATION_SECRET.length > 0) {
|
||||
const XML_BODY_LIMIT = "10mb"; // Set a limit for XML body size
|
||||
|
||||
const partsManagementProvisioning = require("../integrations/partsManagement/endpoints/partsManagementProvisioning");
|
||||
const {
|
||||
partsManagementProvisioning,
|
||||
patchPartsManagementProvisioning
|
||||
} = require("../integrations/partsManagement/endpoints/partsManagementProvisioning");
|
||||
const partsManagementDeprovisioning = require("../integrations/partsManagement/endpoints/partsManagementDeprovisioning");
|
||||
const partsManagementIntegrationMiddleware = require("../middleware/partsManagementIntegrationMiddleware");
|
||||
const partsManagementVehicleDamageEstimateAddRq = require("../integrations/partsManagement/endpoints/vehicleDamageEstimateAddRq");
|
||||
const partsManagementVehicleDamageEstimateChqRq = require("../integrations/partsManagement/endpoints/vehicleDamageEstimateChgRq");
|
||||
const patchJobStatus = require("../job/patchJobStatus");
|
||||
|
||||
/**
|
||||
* Route to handle Vehicle Damage Estimate Add Request
|
||||
@@ -55,6 +59,20 @@ if (typeof PARTS_MANAGEMENT_INTEGRATION_SECRET === "string" && PARTS_MANAGEMENT_
|
||||
* Route to handle Parts Management Provisioning
|
||||
*/
|
||||
router.post("/parts-management/provision", partsManagementIntegrationMiddleware, partsManagementProvisioning);
|
||||
|
||||
/**
|
||||
* PATCH route to update Parts Management Provisioning info
|
||||
*/
|
||||
router.patch(
|
||||
"/parts-management/provision/:id",
|
||||
partsManagementIntegrationMiddleware,
|
||||
patchPartsManagementProvisioning
|
||||
);
|
||||
|
||||
/**
|
||||
* PATCH route to update job status (parts management only)
|
||||
*/
|
||||
router.patch("/parts-management/job/:id/status", partsManagementIntegrationMiddleware, patchJobStatus);
|
||||
} else {
|
||||
logger.logger.warn("PARTS_MANAGEMENT_INTEGRATION_SECRET is not set — skipping /parts-management/provision route");
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ router.post("/bodyshop-cache", eventAuthorizationMiddleware, updateBodyshopCache
|
||||
|
||||
// Estimate Scrubber Vehicle Type
|
||||
router.post("/es/vehicletype", data.vehicletype);
|
||||
|
||||
router.post("/analytics/documents", data.documentAnalytics);
|
||||
// Health Check for docker-compose-cluster load balancer, only available in development
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
router.get("/health", (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user