Merge remote-tracking branch 'origin/release/2025-12-05' into feature/IO-3357-Reynolds-and-Reynolds-DMS-API-Integration
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user