datasquirel/package-shared/functions/api/users/api-get-user.js

35 lines
890 B
JavaScript
Raw Normal View History

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