First Commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import type { BUN_SQLITE_WGUI_USERS } from "@/db/types/db";
|
||||
import grabUsers from "@/src/functions/backend/db/users/grab-users";
|
||||
import type { ApiReqParams, TableType } from "@/src/types";
|
||||
import BunSQLite from "@moduletrace/bun-sqlite";
|
||||
import type {
|
||||
APIResponseObject,
|
||||
BunextAPIRouteHandler,
|
||||
} from "@moduletrace/bunext/types";
|
||||
import { hash } from "bun";
|
||||
import _ from "lodash";
|
||||
|
||||
export const handler: BunextAPIRouteHandler<
|
||||
APIResponseObject<BUN_SQLITE_WGUI_USERS>
|
||||
> = async (ctx) => {
|
||||
try {
|
||||
const body = ctx.body as ApiReqParams;
|
||||
|
||||
const users_res = await grabUsers({
|
||||
query: {
|
||||
sql_query: {
|
||||
limit: 1,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
console.log("users_res", users_res);
|
||||
|
||||
if (users_res.singleRes?.id) {
|
||||
return {
|
||||
success: false,
|
||||
};
|
||||
}
|
||||
|
||||
let final_insert_data = [
|
||||
...(body?.insert_data?.map((data) => {
|
||||
return { ...data, password: hash(data.password || "") };
|
||||
}) || []),
|
||||
];
|
||||
|
||||
const POST = await BunSQLite.insert<BUN_SQLITE_WGUI_USERS, TableType>({
|
||||
table: "users",
|
||||
data: final_insert_data,
|
||||
});
|
||||
|
||||
return POST;
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
msg: error.message,
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user