useUsers refactor

This commit is contained in:
Carlos Mesquita
2024-09-08 09:37:19 +01:00
parent 898edb152f
commit 4282c1d021
6 changed files with 29 additions and 23 deletions

View File

@@ -45,7 +45,7 @@ async function registerIndividual(req: NextApiRequest, res: NextApiResponse) {
code?: string;
};
const codeDoc = await db.collection("codes").findOne<Code>({code});
const codeDoc = await db.collection("codes").findOne<Code>({id: code});
if (code && code.length > 0 && !!codeDoc) {
res.status(400).json({error: "Invalid Code!"});

View File

@@ -35,7 +35,7 @@ async function del(req: NextApiRequest, res: NextApiResponse) {
return;
}
const targetUser = await db.collection("users").findOne<User>({id});
const targetUser = await db.collection("users").findOne<User>({id: id});
if (!targetUser) {
res.status(404).json({ok: false});
return;

View File

@@ -3,7 +3,6 @@ import type {NextApiRequest, NextApiResponse} from "next";
import {withIronSessionApiRoute} from "iron-session/next";
import {sessionOptions} from "@/lib/session";
import {getLinkedUsers} from "@/utils/users.be";
import {Type} from "@/interfaces/user";
export default withIronSessionApiRoute(handler, sessionOptions);
@@ -15,16 +14,16 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
const {
size,
type,
page,
orderBy,
direction = "desc",
} = req.query as {size?: string; type?: Type; page?: string; orderBy?: string; direction?: "asc" | "desc"};
...query
} = req.query as {size?: string; page?: string; orderBy?: string; direction?: "asc" | "desc"; [key: string]: string | string[] | undefined};
const {users, total} = await getLinkedUsers(
req.session.user?.id,
req.session.user?.type,
type,
query,
page !== undefined ? parseInt(page) : undefined,
size !== undefined ? parseInt(size) : undefined,
orderBy,