api ออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง
This commit is contained in:
parent
b7ce71d017
commit
4cccf6f685
1 changed files with 72 additions and 2 deletions
|
|
@ -38,7 +38,7 @@ import { OrgChild1 } from "../entities/OrgChild1";
|
|||
import { OrgChild2 } from "../entities/OrgChild2";
|
||||
import { OrgChild3 } from "../entities/OrgChild3";
|
||||
import { OrgChild4 } from "../entities/OrgChild4";
|
||||
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
@Route("api/v1/org/placement/change-position")
|
||||
@Tags("Placement")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -163,6 +163,7 @@ export class ChangePositionController extends Controller {
|
|||
) {
|
||||
const [changePosition, total] = await AppDataSource.getRepository(ChangePosition)
|
||||
.createQueryBuilder("changePosition")
|
||||
.leftJoinAndSelect("changePosition.profileChangePosition", "profileChangePosition")
|
||||
.where(
|
||||
searchKeyword ?
|
||||
"changePosition.name LIKE :keyword OR changePosition.date LIKE :keyword OR changePosition.status LIKE :keyword"
|
||||
|
|
@ -187,7 +188,10 @@ export class ChangePositionController extends Controller {
|
|||
@Get("{id}")
|
||||
async GetChangePositionById( @Path() id: string ) {
|
||||
|
||||
const data = await this.changePositionRepository.findOne({ where: { id: id }});
|
||||
const data = await this.changePositionRepository.findOne({
|
||||
relations: ["profileChangePosition"],
|
||||
where: { id: id }}
|
||||
);
|
||||
if (!data) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรอบย้ายสับเปลี่ยนตำแหน่ง");
|
||||
return new HttpSuccess(data);
|
||||
}
|
||||
|
|
@ -338,6 +342,7 @@ export class ChangePositionController extends Controller {
|
|||
profileChangePos.positionNumberOld = body.positionNumberOld;
|
||||
profileChangePos.amountOld = body.amountOld;
|
||||
profileChangePos.reason = body.reason? String(body.reason) : "";
|
||||
profileChangePos.dateCurrent = body.dateCurrent;
|
||||
await this.profileChangePositionRepository.save(profileChangePos);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -465,5 +470,70 @@ export class ChangePositionController extends Controller {
|
|||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API ออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง REPORT
|
||||
*
|
||||
* @summary API ออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง REPORT (ADMIN)
|
||||
*
|
||||
*/
|
||||
@Post("report")
|
||||
async sendReport(@Request() request: RequestWithUser, @Body() requestBody: { id: string[] }) {
|
||||
const profilechangePositions = await this.changePositionRepository.find({
|
||||
relations: ["profileChangePosition"],
|
||||
where: { id: In(requestBody.id) }
|
||||
});
|
||||
|
||||
for (const item of profilechangePositions) {
|
||||
item.status = "REPORT";
|
||||
item.lastUpdateUserId = request.user.sub;
|
||||
item.lastUpdateFullName = request.user.name;
|
||||
if (item.profileChangePosition) {
|
||||
for (const profile of item.profileChangePosition) {
|
||||
profile.status = "REPORT";
|
||||
profile.lastUpdateUserId = request.user.sub;
|
||||
profile.lastUpdateFullName = request.user.name;
|
||||
await this.profileChangePositionRepository.save(profile);
|
||||
}
|
||||
}
|
||||
await this.changePositionRepository.save(item);
|
||||
}
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API ออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง DONE
|
||||
*
|
||||
* @summary API ออกคำสั่งย้ายสับเปลี่ยนตำแหน่ง DONE (ADMIN)
|
||||
*
|
||||
*/
|
||||
@Post("report/resume")
|
||||
async doneReport(
|
||||
@Body()
|
||||
body: {
|
||||
result: {
|
||||
id: string;
|
||||
}[];
|
||||
},
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
await Promise.all(
|
||||
body.result.map(async (v) => {
|
||||
const profile = await this.profileChangePositionRepository.findOne({
|
||||
where: { id: v.id }
|
||||
});
|
||||
if (profile != null) {
|
||||
await new CallAPI()
|
||||
.PostData(request, "org/profile/salary", {
|
||||
profileId: profile.id,
|
||||
date: new Date(),
|
||||
})
|
||||
.then(async (x) => {
|
||||
profile.status = "DONE";
|
||||
await this.profileChangePositionRepository.save(profile);
|
||||
});
|
||||
}
|
||||
}),
|
||||
);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue