diff --git a/src/controllers/customer-controller.ts b/src/controllers/customer-controller.ts index 68ce96c..a02da59 100644 --- a/src/controllers/customer-controller.ts +++ b/src/controllers/customer-controller.ts @@ -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({