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

34 lines
797 B
JavaScript
Raw Normal View History

2024-12-06 13:24:26 +00:00
// @ts-check
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=?`;
2024-12-09 12:27:08 +00:00
const API_USER_ID = userId || process.env.DSQL_API_USER_ID;
2024-12-06 13:24:26 +00:00
2024-12-08 08:57:48 +00:00
let foundUser = await varDatabaseDbHandler({
queryString: query,
2024-12-09 12:27:08 +00:00
queryValuesArray: [API_USER_ID],
2024-12-08 08:57:48 +00:00
database: dbFullName.replace(/[^a-z0-9_]/g, ""),
useLocal,
});
2024-12-06 13:24:26 +00:00
if (!foundUser || !foundUser[0]) {
return {
success: false,
payload: null,
};
}
return {
success: true,
payload: foundUser[0],
};
};