feat: get branch endpoint
This commit is contained in:
parent
63de7b3e52
commit
d7b7a6ebee
1 changed files with 29 additions and 0 deletions
|
|
@ -43,6 +43,35 @@ function imageLocation(id: string) {
|
||||||
@Tags("Branch Contact")
|
@Tags("Branch Contact")
|
||||||
@Security("keycloak")
|
@Security("keycloak")
|
||||||
export class BranchContactController extends Controller {
|
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()
|
@Post()
|
||||||
async createBranchContact(
|
async createBranchContact(
|
||||||
@Request() req: RequestWithUser,
|
@Request() req: RequestWithUser,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue