Compare commits

...

11 Commits

Author SHA1 Message Date
Dave
ca1a456312 feature/IO-3402-Import-Add-Notifiers - Fix Normalize 2025-12-19 14:10:15 -05:00
Dave
c010665ea9 feature/IO-3402-Import-Add-Notifiers - Fix 2025-12-18 18:26:02 -05:00
Dave
d6fba12cd9 feature/IO-3402-Import-Add-Notifiers - Fix Auto Notifiers 2025-12-18 13:27:24 -05:00
Allan Carr
6ea1c291e6 Merged in release/2025-12-19 (pull request #2703)
Release/2025 12 19
2025-12-12 02:36:57 +00:00
Allan Carr
05d5c96491 Merged in feature/IO-3462-Project-Mexico-Mod (pull request #2701)
IO-3462 Project Mexico Mod

Approved-by: Dave Richer
2025-12-10 20:18:14 +00:00
Allan Carr
35a566cbe5 IO-3462 Project Mexico Mod
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-12-10 09:52:04 -08:00
Dave Richer
f12e40e4c6 Merged in feature/IO-3461-Fix-EULA (pull request #2698)
feature/IO-3461-Fix-Eula
2025-12-09 22:15:22 +00:00
Dave
bb4e671c83 feature/IO-3461-Fix-Eula 2025-12-09 17:13:59 -05:00
Dave Richer
d1637d2432 Merged in release/2025-12-05 (pull request #2696)
Release/2025 12 05 into master-AIO - IO-3450 IO-3452 IO-3262 - IO-3456 IO-3262
2025-12-06 01:48:37 +00:00
Allan Carr
1c79628613 Merged in feature/IO-3262-Tech-Console-Job-Clock-Out (pull request #2692)
IO-3262 Correction for v_year in Project Mexico

Approved-by: Dave Richer
2025-12-05 19:00:38 +00:00
Allan Carr
521a7084b7 IO-3262 Correction for v_year in Project Mexico
Signed-off-by: Allan Carr <allan@imexsystems.ca>
2025-12-05 09:48:32 -08:00
9 changed files with 102 additions and 84 deletions

View File

@@ -138,7 +138,7 @@ export function App({
); );
} }
if (currentEula && !currentUser.eulaIsAccepted) { if (!isPartsEntry && currentEula && !currentUser.eulaIsAccepted) {
return <Eula />; return <Eula />;
} }

View File

@@ -55,7 +55,8 @@ const Eula = ({ currentEula, currentUser, acceptEula }) => {
const useremail = currentUser.email; const useremail = currentUser.email;
try { try {
const { ...otherFormValues } = formValues; // eslint-disable-next-line no-unused-vars
const { accepted_terms, ...otherFormValues } = formValues;
// Trim the values of the fields before submitting // Trim the values of the fields before submitting
const trimmedFormValues = Object.entries(otherFormValues).reduce((acc, [key, value]) => { const trimmedFormValues = Object.entries(otherFormValues).reduce((acc, [key, value]) => {

View File

@@ -16,6 +16,7 @@ export default function ShopInfoNotificationsAutoadd({ bodyshop }) {
<Text type="secondary">{t("bodyshop.labels.notifications.followers")}</Text> <Text type="secondary">{t("bodyshop.labels.notifications.followers")}</Text>
{employeeOptions.length > 0 ? ( {employeeOptions.length > 0 ? (
<Form.Item <Form.Item
normalize={(value) => (value || []).filter((id) => typeof id === "string" && id.trim() !== "")}
name="notification_followers" name="notification_followers"
rules={[ rules={[
{ {
@@ -42,11 +43,6 @@ export default function ShopInfoNotificationsAutoadd({ bodyshop }) {
options={employeeOptions} options={employeeOptions}
placeholder={t("bodyshop.fields.notifications.placeholder")} placeholder={t("bodyshop.fields.notifications.placeholder")}
showEmail={true} showEmail={true}
onChange={(value) => {
// Filter out null or invalid values before passing to Form
const cleanedValue = value?.filter((id) => id != null && typeof id === "string" && id.trim() !== "");
return cleanedValue;
}}
/> />
</Form.Item> </Form.Item>
) : ( ) : (

View File

@@ -1156,7 +1156,11 @@
enable_manual: false enable_manual: false
update: update:
columns: columns:
- imexshopid
- timezone
- shopname - shopname
- notification_followers
- state
- md_order_statuses - md_order_statuses
retry_conf: retry_conf:
interval_sec: 10 interval_sec: 10
@@ -3698,6 +3702,7 @@
- deliverchecklist - deliverchecklist
- depreciation_taxes - depreciation_taxes
- dms_allocation - dms_allocation
- dms_id
- driveable - driveable
- employee_body - employee_body
- employee_csr - employee_csr
@@ -3975,6 +3980,7 @@
- deliverchecklist - deliverchecklist
- depreciation_taxes - depreciation_taxes
- dms_allocation - dms_allocation
- dms_id
- driveable - driveable
- employee_body - employee_body
- employee_csr - employee_csr
@@ -4264,6 +4270,7 @@
- deliverchecklist - deliverchecklist
- depreciation_taxes - depreciation_taxes
- dms_allocation - dms_allocation
- dms_id
- driveable - driveable
- employee_body - employee_body
- employee_csr - employee_csr

View File

@@ -117,44 +117,46 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
imexshopid: shopid, imexshopid: shopid,
json: JSON.stringify(carfaxObject, null, 2), json: JSON.stringify(carfaxObject, null, 2),
filename: `${shopid}_${moment().format("DDMMYYYY_HHMMss")}.json`, filename: `${shopid}_${moment().format("DDMMYYYY_HHMMss")}.json`,
count: carfaxObject.job.length count: carfaxObject?.job?.length || 0
}; };
if (skipUpload) { if (skipUpload) {
fs.writeFileSync(`./logs/${jsonObj.filename}`, jsonObj.json); fs.writeFileSync(`./logs/${jsonObj.filename}`, jsonObj.json);
uploadToS3(jsonObj, S3_BUCKET_NAME); uploadToS3(jsonObj, S3_BUCKET_NAME);
} else { } else {
await uploadViaSFTP(jsonObj); if (jsonObj.count > 0) {
await uploadViaSFTP(jsonObj);
await sendMexicoBillingEmail({ await sendMexicoBillingEmail({
subject: `${shopid.replace(/_/g, "").toUpperCase()}_MexicoRPS_${moment().format("MMDDYYYY")} ROs ${jsonObj.count} Error ${errorCode(jsonObj)}`, subject: `${shopid.replace(/_/g, "").toUpperCase()}_MexicoRPS_${moment().format("MMDDYYYY")} ROs ${jsonObj.count} Error ${errorCode(jsonObj)}`,
text: `Errors:\n${JSON.stringify( text: `Errors:\n${JSON.stringify(
erroredJobs.map((ej) => ({ erroredJobs.map((ej) => ({
jobid: ej.job?.id, jobid: ej.job?.id,
error: ej.error error: ej.error
})), })),
null, null,
2 2
)}\n\nUploaded:\n${JSON.stringify( )}\n\nUploaded:\n${JSON.stringify(
{ {
bodyshopid: bodyshop.id, bodyshopid: bodyshop.id,
imexshopid: shopid, imexshopid: shopid,
count: jsonObj.count, count: jsonObj.count,
filename: jsonObj.filename, filename: jsonObj.filename,
result: jsonObj.result result: jsonObj.result
}, },
null, null,
2 2
)}` )}`
}); });
}
} }
allJSONResults.push({ jsonObj.count > 0 && allJSONResults.push({
bodyshopid: bodyshop.id, bodyshopid: bodyshop.id,
imexshopid: shopid, imexshopid: shopid,
count: jsonObj.count, count: jsonObj.count,
filename: jsonObj.filename, filename: jsonObj.filename,
result: jsonObj.result result: jsonObj.result || "No Upload Result Available"
}); });
logger.log("CARFAX-RPS-end-shop-extract", "DEBUG", "api", bodyshop.id, { logger.log("CARFAX-RPS-end-shop-extract", "DEBUG", "api", bodyshop.id, {
@@ -234,11 +236,10 @@ const CreateRepairOrderTag = (job, errorCallback) => {
const ret = { const ret = {
ro_number: crypto.createHash("md5").update(job.id, "utf8").digest("hex"), ro_number: crypto.createHash("md5").update(job.id, "utf8").digest("hex"),
v_vin: job.v_vin || "", v_vin: job.v_vin || "",
v_year: job.v_model_yr v_year: (() => {
? parseInt(job.v_model_yr.match(/\d/g)) const y = parseInt(job.v_model_yr);
? parseInt(job.v_model_yr.match(/\d/g).join(""), 10) return isNaN(y) ? null : y < 100 ? y + (y >= (new Date().getFullYear() + 1) % 100 ? 1900 : 2000) : y;
: "" })(),
: "",
v_make: job.v_makedesc || "", v_make: job.v_makedesc || "",
v_model: job.v_model || "", v_model: job.v_model || "",

View File

@@ -160,40 +160,42 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
imexshopid: shopid, imexshopid: shopid,
json: JSON.stringify(carfaxObject, null, 2), json: JSON.stringify(carfaxObject, null, 2),
filename: `${shopid}_${moment().format("DDMMYYYY_HHMMss")}.json`, filename: `${shopid}_${moment().format("DDMMYYYY_HHMMss")}.json`,
count: carfaxObject.job.length count: carfaxObject?.job?.length || 0
}; };
if (skipUpload) { if (skipUpload) {
fs.writeFileSync(`./logs/${jsonObj.filename}`, jsonObj.json); fs.writeFileSync(`./logs/${jsonObj.filename}`, jsonObj.json);
uploadToS3(jsonObj); uploadToS3(jsonObj);
} else { } else {
await uploadViaSFTP(jsonObj); if (jsonObj.count > 0) {
await uploadViaSFTP(jsonObj);
await sendMexicoBillingEmail({ await sendMexicoBillingEmail({
subject: `${shopid.replace(/_/g, "").toUpperCase()}_Mexico${InstanceManager({ subject: `${shopid.replace(/_/g, "").toUpperCase()}_Mexico${InstanceManager({
imex: "IO", imex: "IO",
rome: "RO" rome: "RO"
})}_${moment().format("MMDDYYYY")} ROs ${jsonObj.count} Error ${errorCode(jsonObj)}`, })}_${moment().format("MMDDYYYY")} ROs ${jsonObj.count} Error ${errorCode(jsonObj)}`,
text: `Errors:\n${JSON.stringify( text: `Errors:\n${JSON.stringify(
erroredJobs.map((ej) => ({ erroredJobs.map((ej) => ({
ro_number: ej.job?.ro_number, ro_number: ej.job?.ro_number,
jobid: ej.job?.id, jobid: ej.job?.id,
error: ej.error error: ej.error
})), })),
null, null,
2 2
)}\n\nUploaded:\n${JSON.stringify( )}\n\nUploaded:\n${JSON.stringify(
{ {
bodyshopid: bodyshop.id, bodyshopid: bodyshop.id,
imexshopid: shopid, imexshopid: shopid,
count: jsonObj.count, count: jsonObj.count,
filename: jsonObj.filename, filename: jsonObj.filename,
result: jsonObj.result result: jsonObj.result
}, },
null, null,
2 2
)}` )}`
}); });
}
} }
allJSONResults.push({ allJSONResults.push({
@@ -201,7 +203,7 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
imexshopid: shopid, imexshopid: shopid,
count: jsonObj.count, count: jsonObj.count,
filename: jsonObj.filename, filename: jsonObj.filename,
result: jsonObj.result result: jsonObj.result || "No Upload Result Available"
}); });
logger.log("CARFAX-end-shop-extract", "DEBUG", "api", bodyshop.id, { logger.log("CARFAX-end-shop-extract", "DEBUG", "api", bodyshop.id, {
@@ -286,11 +288,10 @@ const CreateRepairOrderTag = (job, errorCallback) => {
const ret = { const ret = {
ro_number: crypto.createHash("md5").update(job.ro_number, "utf8").digest("hex"), ro_number: crypto.createHash("md5").update(job.ro_number, "utf8").digest("hex"),
v_vin: job.v_vin || "", v_vin: job.v_vin || "",
v_year: job.v_model_yr v_year: (() => {
? parseInt(job.v_model_yr.match(/\d/g)) const y = parseInt(job.v_model_yr);
? parseInt(job.v_model_yr.match(/\d/g).join(""), 10) return isNaN(y) ? null : y < 100 ? y + (y >= (new Date().getFullYear() + 1) % 100 ? 1900 : 2000) : y;
: "" })(),
: "",
v_make: job.v_make_desc || "", v_make: job.v_make_desc || "",
v_model: job.v_model_desc || "", v_model: job.v_model_desc || "",

View File

@@ -2926,6 +2926,15 @@ exports.GET_BODYSHOP_BY_ID = `
} }
`; `;
exports.GET_BODYSHOP_WATCHERS_BY_ID = `
query GET_BODYSHOP_BY_ID($id: uuid!) {
bodyshops_by_pk(id: $id) {
id
notification_followers
}
}
`;
exports.GET_DOCUMENTS_BY_JOB = ` exports.GET_DOCUMENTS_BY_JOB = `
query GET_DOCUMENTS_BY_JOB($jobId: uuid!) { query GET_DOCUMENTS_BY_JOB($jobId: uuid!) {
jobs_by_pk(id: $jobId) { jobs_by_pk(id: $jobId) {

View File

@@ -241,6 +241,8 @@ const partsManagementProvisioning = async (req, res) => {
"phone", "phone",
"userEmail" "userEmail"
]); ]);
// TODO add in check for early access
await ensureExternalIdUnique(body.external_shop_id); await ensureExternalIdUnique(body.external_shop_id);
logger.log("admin-create-shop-user", "debug", body.userEmail, null, { logger.log("admin-create-shop-user", "debug", body.userEmail, null, {

View File

@@ -4,11 +4,14 @@
* This module handles automatically adding watchers to new jobs based on the notifications_autoadd * This module handles automatically adding watchers to new jobs based on the notifications_autoadd
* boolean field in the associations table and the notification_followers JSON field in the bodyshops table. * boolean field in the associations table and the notification_followers JSON field in the bodyshops table.
* It ensures users are not added twice and logs the process. * It ensures users are not added twice and logs the process.
*
* NOTE: Bodyshop notification_followers is fetched directly from the DB (Hasura) to avoid stale Redis cache.
*/ */
const { client: gqlClient } = require("../graphql-client/graphql-client"); const { client: gqlClient } = require("../graphql-client/graphql-client");
const { isEmpty } = require("lodash"); const { isEmpty } = require("lodash");
const { const {
GET_BODYSHOP_WATCHERS_BY_ID,
GET_JOB_WATCHERS_MINIMAL, GET_JOB_WATCHERS_MINIMAL,
GET_NOTIFICATION_WATCHERS, GET_NOTIFICATION_WATCHERS,
INSERT_JOB_WATCHERS INSERT_JOB_WATCHERS
@@ -26,10 +29,7 @@ const FILTER_SELF_FROM_WATCHERS = process.env?.FILTER_SELF_FROM_WATCHERS !== "fa
*/ */
const autoAddWatchers = async (req) => { const autoAddWatchers = async (req) => {
const { event, trigger } = req.body; const { event, trigger } = req.body;
const { const { logger } = req;
logger,
sessionUtils: { getBodyshopFromRedis }
} = req;
// Validate that this is an INSERT event, bail // Validate that this is an INSERT event, bail
if (trigger?.name !== "notifications_jobs_autoadd" || event.op !== "INSERT" || event.data.old) { if (trigger?.name !== "notifications_jobs_autoadd" || event.op !== "INSERT" || event.data.old) {
@@ -48,20 +48,20 @@ const autoAddWatchers = async (req) => {
const hasuraUserId = event?.session_variables?.["x-hasura-user-id"]; const hasuraUserId = event?.session_variables?.["x-hasura-user-id"];
try { try {
// Fetch bodyshop data from Redis // Fetch bodyshop data directly from DB (avoid Redis staleness)
const bodyshopData = await getBodyshopFromRedis(shopId); const bodyshopResponse = await gqlClient.request(GET_BODYSHOP_WATCHERS_BY_ID, { id: shopId });
let notificationFollowers = bodyshopData?.notification_followers; const bodyshopData = bodyshopResponse?.bodyshops_by_pk;
// Bail if notification_followers is missing or not an array const notificationFollowersRaw = bodyshopData?.notification_followers;
if (!notificationFollowers || !Array.isArray(notificationFollowers)) { const notificationFollowers = Array.isArray(notificationFollowersRaw)
return; ? [...new Set(notificationFollowersRaw.filter((id) => id))] // de-dupe + remove falsy
} : [];
// Execute queries in parallel // Execute queries in parallel
const [notificationData, existingWatchersData] = await Promise.all([ const [notificationData, existingWatchersData] = await Promise.all([
gqlClient.request(GET_NOTIFICATION_WATCHERS, { gqlClient.request(GET_NOTIFICATION_WATCHERS, {
shopId, shopId,
employeeIds: notificationFollowers.filter((id) => id) employeeIds: notificationFollowers
}), }),
gqlClient.request(GET_JOB_WATCHERS_MINIMAL, { jobid: jobId }) gqlClient.request(GET_JOB_WATCHERS_MINIMAL, { jobid: jobId })
]); ]);
@@ -73,7 +73,7 @@ const autoAddWatchers = async (req) => {
associationId: assoc.id associationId: assoc.id
})) || []; })) || [];
// Get users from notification_followers // Get users from notification_followers (employee IDs -> employee emails)
const followerEmails = const followerEmails =
notificationData?.employees notificationData?.employees
?.filter((e) => e.user_email) ?.filter((e) => e.user_email)
@@ -84,7 +84,7 @@ const autoAddWatchers = async (req) => {
// Combine and deduplicate emails (use email as the unique key) // Combine and deduplicate emails (use email as the unique key)
const usersToAdd = [...autoAddUsers, ...followerEmails].reduce((acc, user) => { const usersToAdd = [...autoAddUsers, ...followerEmails].reduce((acc, user) => {
if (!acc.some((u) => u.email === user.email)) { if (user?.email && !acc.some((u) => u.email === user.email)) {
acc.push(user); acc.push(user);
} }
return acc; return acc;
@@ -123,6 +123,7 @@ const autoAddWatchers = async (req) => {
message: error?.message, message: error?.message,
stack: error?.stack, stack: error?.stack,
jobId, jobId,
shopId,
roNumber roNumber
}); });
throw error; // Re-throw to ensure the error is logged in the handler throw error; // Re-throw to ensure the error is logged in the handler