feat: list customer
This commit is contained in:
parent
578fc225d9
commit
e76650bfce
1 changed files with 32 additions and 0 deletions
|
|
@ -50,6 +50,38 @@ function imageLocation(id: string) {
|
||||||
@Tags("Customer")
|
@Tags("Customer")
|
||||||
@Security("keycloak")
|
@Security("keycloak")
|
||||||
export class CustomerController extends Controller {
|
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()
|
@Post()
|
||||||
async create(@Request() req: RequestWithUser, @Body() body: CustomerCreate) {
|
async create(@Request() req: RequestWithUser, @Body() body: CustomerCreate) {
|
||||||
const record = await prisma.customer.create({
|
const record = await prisma.customer.create({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue