org_30
This commit is contained in:
parent
c8bddda2e2
commit
0c8b82a41f
3 changed files with 182 additions and 82 deletions
|
|
@ -58,18 +58,18 @@ export class OrgChild2Controller extends Controller {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const getOrgChild2 = {
|
const getOrgChild2 = {
|
||||||
"orgChild2Id" : orgChild2.id,
|
orgChild2Id: orgChild2.id,
|
||||||
"orgChild2Name" : orgChild2.orgChild2Name,
|
orgChild2Name: orgChild2.orgChild2Name,
|
||||||
"orgChild2ShortName" : orgChild2.orgChild2ShortName,
|
orgChild2ShortName: orgChild2.orgChild2ShortName,
|
||||||
"orgChild2Code" : orgChild2.orgChild2Code,
|
orgChild2Code: orgChild2.orgChild2Code,
|
||||||
"orgChild2Rank" : orgChild2.orgChild2Rank,
|
orgChild2Rank: orgChild2.orgChild2Rank,
|
||||||
"orgChild2Order" : orgChild2.orgChild2Order,
|
orgChild2Order: orgChild2.orgChild2Order,
|
||||||
"orgChild2PhoneEx" : orgChild2.orgChild2PhoneEx,
|
orgChild2PhoneEx: orgChild2.orgChild2PhoneEx,
|
||||||
"orgChild2PhoneIn" : orgChild2.orgChild2PhoneIn,
|
orgChild2PhoneIn: orgChild2.orgChild2PhoneIn,
|
||||||
"orgChild2Fax" : orgChild2.orgChild2Fax,
|
orgChild2Fax: orgChild2.orgChild2Fax,
|
||||||
"orgRevisionId" : orgChild2.orgRevisionId,
|
orgRevisionId: orgChild2.orgRevisionId,
|
||||||
"orgCode" : orgRoot.orgRootCode + orgChild2.orgChild2Code
|
orgCode: orgRoot.orgRootCode + orgChild2.orgChild2Code,
|
||||||
}
|
};
|
||||||
return new HttpSuccess(getOrgChild2);
|
return new HttpSuccess(getOrgChild2);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error;
|
return error;
|
||||||
|
|
@ -105,7 +105,7 @@ export class OrgChild2Controller extends Controller {
|
||||||
where: { id: requestBody.orgChild1Id },
|
where: { id: requestBody.orgChild1Id },
|
||||||
});
|
});
|
||||||
if (!child1) {
|
if (!child1) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child1Id");
|
||||||
}
|
}
|
||||||
|
|
||||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||||
|
|
@ -114,8 +114,14 @@ export class OrgChild2Controller extends Controller {
|
||||||
if (!revisionIdExits) {
|
if (!revisionIdExits) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||||
}
|
}
|
||||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
if (
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
revisionIdExits.orgRevisionIsDraft != true &&
|
||||||
|
revisionIdExits.orgRevisionIsCurrent != false
|
||||||
|
) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.NOT_FOUND,
|
||||||
|
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const validOrgChild2Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
const validOrgChild2Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||||
|
|
@ -179,8 +185,14 @@ export class OrgChild2Controller extends Controller {
|
||||||
if (!revisionIdExits) {
|
if (!revisionIdExits) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||||
}
|
}
|
||||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
if (
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
revisionIdExits.orgRevisionIsDraft != true &&
|
||||||
|
revisionIdExits.orgRevisionIsCurrent != false
|
||||||
|
) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.NOT_FOUND,
|
||||||
|
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const validOrgChild2Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
const validOrgChild2Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||||
|
|
@ -223,15 +235,21 @@ export class OrgChild2Controller extends Controller {
|
||||||
if (!child2) {
|
if (!child2) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||||
}
|
}
|
||||||
|
|
||||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||||
where: { id: child2.orgRevisionId },
|
where: { id: child2.orgRevisionId },
|
||||||
});
|
});
|
||||||
if (!revisionIdExits) {
|
if (!revisionIdExits) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||||
}
|
}
|
||||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
if (
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
revisionIdExits.orgRevisionIsDraft != true &&
|
||||||
|
revisionIdExits.orgRevisionIsCurrent != false
|
||||||
|
) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.NOT_FOUND,
|
||||||
|
"not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const exitsChild3 = await this.child3Repository.findOne({ where: { orgChild2Id: id } });
|
const exitsChild3 = await this.child3Repository.findOne({ where: { orgChild2Id: id } });
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { PosExecutive } from "../entities/PosExecutive";
|
import { PosExecutive } from "../entities/PosExecutive";
|
||||||
import { PosType } from "../entities/PosType";
|
import { PosType } from "../entities/PosType";
|
||||||
import { PosLevel } from "../entities/PosLevel";
|
import { PosLevel } from "../entities/PosLevel";
|
||||||
|
import { CreatePosition, Position } from "../entities/Position";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
@Route("api/v1/org/pos")
|
@Route("api/v1/org/pos")
|
||||||
@Tags("Position")
|
@Tags("Position")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -31,8 +33,9 @@ import { PosLevel } from "../entities/PosLevel";
|
||||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
export class PositionController extends Controller {
|
export class PositionController extends Controller {
|
||||||
private posExecutiveRepository = AppDataSource.getRepository(PosExecutive);
|
private posExecutiveRepository = AppDataSource.getRepository(PosExecutive);
|
||||||
private posTypeRepository = AppDataSource.getRepository(PosType)
|
private posTypeRepository = AppDataSource.getRepository(PosType);
|
||||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||||
|
private positionRepository = AppDataSource.getRepository(Position);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API รายการตำแหน่งทางการบริหาร
|
* API รายการตำแหน่งทางการบริหาร
|
||||||
|
|
@ -162,4 +165,60 @@ export class PositionController extends Controller {
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API เพิ่มตำแหน่ง
|
||||||
|
*
|
||||||
|
* @summary ORG_030 - เพิ่มตำแหน่ง (ADMIN) #33
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post("position")
|
||||||
|
@Example([
|
||||||
|
{
|
||||||
|
positionName: "นักบริหาร",
|
||||||
|
positionField: "บริหาร",
|
||||||
|
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||||
|
posLevelId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||||
|
posExecutiveId: "08db9e81-fc46-4e95-8b33-be4ca0016abf",
|
||||||
|
positionExecutiveField: "นักบริหาร",
|
||||||
|
positionArea: "บริหาร"
|
||||||
|
},
|
||||||
|
])
|
||||||
|
async createPosition(
|
||||||
|
@Body()
|
||||||
|
requestBody: CreatePosition,
|
||||||
|
@Request() request: { user: Record<string, any> },) {
|
||||||
|
const position = Object.assign(new Position(), requestBody);
|
||||||
|
if (!position) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkPosTypeId = await this.posTypeRepository.findOne({where: { id: requestBody.posTypeId }});
|
||||||
|
if (!checkPosTypeId) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosTypeId");
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkPosLevelId = await this.posLevelRepository.findOne({where: { id: requestBody.posLevelId }});
|
||||||
|
if (!checkPosLevelId) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId");
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkPosExecutiveId = await this.posExecutiveRepository.findOne({where: { id: requestBody.posExecutiveId }});
|
||||||
|
if (!checkPosExecutiveId) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosExecutiveId");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
position.createdUserId = request.user.sub;
|
||||||
|
position.createdFullName = request.user.name;
|
||||||
|
position.lastUpdateUserId = request.user.sub;
|
||||||
|
position.lastUpdateFullName = request.user.name;
|
||||||
|
await this.positionRepository.save(position);
|
||||||
|
return new HttpSuccess(position.id);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,71 +3,94 @@ import { EntityBase } from "./base/Base";
|
||||||
|
|
||||||
@Entity("position")
|
@Entity("position")
|
||||||
export class Position extends EntityBase {
|
export class Position extends EntityBase {
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
comment: "ชื่อตำแหน่งในสายงาน (ชื่อตำแหน่ง)",
|
comment: "ชื่อตำแหน่งในสายงาน (ชื่อตำแหน่ง)",
|
||||||
length: 255,
|
length: 255,
|
||||||
default: "string",
|
default: "string",
|
||||||
})
|
})
|
||||||
positionName: string;
|
positionName: string;
|
||||||
|
|
||||||
@Column({
|
|
||||||
nullable: true,
|
|
||||||
comment: "สายงาน",
|
|
||||||
length: 45,
|
|
||||||
default: "string",
|
|
||||||
})
|
|
||||||
positionField: string;
|
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
length: 40,
|
nullable: true,
|
||||||
comment: "ประเภทตำแหน่ง",
|
comment: "สายงาน",
|
||||||
default: "00000000-0000-0000-0000-000000000000",
|
length: 45,
|
||||||
})
|
default: "string",
|
||||||
posTypeId: string;
|
})
|
||||||
|
positionField: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
length: 40,
|
length: 40,
|
||||||
comment: "ระดับตำแหน่ง",
|
comment: "ประเภทตำแหน่ง",
|
||||||
default: "00000000-0000-0000-0000-000000000000",
|
default: "00000000-0000-0000-0000-000000000000",
|
||||||
})
|
})
|
||||||
posLevelId: string;
|
posTypeId: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
length: 40,
|
||||||
length: 40,
|
comment: "ระดับตำแหน่ง",
|
||||||
comment: "ตำแหน่งทางการบริหาร",
|
default: "00000000-0000-0000-0000-000000000000",
|
||||||
default: "00000000-0000-0000-0000-000000000000",
|
})
|
||||||
})
|
posLevelId: string;
|
||||||
posExecutiveId: string;
|
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
comment: "ด้านทางการบริหาร",
|
length: 40,
|
||||||
length: 255,
|
comment: "ตำแหน่งทางการบริหาร",
|
||||||
default: "string",
|
default: "00000000-0000-0000-0000-000000000000",
|
||||||
})
|
})
|
||||||
positionExecutiveField: string;
|
posExecutiveId: string;
|
||||||
|
|
||||||
@Column({
|
|
||||||
nullable: true,
|
|
||||||
comment: "ด้าน/สาขา",
|
|
||||||
length: 255,
|
|
||||||
default: "string",
|
|
||||||
})
|
|
||||||
positionArea: string;
|
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
comment: "เป็นตำแหน่งที่ถูกเลือกในรอบนั้นๆ หรือไม่?",
|
comment: "ด้านทางการบริหาร",
|
||||||
})
|
length: 255,
|
||||||
positionIsSelected: boolean;
|
default: "string",
|
||||||
|
})
|
||||||
|
positionExecutiveField: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
length: 40,
|
nullable: true,
|
||||||
comment: "เชื่อมโยงกับตารางเลขที่ตำแหน่ง",
|
comment: "ด้าน/สาขา",
|
||||||
default: "00000000-0000-0000-0000-000000000000",
|
length: 255,
|
||||||
})
|
default: "string",
|
||||||
posMasterId: string;
|
})
|
||||||
|
positionArea: string;
|
||||||
|
|
||||||
}
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "เป็นตำแหน่งที่ถูกเลือกในรอบนั้นๆ หรือไม่?",
|
||||||
|
})
|
||||||
|
positionIsSelected: boolean;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
length: 40,
|
||||||
|
comment: "เชื่อมโยงกับตารางเลขที่ตำแหน่ง",
|
||||||
|
default: "00000000-0000-0000-0000-000000000000",
|
||||||
|
})
|
||||||
|
posMasterId: string;
|
||||||
|
}
|
||||||
|
export class CreatePosition {
|
||||||
|
@Column()
|
||||||
|
positionName: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
positionField: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
posTypeId: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
posLevelId: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
posExecutiveId: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
positionExecutiveField: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
positionArea: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type UpdatePosition = Partial<CreatePosition>;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue