Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop

This commit is contained in:
kittapath 2024-11-15 15:34:49 +07:00
commit f757e5aeeb
2 changed files with 86 additions and 0 deletions

View file

@ -1127,6 +1127,88 @@ export class CommandController extends Controller {
return new HttpSuccess();
}
/**
* API
*
* @summary API
*
* @param {string} id Id
*/
@Put("testRabbit/{id}")
async testRabbit(
@Path() id: string,
@Body()
requestBody: { sign?: boolean },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id: id },
relations: ["commandType", "commandRecives",],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
command.isSign = true;
if (command.commandExcecuteDate == null)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบวันที่คำสั่งมีผล");
let profiles =
command && command.commandRecives.length > 0
? command.commandRecives
.filter((x) => x.profileId != null)
.map((x) => ({
receiverUserId: x.profileId,
notiLink: "",
}))
: [];
await new CallAPI()
.PostData(request, "/placement/noti/profiles", {
subject: `${command.issue}`,
body: `${command.issue}`,
receiverUserIds: profiles,
payload: "", //แนบไฟล์
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.catch((error) => {
console.error("Error calling API:", error);
});
if (
new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()) <
new Date(
command.commandExcecuteDate.getFullYear(),
command.commandExcecuteDate.getMonth(),
command.commandExcecuteDate.getDate(),
)
) {
command.status = "WAITING";
command.lastUpdateUserId = request.user.sub;
command.lastUpdateFullName = request.user.name;
command.lastUpdatedAt = new Date();
await this.commandRepository.save(command);
} else {
const path = commandTypePath(command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
const msg = {
data: {
id: command.id,
status: "REPORTED",
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
lastUpdatedAt: new Date(),
},
user: request.user,
token: request.headers["authorization"],
};
sendToQueue(msg);
}
return new HttpSuccess();
}
async cronjobCommand(@Request() request?: RequestWithUser) {
const today = new Date();
today.setUTCHours(0, 0, 0, 0);

View file

@ -19,8 +19,12 @@ export async function init() {
const connection = await amqp.connect(url); //----> (1.3) set up url with amqp protocol
console.log(connection ? "[AMQ] connection success" : "[AMQ] connection failed");
const channel = await connection.createChannel(); //----> (1.4) create Channel
console.log(channel ? "[AMQ] create channel success" : "[AMQ] create channel failed");
channel.assertQueue(queue, { durable: true }); //----> (1.5) assert queue and set durable (if "true" save to disk on RabbitMQ)
channel.assertQueue(queue_org, { durable: true });
channel.prefetch(1);