import { PrismaClient } from "@prisma/client"; import { NUl } from "naive-ui"; import { Find } from "~/types"; const db = new PrismaClient(); async function find() { return await db.job .findMany({ include: { data: true, }, orderBy: [ { pin: "desc", }, { updateTime: "desc", }, ], }) .then((jobs) => { console.log("finded"); return jobs; }) .finally(() => console.log("failed")) .catch((err) => { return err; }); } async function findSort(area: string, type: string, time: string, pay: number) { return await db.job .findMany({ where: { area: !area ? undefined : area, place: !type ? undefined : type, worktime: !time ? undefined : time, data: { pay: { gte: Number(pay), }, }, }, orderBy: [ { pin: "desc", }, { updateTime: "desc", }, ], include: { data: true, }, }) .then((jobs) => { console.log("findSorts"); return jobs; }) .finally(() => console.log("OK")) .catch((err) => { return err; }); } export default defineEventHandler(async (event) => { const args: Find = getQuery(event); let result; if (JSON.stringify(args) == "{}") { result = await find(); } else { result = await findSort(args.area, args.type, args.time, args.pay); } return JSON.stringify(result); });