Files
pedwfrontend/pages/api/endpoint/updateaccount_api.js
T

48 lines
1.3 KiB
JavaScript

/**
* @swagger
* /api/endpoint/updateaccount_api:
* patch:
* tags: [Account]
* description: Update account
* summary: Phase 2
* responses:
* 200:
* description: Success
*/
import { consoleLogger } from "../../../actions/core/logger";
import { respondError, respondSuccess } from "../middleware/apiResponse";
import { updateCrmContact } from "../../../lib/server/updateCrmContact";
export default async function ApiProxy(req, res) {
const contactId = req.query.contactId;
if (typeof contactId !== "string" || contactId.trim().length === 0) {
return respondError(res, {
status: 400,
code: "CONTACT_ID_REQUIRED",
message: "contactId is required"
});
}
if (!req.body || Object.keys(req.body).length === 0) {
return respondError(res, {
status: 400,
code: "ACCOUNT_UPDATE_PAYLOAD_REQUIRED",
message: "Account update payload is required"
});
}
try {
const data = await updateCrmContact(contactId, req.body);
return respondSuccess(res, data);
} catch (error) {
consoleLogger(error);
return respondError(res, {
status: 400,
code: "ACCOUNT_UPDATE_FAILED",
message: "Failed to update account"
});
}
}