List out house

view house detail
This commit is contained in:
2026-02-01 11:12:33 +07:00
parent ed7e5baaea
commit afa26ab50d
25 changed files with 570 additions and 103 deletions

67
src/service/house.api.ts Normal file
View File

@@ -0,0 +1,67 @@
import { prisma } from '@/db';
import { OrganizationWhereInput } from '@/generated/prisma/models';
import { authMiddleware } from '@/lib/middleware';
import { parseError } from '@/utils/helper';
import { createServerFn } from '@tanstack/react-start';
import { houseListSchema } from './house.schema';
export const getAllHouse = createServerFn({ method: 'GET' })
.middleware([authMiddleware])
.inputValidator(houseListSchema)
.handler(async ({ data }) => {
try {
const { page, limit, keyword } = data;
const skip = (page - 1) * limit;
const where: OrganizationWhereInput = {
OR: [
{
name: {
contains: keyword,
mode: 'insensitive',
},
},
],
};
const [list, total]: [OrganizationWithMembers[], number] =
await Promise.all([
await prisma.organization.findMany({
where,
orderBy: { createdAt: 'desc' },
include: {
members: {
select: {
role: true,
user: {
select: {
name: true,
email: true,
image: true,
},
},
},
},
},
take: limit,
skip,
}),
await prisma.organization.count({ where }),
]);
const totalPage = Math.ceil(+total / limit);
return {
result: list,
pagination: {
currentPage: page,
totalPage,
totalItem: total,
},
};
} catch (error) {
console.error(error);
const { message, code } = parseError(error);
throw { message, code };
}
});