feature/IO-3456-Broken-Image - Fix issue
This commit is contained in:
@@ -134,13 +134,16 @@ const insertUserAssociation = async (uid, email, shopId) => {
|
||||
|
||||
/**
|
||||
* 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 res
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
const patchPartsManagementProvisioning = async (req, res) => {
|
||||
const { id } = req.params;
|
||||
|
||||
// Fields that can be directly patched 1:1
|
||||
const allowedFields = [
|
||||
"shopname",
|
||||
"address1",
|
||||
@@ -151,31 +154,58 @@ const patchPartsManagementProvisioning = async (req, res) => {
|
||||
"country",
|
||||
"email",
|
||||
"timezone",
|
||||
"phone",
|
||||
"logo_img_path"
|
||||
"phone"
|
||||
// NOTE: logo_img_path is handled separately via logoUrl
|
||||
];
|
||||
|
||||
const updateFields = {};
|
||||
|
||||
// Copy over simple scalar fields if present
|
||||
for (const field of allowedFields) {
|
||||
if (req.body[field] !== undefined) {
|
||||
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) {
|
||||
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 } }`,
|
||||
`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 });
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user