2025-01-10 19:10:28 +00:00
|
|
|
import deleteDbEntry from "../../backend/db/deleteDbEntry";
|
|
|
|
import varDatabaseDbHandler from "../../backend/varDatabaseDbHandler";
|
2024-12-08 08:58:57 +00:00
|
|
|
|
2025-01-10 19:10:28 +00:00
|
|
|
type Param = {
|
|
|
|
dbFullName: string;
|
|
|
|
deletedUserId: string | number;
|
|
|
|
useLocal?: boolean;
|
|
|
|
};
|
|
|
|
type Return = { success: boolean; result?: any; msg?: string };
|
2024-12-08 08:58:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* # Update API User Function
|
|
|
|
*/
|
2025-01-10 19:10:28 +00:00
|
|
|
export default async function apiDeleteUser({
|
2024-12-08 08:58:57 +00:00
|
|
|
dbFullName,
|
|
|
|
deletedUserId,
|
|
|
|
useLocal,
|
2025-01-10 19:10:28 +00:00
|
|
|
}: Param): Promise<Return> {
|
2024-12-08 08:58:57 +00:00
|
|
|
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,
|
|
|
|
};
|
2025-01-10 19:10:28 +00:00
|
|
|
}
|