feature/IO-3390-Parts-Management-2 - Add Job status patch route, Bodyshop Patch route, remove PAO from simplified parts filter.
This commit is contained in:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user