validate orgRevisionId (root, child1)
This commit is contained in:
parent
f9f0782cb2
commit
93683f897b
2 changed files with 38 additions and 12 deletions
|
|
@ -72,7 +72,7 @@ export class OrgRootController extends Controller {
|
|||
}
|
||||
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||
where: { id: requestBody.orgRevisionId },
|
||||
where: { id: requestBody.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
|
||||
});
|
||||
|
||||
if (orgRevision) {
|
||||
|
|
@ -82,7 +82,8 @@ export class OrgRootController extends Controller {
|
|||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
await this.orgRootRepository.save(orgRoot);
|
||||
} else {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี Revision");
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี Revision");
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
@ -123,7 +124,7 @@ export class OrgRootController extends Controller {
|
|||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: requestBody.orgRevisionId },
|
||||
where: { id: requestBody.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
|
|
@ -164,21 +165,23 @@ export class OrgRootController extends Controller {
|
|||
async delete(@Path() id: string) {
|
||||
try {
|
||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id } });
|
||||
const orgChild1 = await this.orgChild1Repository.findOne({ where: { orgRootId: id } });
|
||||
|
||||
if (!orgRoot) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
|
||||
if (!orgChild1) {
|
||||
await this.orgRootRepository.remove(orgRoot);
|
||||
} else {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1",
|
||||
);
|
||||
const orgChild1 = await this.orgChild1Repository.findOne({ where: { orgRootId: id } });
|
||||
if(orgChild1 != null){
|
||||
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR,"ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1",);
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: orgRoot.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
|
||||
await this.orgRootRepository.remove(orgRoot);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue