fix: update status once used and must not delete
This commit is contained in:
parent
24c39d0cf0
commit
767127cec9
3 changed files with 10 additions and 28 deletions
|
|
@ -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);
|
this.setStatus(HttpStatus.CREATED);
|
||||||
|
|
||||||
return record;
|
return record;
|
||||||
|
|
@ -299,21 +303,10 @@ export class BranchController extends Controller {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found");
|
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");
|
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({
|
return await prisma.branch.delete({
|
||||||
include: {
|
include: {
|
||||||
province: true,
|
province: true,
|
||||||
|
|
|
||||||
|
|
@ -84,8 +84,8 @@ export class BranchUserController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
await prisma.user.updateMany({
|
await prisma.user.updateMany({
|
||||||
where: { id: { in: body.user } },
|
where: { id: { in: body.user }, status: Status.CREATED },
|
||||||
data: { status: Status.USED },
|
data: { status: Status.ACTIVE },
|
||||||
});
|
});
|
||||||
|
|
||||||
await prisma.branchUser.createMany({
|
await prisma.branchUser.createMany({
|
||||||
|
|
@ -177,8 +177,8 @@ export class UserBranchController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
await prisma.branch.updateMany({
|
await prisma.branch.updateMany({
|
||||||
where: { id: { in: body.branch } },
|
where: { id: { in: body.branch }, status: Status.CREATED },
|
||||||
data: { status: Status.USED },
|
data: { status: Status.ACTIVE },
|
||||||
});
|
});
|
||||||
|
|
||||||
await prisma.branchUser.createMany({
|
await prisma.branchUser.createMany({
|
||||||
|
|
|
||||||
|
|
@ -321,7 +321,7 @@ export class UserController extends Controller {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "User cannot be found.", "data_not_found");
|
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");
|
throw new HttpError(HttpStatus.FORBIDDEN, "User is in used.", "data_in_used");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -329,17 +329,6 @@ export class UserController extends Controller {
|
||||||
forceDelete: true,
|
forceDelete: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
await prisma.branch.updateMany({
|
|
||||||
where: {
|
|
||||||
NOT: {
|
|
||||||
user: { some: {} },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
status: Status.CREATED,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return await prisma.user.delete({
|
return await prisma.user.delete({
|
||||||
include: {
|
include: {
|
||||||
province: true,
|
province: true,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue