Update Operation
The updateOp function is used to update an existing record in a PostgreSQL table.
Usage
const updatedData = await updateOp(tableName, payload);Parameters
tableName (Required)
The name of the PostgreSQL table where the record will be updated.
payload (Required)
A modified userData object that must include:
__d3__id→ ID of the record to update__d3__newData→ Object containing updated field values
If updating a related table, the payload must also include:
__d3__parentId__d3__relationId
Payload Structure
{
__d3__id: 4,
__d3__newData: {
columnName1: "updatedValue1",
columnName2: "updatedValue2"
}
}Return Value
Returns the result of Sequelize dataModel.update().
Sample Output
{
affectedCount: [1]
}affectedCount[0] indicates how many records were successfully updated.
Example Implementation
async function customizeERP(userData, apiOperations) {
const tableName = "table_name";
const { updateOp } = apiOperations;
return new Promise(async (resolve, reject) => {
const payload = {
__d3__id: userData?.__d3__id,
__d3__newData: { ...userData?.__d3__newData }
};
const updatedData = await updateOp(tableName, payload);
if (updatedData?.affectedCount?.[0]) {
resolve({ result: updatedData });
} else {
resolve({
result: {},
popupMsg: {
type: "error",
message: "Could Not update data! Please try again later"
}
});
}
});
}Example Input
{
"__d3__newData": {
"id": 1,
"name": "Sample",
"bio": "Sample",
"create at": "2025-06-11T09:02:01.794Z",
"__d3__createdBy": 575,
"__d3__lastUpdatedBy": null,
"__d3__createdAt": "2025-05-21T16:28:50.975Z",
"__d3__updatedAt": "2025-06-01T10:00:05.594Z",
"__d3__deletedAt": null
},
"__d3__id": 4
}Example Output
{
"response": {
"__d3__result": {
"result": {
"affectedCount": [1]
}
},
"__d3__error": false,
"printConsole": []
}
}