57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import apiUpdateUser from "../../functions/api/users/api-update-user";
|
|
import {
|
|
ApiUpdateUserParams,
|
|
UpdateUserFunctionReturn,
|
|
UpdateUserParams,
|
|
} from "../../types";
|
|
import queryDSQLAPI from "../../functions/api/query-dsql-api";
|
|
import grabUserDSQLAPIPath from "../../utils/backend/users/grab-api-path";
|
|
import { DSQL_DATASQUIREL_USERS } from "../../types/dsql";
|
|
|
|
/**
|
|
* # Update User
|
|
*/
|
|
export default async function updateUser<
|
|
T extends DSQL_DATASQUIREL_USERS = DSQL_DATASQUIREL_USERS & {
|
|
[k: string]: any;
|
|
}
|
|
>({
|
|
payload,
|
|
database,
|
|
updatedUserId,
|
|
useLocal,
|
|
apiKey,
|
|
apiVersion,
|
|
dbUserId,
|
|
}: UpdateUserParams<T>): Promise<UpdateUserFunctionReturn> {
|
|
const updateUserParams: ApiUpdateUserParams = {
|
|
payload: payload,
|
|
database,
|
|
updatedUserId,
|
|
dbUserId,
|
|
};
|
|
|
|
if (useLocal) {
|
|
return await apiUpdateUser(updateUserParams);
|
|
}
|
|
|
|
/**
|
|
* Make https request
|
|
*
|
|
* @description make a request to datasquirel.com
|
|
*/
|
|
const httpResponse = await queryDSQLAPI({
|
|
path: grabUserDSQLAPIPath({
|
|
paradigm: "auth",
|
|
action: "update",
|
|
database,
|
|
apiVersion,
|
|
}),
|
|
apiKey,
|
|
body: updateUserParams,
|
|
method: "POST",
|
|
});
|
|
|
|
return httpResponse as UpdateUserFunctionReturn;
|
|
}
|