สลับตำแหน่งเงินเดือน
This commit is contained in:
parent
ab365257de
commit
021ee8cd6e
4 changed files with 74 additions and 1 deletions
|
|
@ -20,6 +20,7 @@ import HttpError from "../interfaces/http-error";
|
||||||
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
|
import { ProfileSalaryHistory } from "../entities/ProfileSalaryHistory";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import { Profile } from "../entities/Profile";
|
import { Profile } from "../entities/Profile";
|
||||||
|
import { LessThan, MoreThan } from "typeorm";
|
||||||
|
|
||||||
@Route("api/v1/org/profile/salary")
|
@Route("api/v1/org/profile/salary")
|
||||||
@Tags("ProfileSalary")
|
@Tags("ProfileSalary")
|
||||||
|
|
@ -59,7 +60,10 @@ export class ProfileSalaryController extends Controller {
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
public async getSalary(@Path() profileId: string) {
|
public async getSalary(@Path() profileId: string) {
|
||||||
const record = await this.salaryRepo.findBy({ profileId });
|
const record = await this.salaryRepo.find({
|
||||||
|
where: { profileId: profileId },
|
||||||
|
order: { order: "ASC" },
|
||||||
|
});
|
||||||
return new HttpSuccess(record);
|
return new HttpSuccess(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -133,9 +137,15 @@ export class ProfileSalaryController extends Controller {
|
||||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dest_item = await this.salaryRepo.findOne({
|
||||||
|
where: { profileId: body.profileId },
|
||||||
|
order: { order: "DESC" },
|
||||||
|
});
|
||||||
|
|
||||||
const data = new ProfileSalary();
|
const data = new ProfileSalary();
|
||||||
|
|
||||||
const meta = {
|
const meta = {
|
||||||
|
order: dest_item == null ? 1 : dest_item.order,
|
||||||
createdUserId: req.user.sub,
|
createdUserId: req.user.sub,
|
||||||
createdFullName: req.user.name,
|
createdFullName: req.user.name,
|
||||||
lastUpdateUserId: req.user.sub,
|
lastUpdateUserId: req.user.sub,
|
||||||
|
|
@ -186,4 +196,37 @@ export class ProfileSalaryController extends Controller {
|
||||||
|
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get("swap/{direction}/{salaryId}")
|
||||||
|
public async swapSalary(@Path() direction: string, salaryId: string) {
|
||||||
|
const source_item = await this.salaryRepo.findOne({ where: { id: salaryId } });
|
||||||
|
if (source_item == null) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
const sourceOrder = source_item.order;
|
||||||
|
if (direction.trim().toUpperCase() == "UP") {
|
||||||
|
console.log("xxxxxxxxxxxxxxxxxxxxxxxxx");
|
||||||
|
const dest_item = await this.salaryRepo.findOne({
|
||||||
|
where: { profileId: source_item.profileId, order: LessThan(sourceOrder) },
|
||||||
|
order: { order: "DESC" },
|
||||||
|
});
|
||||||
|
console.log("vvvvvvvvvvvvvvvvvvvvvvv");
|
||||||
|
if (dest_item == null) return new HttpSuccess();
|
||||||
|
console.log("ccccccccccccccccccccccccc");
|
||||||
|
var destOrder = dest_item.order;
|
||||||
|
dest_item.order = sourceOrder;
|
||||||
|
source_item.order = destOrder;
|
||||||
|
console.log("zzzzzzzzzzzzzzzzzzzzz");
|
||||||
|
await Promise.all([this.salaryRepo.save(source_item), this.salaryRepo.save(dest_item)]);
|
||||||
|
} else {
|
||||||
|
const dest_item = await this.salaryRepo.findOne({
|
||||||
|
where: { profileId: source_item.profileId, order: MoreThan(sourceOrder) },
|
||||||
|
order: { order: "ASC" },
|
||||||
|
});
|
||||||
|
if (dest_item == null) return new HttpSuccess();
|
||||||
|
var destOrder = dest_item.order;
|
||||||
|
dest_item.order = sourceOrder;
|
||||||
|
source_item.order = destOrder;
|
||||||
|
await Promise.all([this.salaryRepo.save(source_item), this.salaryRepo.save(dest_item)]);
|
||||||
|
}
|
||||||
|
return new HttpSuccess();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,13 @@ export class ProfileSalary extends EntityBase {
|
||||||
})
|
})
|
||||||
templateDoc: string;
|
templateDoc: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "ลำดับตำแหน่ง",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
order: number;
|
||||||
|
|
||||||
@OneToMany(() => ProfileSalaryHistory, (profileSalaryHistory) => profileSalaryHistory.histories)
|
@OneToMany(() => ProfileSalaryHistory, (profileSalaryHistory) => profileSalaryHistory.histories)
|
||||||
profileSalaryHistories: ProfileSalaryHistory[];
|
profileSalaryHistories: ProfileSalaryHistory[];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,13 @@ export class ProfileSalaryHistory extends EntityBase {
|
||||||
})
|
})
|
||||||
profileSalaryId: string;
|
profileSalaryId: string;
|
||||||
|
|
||||||
|
@Column({
|
||||||
|
nullable: true,
|
||||||
|
comment: "ลำดับตำแหน่ง",
|
||||||
|
default: null,
|
||||||
|
})
|
||||||
|
order: number;
|
||||||
|
|
||||||
@ManyToOne(() => ProfileSalary, (profileSalary) => profileSalary.profileSalaryHistories)
|
@ManyToOne(() => ProfileSalary, (profileSalary) => profileSalary.profileSalaryHistories)
|
||||||
@JoinColumn({ name: "profileSalaryId" })
|
@JoinColumn({ name: "profileSalaryId" })
|
||||||
histories: ProfileSalary;
|
histories: ProfileSalary;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||||
|
|
||||||
|
export class UpdateTableProfilesalaryAddOrder1711599588075 implements MigrationInterface {
|
||||||
|
name = 'UpdateTableProfilesalaryAddOrder1711599588075'
|
||||||
|
|
||||||
|
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` ADD \`order\` int NULL COMMENT 'ลำดับตำแหน่ง'`);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileSalary\` ADD \`order\` int NULL COMMENT 'ลำดับตำแหน่ง'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileSalary\` DROP COLUMN \`order\``);
|
||||||
|
await queryRunner.query(`ALTER TABLE \`profileSalaryHistory\` DROP COLUMN \`order\``);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue