Merge branch 'develop' into working

This commit is contained in:
Suphonchai Phoonsawat 2024-10-08 11:47:41 +07:00
commit 12b2a2f1fd
3 changed files with 101 additions and 42 deletions

View file

@ -88,18 +88,6 @@ export class CommandController extends Controller {
) {
const [commands, total] = await this.commandRepository
.createQueryBuilder("command")
.andWhere(
new Brackets((qb) => {
qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :keyword" : "1=1", {
keyword: `%${keyword}%`,
}).orWhere(
keyword != null && keyword != "" ? "command.createdFullName LIKE :keyword" : "1=1",
{
keyword: `%${keyword}%`,
},
);
}),
)
.andWhere(
status != null && status != undefined && status != ""
? "command.status IN (:...status)"
@ -133,6 +121,18 @@ export class CommandController extends Controller {
: `${commandTypeId}`,
},
)
.andWhere(
new Brackets((qb) => {
qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :keyword" : "1=1", {
keyword: `%${keyword}%`,
}).orWhere(
keyword != null && keyword != "" ? "command.issue LIKE :keyword" : "1=1",
{
keyword: `%${keyword}%`,
},
);
}),
)
.orderBy("command.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize)
@ -432,13 +432,24 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Delete("tab2/{commandReciveId}")
async DeleteTab2(@Path() commandReciveId: string) {
async DeleteTab2(@Path() commandReciveId: string, @Request() request: RequestWithUser) {
const commandRecive = await this.commandReciveRepository.findOne({
where: { id: commandReciveId },
relations: ["command", "command.commandType"],
});
if (!commandRecive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับคำสั่ง");
}
const path = this.commandTypePath(commandRecive.command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
await new CallAPI()
.PostData(request, path + "/delete", {
refIds: [commandRecive.refId],
})
.then(async (res) => {})
.catch(() => {});
const commandId = commandRecive.commandId;
await this.commandReciveRepository.delete(commandRecive.id);
@ -452,6 +463,7 @@ export class CommandController extends Controller {
p.order = i + 1;
await this.commandReciveRepository.save(p);
});
return new HttpSuccess();
}
@ -619,7 +631,6 @@ export class CommandController extends Controller {
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับสำเนาคำสั่ง");
}
await this.commandSendCCRepository.delete({ commandSendId: commandSendId });
await this.commandSendRepository.delete(commandSendId);
return new HttpSuccess();
@ -725,9 +736,10 @@ export class CommandController extends Controller {
* @param {string} id Id
*/
@Delete("{id}")
async Delete(@Path() id: string) {
async Delete(@Path() id: string, @Request() request: RequestWithUser) {
const command = await this.commandRepository.findOne({
where: { id: id },
relations: ["commandType", "commandRecives"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -735,6 +747,16 @@ export class CommandController extends Controller {
const commandSend = await this.commandSendRepository.find({
where: { commandId: id },
});
const path = this.commandTypePath(command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
await new CallAPI()
.PostData(request, path + "/delete", {
refIds: command.commandRecives.map((x) => x.refId),
})
.then(async (res) => {})
.catch(() => {});
await this.commandSendCCRepository.delete({ commandSendId: In(commandSend.map((x) => x.id)) });
await this.commandReciveRepository.delete({ commandId: command.id });
await this.commandSendRepository.delete({ commandId: command.id });
@ -873,6 +895,24 @@ export class CommandController extends Controller {
command.isSign = true;
if (command.commandExcecuteDate == null)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบวันที่คำสั่งมีผล");
let profiles = command.commandRecives
.filter((x) => x.profileId != null)
.map(async (x) => x.profileId);
await new CallAPI()
.PostData(request, "/placement/noti/profiles", {
subject: `${command.issue}`,
body: `${command.issue}`,
receiverUserId: profiles,
payload: "",//แนบไฟล์
isSendMail: true,
isSendInbox: true,
receiveDate: command.commandExcecuteDate,
})
.catch((error) => {
console.error("Error calling API:", error);
});
if (
new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()) <
new Date(
@ -979,20 +1019,22 @@ export class CommandController extends Controller {
await new CallAPI()
.PostData(request, path + "/attachment", {
refIds: command.commandRecives.map((x) => ({
refId: x.refId,
Sequence: x.order,
CitizenId: x.citizenId,
Prefix: x.prefix,
FirstName: x.firstName,
LastName: x.lastName,
Amount: x.amount,
PositionSalaryAmount: x.positionSalaryAmount,
MouthSalaryAmount: x.mouthSalaryAmount,
RemarkHorizontal: x.remarkHorizontal,
RemarkVertical: x.remarkVertical,
CommandYear: command.commandYear,
})),
refIds: command.commandRecives
.filter((x) => x.refId != null)
.map((x) => ({
refId: x.refId,
Sequence: x.order,
CitizenId: x.citizenId,
Prefix: x.prefix,
FirstName: x.firstName,
LastName: x.lastName,
Amount: x.amount,
PositionSalaryAmount: x.positionSalaryAmount,
MouthSalaryAmount: x.mouthSalaryAmount,
RemarkHorizontal: x.remarkHorizontal,
RemarkVertical: x.remarkVertical,
CommandYear: command.commandYear,
})),
})
.then(async (res) => {
console.log(res);
@ -1025,6 +1067,7 @@ export class CommandController extends Controller {
commandExcecuteDate?: Date | null;
persons: {
refId: string;
profileId?: string|null;
citizenId: string;
prefix: string;
firstName: string;
@ -1035,7 +1078,7 @@ export class CommandController extends Controller {
) {
let command = new Command();
let commandCode = null;
let null_:any = null
let null_: any = null;
if (
requestBody.commandId != undefined &&
requestBody.commandId != null &&
@ -1074,13 +1117,13 @@ export class CommandController extends Controller {
command.isAttachment = commandType.isAttachment;
command.status = "NEW";
command.issue = commandType.name;
command.commandAffectDate = requestBody.commandAffectDate
(command.commandAffectDate = requestBody.commandAffectDate
? new Date(requestBody.commandAffectDate)
: null_,
command.commandExcecuteDate = requestBody.commandExcecuteDate
? new Date(requestBody.commandExcecuteDate)
: null_,
command.createdUserId = request.user.sub;
: null_),
(command.commandExcecuteDate = requestBody.commandExcecuteDate
? new Date(requestBody.commandExcecuteDate)
: null_),
(command.createdUserId = request.user.sub);
command.createdFullName = request.user.name;
command.createdAt = new Date();
command.lastUpdateUserId = request.user.sub;
@ -1093,7 +1136,7 @@ export class CommandController extends Controller {
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
await new CallAPI()
.PostData(request, path, {
refIds: requestBody.persons.map((x) => x.refId),
refIds: requestBody.persons.filter((x) => x.refId != null).map((x) => x.refId),
})
.then(async (res) => {
let order =

View file

@ -101,11 +101,13 @@ export class CommandRecive extends EntityBase {
@JoinColumn({ name: "commandId" })
command: Command;
// @Column({
// length: 40,
// comment: "คีย์นอก(FK)ของตาราง profile",
// })
// profileId: string;
@Column({
nullable: true,
length: 40,
comment: "คีย์นอก(FK)ของตาราง profile",
default: null,
})
profileId: string;
// @ManyToOne(() => Profile, (profile) => profile.commandRecives)
// @JoinColumn({ name: "profileId" })

View file

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableAssign11728318691161 implements MigrationInterface {
name = 'AddTableAssign11728318691161'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`commandRecive\` ADD \`profileId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง profile'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`commandRecive\` DROP COLUMN \`profileId\``);
}
}