upd: api test

This commit is contained in:
2025-12-01 15:14:24 +08:00
parent 4cc28c4311
commit 5ecf264155
3 changed files with 88 additions and 7 deletions

View File

@@ -9,9 +9,31 @@ const WargaRoute = new Elysia({
})
.get("/list", async ({ query }) => {
const { search } = query
const { search, page = 1 } = query
const dataSkip = page == null || page == undefined ? 0 : Number(page) * 10 - 10;
const totalData = await prisma.warga.count({
where: {
OR: [
{
name: {
contains: search,
mode: "insensitive"
}
},
{
phone: {
contains: search,
mode: "insensitive"
}
}
]
}
});
const data = await prisma.warga.findMany({
skip: dataSkip,
take: 10,
where: {
OR: [
{
@@ -33,7 +55,15 @@ const WargaRoute = new Elysia({
}
})
return data
const dataFix = {
data,
total: totalData,
page: Number(page) || 1,
pageSize: 10,
totalPages: Math.ceil(totalData / 10)
};
return dataFix
}, {
detail: {
summary: "List Warga",