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

35 lines
890 B
JavaScript

// @ts-check
const LOCAL_DB_HANDLER = require("../../../utils/backend/global-db/LOCAL_DB_HANDLER");
const varDatabaseDbHandler = require("../../backend/varDatabaseDbHandler");
/** @type {import("../../../types").APIGetUserFunction} */
module.exports = async function apiGetUser({
fields,
dbFullName,
userId,
useLocal,
}) {
const query = `SELECT ${fields.join(",")} FROM users WHERE id=?`;
let foundUser = useLocal
? await LOCAL_DB_HANDLER(query, [userId])
: await varDatabaseDbHandler({
queryString: query,
queryValuesArray: [userId],
database: dbFullName.replace(/[^a-z0-9_]/g, ""),
});
if (!foundUser || !foundUser[0]) {
return {
success: false,
payload: null,
};
}
return {
success: true,
payload: foundUser[0],
};
};