salix/back/methods/chat/notifyIssues.js

40 lines
1.0 KiB
JavaScript

module.exports = Self => {
Self.remoteMethodCtx('notifyIssues', {
description: 'Notifies new urgent issues',
accessType: 'READ',
returns: {
type: 'Object',
root: true
},
http: {
path: `/notifyIssues`,
verb: 'GET'
}
});
Self.notifyIssues = async ctx => {
const models = Self.app.models;
const $t = ctx.req.__; // $translate
const [urgentIssue] = await Self.rawSql(`
SELECT * FROM managedesktop.vn_workOrderInmediata LIMIT 1
`);
if (!urgentIssue) return;
const message = $t(`There's a new urgent ticket`, {
title: urgentIssue.title,
issueId: urgentIssue.workOrderId
});
const department = await models.Department.findOne({
where: {code: 'IT'}
});
const channelName = department && department.chatName;
if (channelName)
return Self.send(ctx, `#${channelName}`, `@all ➔ ${message}`);
return;
};
};