diff --git a/back/methods/notification/send.js b/back/methods/notification/send.js index 58a26dd28..3d3842b5d 100644 --- a/back/methods/notification/send.js +++ b/back/methods/notification/send.js @@ -16,19 +16,18 @@ module.exports = Self => { Self.send = async options => { const models = Self.app.models; - const findStatus = 'pending'; const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options); const notificationQueue = await models.NotificationQueue.find({ - where: {status: findStatus}, + where: {status: 'pending'}, include: [ { relation: 'notification', scope: { - include: { + include: [{ relation: 'subscription', scope: { include: { @@ -40,18 +39,21 @@ module.exports = Self => { } } } - } - } + }, + }, { + relation: 'notificationTemplate', + fields: ['id'] + }] } - } - ] + }] }, myOptions); + console.log('notificationQueue: ', notificationQueue); const statusSent = 'sent'; for (const queue of notificationQueue) { - const queueName = queue.notification().name; + const queueName = queue.notification().notificationTemplate().code; const queueParams = JSON.parse(queue.params); for (const notificationUser of queue.notification().subscription()) { @@ -74,7 +76,6 @@ module.exports = Self => { await queue.updateAttribute('status', statusSent); } catch (error) { - console.log('error: ', error); await queue.updateAttribute('status', 'error'); } } diff --git a/back/models/notification.json b/back/models/notification.json index 56f66bf1d..18cc00cb6 100644 --- a/back/models/notification.json +++ b/back/models/notification.json @@ -25,6 +25,11 @@ "type": "hasMany", "model": "NotificationSubscription", "foreignKey": "notificationFk" + }, + "notificationTemplate": { + "type": "belongsTo", + "model": "NotificationTemplate", + "foreignKey": "templateFk" } } } \ No newline at end of file diff --git a/print/core/email.js b/print/core/email.js index 2d1ee42cf..fc5aff9af 100644 --- a/print/core/email.js +++ b/print/core/email.js @@ -18,6 +18,7 @@ class Email extends Component { } async getSubject() { + if (this.args.subject) return this.args.subject; return (await this.getUserLocale())['subject']; } @@ -77,7 +78,8 @@ class Email extends Component { for (let attachment of options.attachments) attachments.push(attachment); } - + console.log(typeof this.args); + console.log(this.args?.subject); const localeSubject = await this.getSubject(); const mailOptions = { to: this.args.recipient, diff --git a/print/templates/email/blank-notification/blank-notification.html b/print/templates/email/blank-notification/blank-notification.html index 266db117d..c3f63723f 100644 --- a/print/templates/email/blank-notification/blank-notification.html +++ b/print/templates/email/blank-notification/blank-notification.html @@ -1,7 +1,8 @@
-

pinga

+

+

\ No newline at end of file diff --git a/print/templates/email/blank-notification/blank-notification.js b/print/templates/email/blank-notification/blank-notification.js index 051fb5a6f..7ac4e8609 100755 --- a/print/templates/email/blank-notification/blank-notification.js +++ b/print/templates/email/blank-notification/blank-notification.js @@ -1,10 +1,9 @@ const Component = require(`vn-print/core/component`); -const emailBody = new Component(); -console.log('entra'); +const emailBody = new Component('email-body'); module.exports = { name: 'blank-notification', components: { - 'email-body': emailBody.build(), + 'email-body': emailBody.build() }, props: { title: { @@ -12,8 +11,10 @@ module.exports = { required: true }, text: { - type: String, - required: true + type: String + }, + subject: { + type: String } } };