feat: list customer

This commit is contained in:
Methapon2001 2024-04-05 11:00:31 +07:00
parent 578fc225d9
commit e76650bfce

View file

@ -50,6 +50,38 @@ function imageLocation(id: string) {
@Tags("Customer")
@Security("keycloak")
export class CustomerController extends Controller {
@Get()
async list(
@Query() query: string = "",
@Query() page: number = 1,
@Query() pageSize: number = 30,
) {
const where = {
OR: [{ customerName: { contains: query } }, { customerNameEN: { contains: query } }],
} satisfies Prisma.CustomerWhereInput;
const [result, total] = await prisma.$transaction([
prisma.customer.findMany({
where,
take: pageSize,
skip: (page - 1) * pageSize,
}),
prisma.customer.count({ where }),
]);
return {
result: await Promise.all(
result.map(async (v) => ({
...v,
imageUrl: await minio.presignedGetObject(MINIO_BUCKET, imageLocation(v.id), 12 * 60 * 60),
})),
),
page,
pageSize,
total,
};
}
@Post()
async create(@Request() req: RequestWithUser, @Body() body: CustomerCreate) {
const record = await prisma.customer.create({