แก้ไขสิทธิ์
This commit is contained in:
parent
4641362b95
commit
0024ed9414
9 changed files with 154 additions and 27 deletions
|
|
@ -25,6 +25,7 @@ import { CommandSend } from "../entities/CommandSend";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import { CommandSendCC } from "../entities/CommandSendCC";
|
||||
|
||||
@Route("api/v1/org/command")
|
||||
@Tags("Command")
|
||||
|
|
@ -38,6 +39,7 @@ export class CommandController extends Controller {
|
|||
private commandRepository = AppDataSource.getRepository(Command);
|
||||
private commandTypeRepository = AppDataSource.getRepository(CommandType);
|
||||
private commandSendRepository = AppDataSource.getRepository(CommandSend);
|
||||
private commandSendCCRepository = AppDataSource.getRepository(CommandSendCC);
|
||||
private profileRepository = AppDataSource.getRepository(Profile);
|
||||
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
|
||||
|
||||
|
|
@ -232,7 +234,7 @@ export class CommandController extends Controller {
|
|||
async GetByIdTab3(@Path() id: string) {
|
||||
const command = await this.commandRepository.findOne({
|
||||
where: { id },
|
||||
relations: ["commandSends"],
|
||||
relations: ["commandSends", "commandSends.commandSendCCs"],
|
||||
});
|
||||
if (!command) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
||||
|
|
@ -246,7 +248,7 @@ export class CommandController extends Controller {
|
|||
lastName: item.lastName,
|
||||
position: item.position,
|
||||
org: item.org,
|
||||
sendCC: item.sendCC,
|
||||
sendCC: item.commandSendCCs.map((x) => x.name),
|
||||
profileId: item.profileId,
|
||||
}));
|
||||
return new HttpSuccess(_command);
|
||||
|
|
@ -330,7 +332,7 @@ export class CommandController extends Controller {
|
|||
requestBody: {
|
||||
commandSend: {
|
||||
id: string;
|
||||
sendCC: string;
|
||||
sendCC: string[];
|
||||
}[];
|
||||
},
|
||||
@Request() request: RequestWithUser,
|
||||
|
|
@ -342,16 +344,25 @@ export class CommandController extends Controller {
|
|||
|
||||
await Promise.all(
|
||||
requestBody.commandSend.map(async (item) => {
|
||||
const commandSend = await this.commandSendRepository.findOne({
|
||||
where: { id: item.id },
|
||||
const commandSendCC = await this.commandSendCCRepository.find({
|
||||
where: { commandSendId: item.id },
|
||||
});
|
||||
if (!commandSend) return;
|
||||
await this.commandSendCCRepository.remove(commandSendCC);
|
||||
|
||||
commandSend.sendCC = item.sendCC;
|
||||
commandSend.lastUpdateUserId = request.user.sub;
|
||||
commandSend.lastUpdateFullName = request.user.name;
|
||||
commandSend.lastUpdatedAt = new Date();
|
||||
await this.commandSendRepository.save(commandSend);
|
||||
await Promise.all(
|
||||
item.sendCC.map(async (item1) => {
|
||||
const _commandSendCC = new CommandSendCC();
|
||||
_commandSendCC.name = item1;
|
||||
_commandSendCC.commandSendId = item.id;
|
||||
_commandSendCC.createdUserId = request.user.sub;
|
||||
_commandSendCC.createdFullName = request.user.name;
|
||||
_commandSendCC.createdAt = new Date();
|
||||
_commandSendCC.lastUpdateUserId = request.user.sub;
|
||||
_commandSendCC.lastUpdateFullName = request.user.name;
|
||||
_commandSendCC.lastUpdatedAt = new Date();
|
||||
await this.commandSendCCRepository.save(_commandSendCC);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue