42 lines
958 B
TypeScript
42 lines
958 B
TypeScript
|
import {
|
||
|
APIGetUserFunctionParams,
|
||
|
GetUserFunctionReturn,
|
||
|
} from "../../../types";
|
||
|
import varDatabaseDbHandler from "../../backend/varDatabaseDbHandler";
|
||
|
|
||
|
/**
|
||
|
* # API Get User
|
||
|
*/
|
||
|
export default async function apiGetUser({
|
||
|
fields,
|
||
|
dbFullName,
|
||
|
userId,
|
||
|
useLocal,
|
||
|
}: APIGetUserFunctionParams): Promise<GetUserFunctionReturn> {
|
||
|
const finalDbName = dbFullName.replace(/[^a-z0-9_]/g, "");
|
||
|
|
||
|
const query = `SELECT ${fields.join(
|
||
|
","
|
||
|
)} FROM ${finalDbName}.users WHERE id=?`;
|
||
|
const API_USER_ID = userId || process.env.DSQL_API_USER_ID;
|
||
|
|
||
|
let foundUser = await varDatabaseDbHandler({
|
||
|
queryString: query,
|
||
|
queryValuesArray: [API_USER_ID],
|
||
|
database: finalDbName,
|
||
|
useLocal,
|
||
|
});
|
||
|
|
||
|
if (!foundUser || !foundUser[0]) {
|
||
|
return {
|
||
|
success: false,
|
||
|
payload: null,
|
||
|
};
|
||
|
}
|
||
|
|
||
|
return {
|
||
|
success: true,
|
||
|
payload: foundUser[0],
|
||
|
};
|
||
|
}
|