Merge branch 'feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration' into rrScratch3

This commit is contained in:
Dave
2025-12-05 12:13:27 -05:00
3 changed files with 41 additions and 14 deletions

View File

@@ -30,7 +30,7 @@ Send a JSON object with one or more of the following fields to update:
- `email` (string, shop's email, not user email) - `email` (string, shop's email, not user email)
- `timezone` (string) - `timezone` (string)
- `phone` (string) - `phone` (string)
- `logo_img_path` (object, e.g. `{ src, width, height, headerMargin }`) - `logo_img_path` (string)
Any fields not included in the request body will remain unchanged. Any fields not included in the request body will remain unchanged.
@@ -50,12 +50,7 @@ Content-Type: application/json
"email": "shop@example.com", "email": "shop@example.com",
"timezone": "America/Chicago", "timezone": "America/Chicago",
"phone": "555-123-4567", "phone": "555-123-4567",
"logo_img_path": { "logo_img_path": "https://example.com/logo.png"
"src": "https://example.com/logo.png",
"width": "200",
"height": "100",
"headerMargin": 10
}
} }
``` ```

View File

@@ -55,7 +55,9 @@ exports.default = async (req, res) => {
"patrick.fic@convenient-brands.com", "patrick.fic@convenient-brands.com",
"bradley.rhoades@convenient-brands.com", "bradley.rhoades@convenient-brands.com",
"jrome@rometech.com", "jrome@rometech.com",
"ivana@imexsystems.ca" "ivana@imexsystems.ca",
"support@imexsystems.ca",
"sarah@rometech.com"
], ],
subject: `RO Usage Report - ${moment().format("MM/DD/YYYY")}`, subject: `RO Usage Report - ${moment().format("MM/DD/YYYY")}`,
text: ` text: `

View File

@@ -134,13 +134,16 @@ const insertUserAssociation = async (uid, email, shopId) => {
/** /**
* PATCH handler for updating bodyshop fields. * PATCH handler for updating bodyshop fields.
* Allows patching: shopname, address1, address2, city, state, zip_post, country, email, timezone, phone, logo_img_path * Allows patching: shopname, address1, address2, city, state, zip_post, country, email, timezone, phone
* Also allows updating logo_img_path via a simple logoUrl string, which is expanded to the full object.
* @param req * @param req
* @param res * @param res
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
const patchPartsManagementProvisioning = async (req, res) => { const patchPartsManagementProvisioning = async (req, res) => {
const { id } = req.params; const { id } = req.params;
// Fields that can be directly patched 1:1
const allowedFields = [ const allowedFields = [
"shopname", "shopname",
"address1", "address1",
@@ -151,31 +154,58 @@ const patchPartsManagementProvisioning = async (req, res) => {
"country", "country",
"email", "email",
"timezone", "timezone",
"phone", "phone"
"logo_img_path" // NOTE: logo_img_path is handled separately via logoUrl
]; ];
const updateFields = {}; const updateFields = {};
// Copy over simple scalar fields if present
for (const field of allowedFields) { for (const field of allowedFields) {
if (req.body[field] !== undefined) { if (req.body[field] !== undefined) {
updateFields[field] = req.body[field]; updateFields[field] = req.body[field];
} }
} }
// Handle logo update via a simple href string, same behavior as provision route
if (typeof req.body.logo_img_path === "string") {
const trimmed = req.body.logo_img_path.trim();
if (trimmed) {
updateFields.logo_img_path = {
src: trimmed,
width: "",
height: "",
headerMargin: DefaultNewShop.logo_img_path.headerMargin
};
}
}
if (Object.keys(updateFields).length === 0) { if (Object.keys(updateFields).length === 0) {
return res.status(400).json({ error: "No valid fields provided for update." }); return res.status(400).json({ error: "No valid fields provided for update." });
} }
// Check that the bodyshop has an external_shop_id before allowing patch // Check that the bodyshop has an external_shop_id before allowing patch
try { try {
// Fetch the bodyshop by id
const shopResp = await client.request( const shopResp = await client.request(
`query GetBodyshop($id: uuid!) { bodyshops_by_pk(id: $id) { id external_shop_id } }`, `query GetBodyshop($id: uuid!) {
bodyshops_by_pk(id: $id) {
id
external_shop_id
}
}`,
{ id } { id }
); );
if (!shopResp.bodyshops_by_pk?.external_shop_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." }); return res.status(400).json({ error: "Cannot patch: bodyshop does not have an external_shop_id." });
} }
} catch (err) { } catch (err) {
return res.status(500).json({ error: "Failed to validate bodyshop external_shop_id.", detail: err }); return res.status(500).json({
error: "Failed to validate bodyshop external_shop_id.",
detail: err
});
} }
try { try {
const resp = await client.request(UPDATE_BODYSHOP_BY_ID, { id, fields: updateFields }); const resp = await client.request(UPDATE_BODYSHOP_BY_ID, { id, fields: updateFields });
if (!resp.update_bodyshops_by_pk) { if (!resp.update_bodyshops_by_pk) {