This commit is contained in:
2026-03-12 13:07:43 +00:00
parent 5131e22c69
commit 3663d91aa6
5 changed files with 123 additions and 2 deletions
@@ -0,0 +1,46 @@
import loginUser from "@/src/functions/auth/login-user";
import { NSQLITE_TURBOCI_ADMIN_USERS } from "@/src/db/types";
import userAuth from "@/src/utils/user-auth";
import NSQLite from "@moduletrace/nsqlite";
import { APIResponseObject } from "@moduletrace/datasquirel/dist/package-shared/types";
import type { NextApiRequest, NextApiResponse } from "next";
import { APIReqObject } from "@/src/types";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse<APIResponseObject>,
) {
try {
if (req.method !== "POST") {
return res.json({
success: false,
msg: "Wrong Method",
});
}
const { singleRes: user } = await userAuth({ req });
if (!user?.id || !user.super_admin) {
return res.json({
success: false,
msg: "Unauthorized",
});
}
const { user_id } = req.query as APIReqObject;
const target_user_res =
await NSQLite.select<NSQLITE_TURBOCI_ADMIN_USERS>({
table: "users",
targetId: user_id,
});
const target_user = target_user_res.singleRes;
const updated = await loginUser({ res, user_id: user.id });
return res.json(updated);
} catch (error: any) {
return res.json({ success: false, msg: error.message });
}
}