ทำสำเนา
This commit is contained in:
parent
7d3839a195
commit
eabd1c4ac7
1 changed files with 55 additions and 1 deletions
|
|
@ -616,12 +616,15 @@ export class CommandController extends Controller {
|
|||
requestBody: { commandNo?: string | null; commandYear?: number | null },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const command = await this.commandRepository.findOne({ where: { id: id } });
|
||||
const command = await this.commandRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!command) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
||||
}
|
||||
const copy = new Command();
|
||||
Object.assign(copy, { ...command, ...requestBody, id: undefined });
|
||||
copy.status = "NEW";
|
||||
copy.createdUserId = request.user.sub;
|
||||
copy.createdFullName = request.user.name;
|
||||
copy.createdAt = new Date();
|
||||
|
|
@ -629,6 +632,57 @@ export class CommandController extends Controller {
|
|||
copy.lastUpdateFullName = request.user.name;
|
||||
copy.lastUpdatedAt = new Date();
|
||||
await this.commandRepository.save(copy);
|
||||
|
||||
const commandRecives = await this.commandReciveRepository.find({
|
||||
where: { commandId: id },
|
||||
});
|
||||
const commandSends = await this.commandSendRepository.find({
|
||||
where: { commandId: id },
|
||||
});
|
||||
const commandSendCCs = await this.commandSendCCRepository.find({
|
||||
where: { commandSendId: In(commandSends.map((x) => x.id)) },
|
||||
});
|
||||
commandRecives.map((x: any) => {
|
||||
delete x.id;
|
||||
return {
|
||||
...x,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
createdAt: new Date(),
|
||||
lastUpdateUserId: request.user.sub,
|
||||
lastUpdateFullName: request.user.name,
|
||||
lastUpdatedAt: new Date(),
|
||||
};
|
||||
});
|
||||
await this.commandRepository.save(commandRecives);
|
||||
|
||||
commandSends.map((x: any) => {
|
||||
delete x.id;
|
||||
return {
|
||||
...x,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
createdAt: new Date(),
|
||||
lastUpdateUserId: request.user.sub,
|
||||
lastUpdateFullName: request.user.name,
|
||||
lastUpdatedAt: new Date(),
|
||||
};
|
||||
});
|
||||
await this.commandRepository.save(commandSends);
|
||||
|
||||
commandSendCCs.map((x: any) => {
|
||||
delete x.id;
|
||||
return {
|
||||
...x,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
createdAt: new Date(),
|
||||
lastUpdateUserId: request.user.sub,
|
||||
lastUpdateFullName: request.user.name,
|
||||
lastUpdatedAt: new Date(),
|
||||
};
|
||||
});
|
||||
await this.commandRepository.save(commandSendCCs);
|
||||
return new HttpSuccess(copy.id);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue