diff --git a/src/controllers/branch/branch-controller.ts b/src/controllers/branch/branch-controller.ts index 65b95fb..79af679 100644 --- a/src/controllers/branch/branch-controller.ts +++ b/src/controllers/branch/branch-controller.ts @@ -207,6 +207,10 @@ export class BranchController extends Controller { }, }); + if (headOfficeId) { + await prisma.branch.update({ where: { id: headOfficeId }, data: { status: Status.ACTIVE } }); + } + this.setStatus(HttpStatus.CREATED); return record; @@ -299,21 +303,10 @@ export class BranchController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found"); } - if (record.status === Status.USED) { + if (record.status !== Status.CREATED) { throw new HttpError(HttpStatus.FORBIDDEN, "Branch is in used.", "data_in_used"); } - await prisma.user.updateMany({ - where: { - NOT: { - branch: { some: {} }, - }, - }, - data: { - status: Status.CREATED, - }, - }); - return await prisma.branch.delete({ include: { province: true, diff --git a/src/controllers/branch/user-controller.ts b/src/controllers/branch/user-controller.ts index 483f1c4..c326805 100644 --- a/src/controllers/branch/user-controller.ts +++ b/src/controllers/branch/user-controller.ts @@ -84,8 +84,8 @@ export class BranchUserController extends Controller { } await prisma.user.updateMany({ - where: { id: { in: body.user } }, - data: { status: Status.USED }, + where: { id: { in: body.user }, status: Status.CREATED }, + data: { status: Status.ACTIVE }, }); await prisma.branchUser.createMany({ @@ -177,8 +177,8 @@ export class UserBranchController extends Controller { } await prisma.branch.updateMany({ - where: { id: { in: body.branch } }, - data: { status: Status.USED }, + where: { id: { in: body.branch }, status: Status.CREATED }, + data: { status: Status.ACTIVE }, }); await prisma.branchUser.createMany({ diff --git a/src/controllers/user/user-controller.ts b/src/controllers/user/user-controller.ts index f507caf..6be8828 100644 --- a/src/controllers/user/user-controller.ts +++ b/src/controllers/user/user-controller.ts @@ -321,7 +321,7 @@ export class UserController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "data_not_found"); } - if (record.status === Status.USED) { + if (record.status !== Status.CREATED) { throw new HttpError(HttpStatus.FORBIDDEN, "User is in used.", "data_in_used"); } @@ -329,17 +329,6 @@ export class UserController extends Controller { forceDelete: true, }); - await prisma.branch.updateMany({ - where: { - NOT: { - user: { some: {} }, - }, - }, - data: { - status: Status.CREATED, - }, - }); - return await prisma.user.delete({ include: { province: true,