feat: get branch endpoint

This commit is contained in:
Methapon2001 2024-04-02 15:25:28 +07:00
parent 63de7b3e52
commit d7b7a6ebee

View file

@ -43,6 +43,35 @@ function imageLocation(id: string) {
@Tags("Branch Contact")
@Security("keycloak")
export class BranchContactController extends Controller {
@Get()
async getBranchContact(
@Path() branchId: string,
@Query() page: number = 1,
@Query() pageSize: number = 30,
) {
const [result, total] = await prisma.$transaction([
prisma.branchContact.findMany({
where: { branchId },
take: pageSize,
skip: (page - 1) * pageSize,
}),
prisma.branchContact.count({ where: { branchId } }),
]);
return { result, page, pageSize, total };
}
@Get("{contactId}")
async getBranchContactById(@Path() branchId: string, @Path() contactId: string) {
const record = await prisma.branchContact.findFirst({ where: { id: contactId, branchId } });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.");
return Object.assign(record, {
qrCodeImageUrl: await minio.presignedGetObject(MINIO_BUCKET, imageLocation(record.id)),
});
}
@Post()
async createBranchContact(
@Request() req: RequestWithUser,