dsql-admin/dsql-app/package-shared/functions/api/users/api-update-user.js
Benjamin Toby 8b7ea057d0 Updates
2024-12-06 14:24:26 +01:00

50 lines
1.1 KiB
JavaScript

// @ts-check
const updateDbEntry = require("../../backend/db/updateDbEntry");
/**
* # Update API User Function
*
* @param {object} params
* @param {{ id: string | number } & Object<string, (string | number | null | undefined)>} params.payload
* @param {string} params.dbFullName
* @param {boolean} [params.useLocal]
*
* @returns {Promise<{ success: boolean, payload: any }>}
*/
module.exports = async function apiUpdateUser({
payload,
dbFullName,
useLocal,
}) {
const data = (() => {
const reqBodyKeys = Object.keys(payload);
/** @type {any} */
const finalData = {};
reqBodyKeys.forEach((key) => {
if (key?.match(/^date_|^id$/)) return;
finalData[key] = payload[key];
});
return finalData;
})();
const updateUser = await updateDbEntry({
dbContext: "Dsql User",
paradigm: "Full Access",
dbFullName,
tableName: "users",
identifierColumnName: "id",
identifierValue: payload.id,
data: data,
useLocal,
});
return {
success: true,
payload: updateUser,
};
};