ปรับ validate orgRevision (root)
This commit is contained in:
parent
71642cc5e1
commit
3fac128e5b
1 changed files with 20 additions and 25 deletions
|
|
@ -103,25 +103,20 @@ export class OrgRootController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({
|
||||
where: {
|
||||
id: requestBody.orgRevisionId,
|
||||
orgRevisionIsDraft: true,
|
||||
orgRevisionIsCurrent: false,
|
||||
},
|
||||
});
|
||||
|
||||
if (orgRevision) {
|
||||
orgRoot.createdUserId = request.user.sub;
|
||||
orgRoot.createdFullName = request.user.name;
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
await this.orgRootRepository.save(orgRoot);
|
||||
} else {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดี Revision");
|
||||
const orgRevision = await this.orgRevisionRepository.findOne({ where: { id: requestBody.orgRevisionId }});
|
||||
if (!orgRevision) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
}
|
||||
|
||||
if(orgRevision.orgRevisionIsDraft != true && orgRevision.orgRevisionIsCurrent != false){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
||||
}
|
||||
|
||||
orgRoot.createdUserId = request.user.sub;
|
||||
orgRoot.createdFullName = request.user.name;
|
||||
orgRoot.lastUpdateUserId = request.user.sub;
|
||||
orgRoot.lastUpdateFullName = request.user.name;
|
||||
await this.orgRootRepository.save(orgRoot);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
|
|
@ -159,16 +154,13 @@ export class OrgRootController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRootRank");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: {
|
||||
id: requestBody.orgRevisionId,
|
||||
orgRevisionIsDraft: true,
|
||||
orgRevisionIsCurrent: false,
|
||||
},
|
||||
});
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({ where: {id: requestBody.orgRevisionId} });
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
||||
}
|
||||
|
||||
const chkCode = await this.orgRootRepository.findOne({
|
||||
where: { orgRootCode: requestBody.orgRootCode },
|
||||
|
|
@ -218,11 +210,14 @@ export class OrgRootController extends Controller {
|
|||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: orgRoot.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
|
||||
where: { id: orgRoot.orgRevisionId },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
||||
}
|
||||
|
||||
await this.orgRootRepository.remove(orgRoot);
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue