Merge branch 'feat/branch-endpoints' into dev

This commit is contained in:
Methapon2001 2024-04-02 13:19:08 +07:00
commit 8a32de9bb0

View file

@ -127,6 +127,11 @@ export class BranchController extends Controller {
const { provinceId, districtId, subDistrictId, headOfficeId, ...rest } = body;
return await prisma.branch.create({
include: {
province: true,
district: true,
subDistrict: true,
},
data: {
...rest,
isHeadOffice: headOfficeId === null,
@ -198,7 +203,14 @@ export class BranchController extends Controller {
@Delete("{branchId}")
async deleteBranch(@Path() branchId: string) {
const record = await prisma.branch.findFirst({ where: { id: branchId } });
const record = await prisma.branch.findFirst({
include: {
province: true,
district: true,
subDistrict: true,
},
where: { id: branchId },
});
if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.");