dsql-admin/dsql-app/package-shared/functions/api/users/api-delete-user.js

53 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-12-08 08:57:48 +00:00
// @ts-check
const deleteDbEntry = require("../../backend/db/deleteDbEntry");
const varDatabaseDbHandler = require("../../backend/varDatabaseDbHandler");
/**
* # Update API User Function
*
* @param {object} params
* @param {string} params.dbFullName
* @param {string | number} params.deletedUserId
* @param {boolean} [params.useLocal]
*
* @returns {Promise<{ success: boolean, result?: any, msg?: string }>}
*/
module.exports = async function apiDeleteUser({
dbFullName,
deletedUserId,
useLocal,
}) {
const existingUserQuery = `SELECT * FROM users WHERE id = ?`;
const existingUserValues = [deletedUserId];
const existingUser = await varDatabaseDbHandler({
queryString: existingUserQuery,
queryValuesArray: existingUserValues,
database: dbFullName,
useLocal,
});
if (!existingUser?.[0]) {
return {
success: false,
msg: "User not found",
};
}
const deleteUser = await deleteDbEntry({
dbContext: "Dsql User",
paradigm: "Full Access",
dbFullName,
tableName: "users",
identifierColumnName: "id",
identifierValue: deletedUserId,
useLocal,
});
return {
success: true,
result: deleteUser,
};
};