datasquirel/package-shared/functions/api/users/api-get-user.js
Benjamin Toby 8ca2779741 Updates
2024-12-06 11:31:24 +01:00

27 lines
683 B
JavaScript

// @ts-check
const varDatabaseDbHandler = require("../../backend/varDatabaseDbHandler");
/** @type {import("../../../types").APIGetUserFunction} */
module.exports = async function apiGetUser({ fields, dbFullName, userId }) {
const query = `SELECT ${fields.join(",")} FROM users WHERE id=?`;
let foundUser = 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],
};
};