edit status code
This commit is contained in:
parent
1384b41b9b
commit
4abee90c38
4 changed files with 309 additions and 321 deletions
|
|
@ -47,16 +47,16 @@ export class OrgChild4Controller extends Controller {
|
|||
* @param {string} id Id Child4
|
||||
*/
|
||||
@Get("{id}")
|
||||
async GetChild4(@Path() id: string) {
|
||||
try {
|
||||
const orgChild4 = await this.child4Repository.findOne({ where: { id } });
|
||||
if (!orgChild4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 4");
|
||||
}
|
||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild4.orgRootId } });
|
||||
async GetChild4(@Path() id: string) {
|
||||
const orgChild4 = await this.child4Repository.findOne({ where: { id } });
|
||||
if (!orgChild4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 4");
|
||||
}
|
||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild4.orgRootId } });
|
||||
if (!orgRoot) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
|
||||
}
|
||||
try {
|
||||
const getOrgChild4 = {
|
||||
"orgChild4Id" : orgChild4.id,
|
||||
"orgChild4Name" : orgChild4.orgChild4Name,
|
||||
|
|
@ -101,8 +101,6 @@ export class OrgChild4Controller extends Controller {
|
|||
requestBody: CreateOrgChild4,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
try {
|
||||
//BE ใช้ orgChild3Id หา orgChild1Id, orgRootId
|
||||
const child3 = await this.child3Repository.findOne({
|
||||
where: { id: requestBody.orgChild3Id },
|
||||
});
|
||||
|
|
@ -124,7 +122,7 @@ export class OrgChild4Controller extends Controller {
|
|||
if (!validOrgChild4Ranks.includes(requestBody.orgChild4Rank.toUpperCase())) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild4Rank");
|
||||
}
|
||||
|
||||
try {
|
||||
const child4 = Object.assign(new OrgChild4(), requestBody) as OrgChild4;
|
||||
child4.orgChild4Name = requestBody.orgChild4Name;
|
||||
child4.createdUserId = request.user.sub;
|
||||
|
|
@ -171,37 +169,36 @@ export class OrgChild4Controller extends Controller {
|
|||
requestBody: UpdateOrgChild4,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const child3IdExits = await this.child3Repository.findOne({
|
||||
where: { id: requestBody.orgChild3Id },
|
||||
});
|
||||
if (!child3IdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child3Id");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child3IdExits.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 validOrgChild4Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (
|
||||
requestBody.orgChild4Rank == null ||
|
||||
!validOrgChild4Ranks.includes(requestBody.orgChild4Rank.toUpperCase())
|
||||
) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
|
||||
}
|
||||
|
||||
const child4 = await this.child4Repository.findOne({ where: { id } });
|
||||
if (!child4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
try {
|
||||
const child3IdExits = await this.child3Repository.findOne({
|
||||
where: { id: requestBody.orgChild3Id },
|
||||
});
|
||||
if (!child3IdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child3Id");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child3IdExits.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 validOrgChild4Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (
|
||||
requestBody.orgChild4Rank == null ||
|
||||
!validOrgChild4Ranks.includes(requestBody.orgChild4Rank.toUpperCase())
|
||||
) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
|
||||
}
|
||||
|
||||
const child4 = await this.child4Repository.findOne({ where: { id } });
|
||||
if (!child4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
child4.lastUpdateUserId = request.user.sub;
|
||||
child4.lastUpdateFullName = request.user.name;
|
||||
child4.lastUpdatedAt = new Date();
|
||||
|
|
@ -227,22 +224,21 @@ export class OrgChild4Controller extends Controller {
|
|||
*/
|
||||
@Delete("{id}")
|
||||
async delete(@Path() id: string) {
|
||||
const child4 = await this.child4Repository.findOne({ where: { id } });
|
||||
if (!child4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child4.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");
|
||||
}
|
||||
try {
|
||||
const child4 = await this.child4Repository.findOne({ where: { id } });
|
||||
if (!child4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child4.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.child4Repository.remove(child4);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue