WIP: 6367-blankNotification #1903

Draft
pablone wants to merge 11 commits from 6367-blankNotification into dev
5 changed files with 26 additions and 16 deletions
Showing only changes of commit 97b6cac486 - Show all commits

View File

@ -16,19 +16,18 @@ module.exports = Self => {
Self.send = async options => { Self.send = async options => {
const models = Self.app.models; const models = Self.app.models;
const findStatus = 'pending';
const myOptions = {}; const myOptions = {};
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const notificationQueue = await models.NotificationQueue.find({ const notificationQueue = await models.NotificationQueue.find({
where: {status: findStatus}, where: {status: 'pending'},
include: [ include: [
{ {
relation: 'notification', relation: 'notification',
scope: { scope: {
include: { include: [{
relation: 'subscription', relation: 'subscription',
scope: { scope: {
include: { include: {
@ -40,18 +39,21 @@ module.exports = Self => {
} }
} }
} }
} },
} }, {
relation: 'notificationTemplate',
fields: ['id']
}]
} }
} }]
]
}, myOptions); }, myOptions);
console.log('notificationQueue: ', notificationQueue);
const statusSent = 'sent'; const statusSent = 'sent';
for (const queue of notificationQueue) { for (const queue of notificationQueue) {
const queueName = queue.notification().name; const queueName = queue.notification().notificationTemplate().code;
const queueParams = JSON.parse(queue.params); const queueParams = JSON.parse(queue.params);
for (const notificationUser of queue.notification().subscription()) { for (const notificationUser of queue.notification().subscription()) {
@ -74,7 +76,6 @@ module.exports = Self => {
await queue.updateAttribute('status', statusSent); await queue.updateAttribute('status', statusSent);
} catch (error) { } catch (error) {
console.log('error: ', error);
await queue.updateAttribute('status', 'error'); await queue.updateAttribute('status', 'error');
} }
} }

View File

@ -25,6 +25,11 @@
"type": "hasMany", "type": "hasMany",
"model": "NotificationSubscription", "model": "NotificationSubscription",
"foreignKey": "notificationFk" "foreignKey": "notificationFk"
},
"notificationTemplate": {
"type": "belongsTo",
"model": "NotificationTemplate",
"foreignKey": "templateFk"
} }
} }
} }

View File

@ -18,6 +18,7 @@ class Email extends Component {
} }
async getSubject() { async getSubject() {
if (this.args.subject) return this.args.subject;
return (await this.getUserLocale())['subject']; return (await this.getUserLocale())['subject'];
} }
@ -77,7 +78,8 @@ class Email extends Component {
for (let attachment of options.attachments) for (let attachment of options.attachments)
attachments.push(attachment); attachments.push(attachment);
} }
console.log(typeof this.args);
console.log(this.args?.subject);
const localeSubject = await this.getSubject(); const localeSubject = await this.getSubject();
const mailOptions = { const mailOptions = {
to: this.args.recipient, to: this.args.recipient,

View File

@ -1,7 +1,8 @@
<email-body v-bind="$props"> <email-body v-bind="$props">
<div class="grid-row"> <div class="grid-row">
<div class="grid-block vn-pa-ml"> <div class="grid-block vn-pa-ml">
<h1>pinga</h1> <h1 v-html="title" align="center"></h1>
<p v-html="text"></p>
</div> </div>
</div> </div>
</email-body> </email-body>

View File

@ -1,10 +1,9 @@
const Component = require(`vn-print/core/component`); const Component = require(`vn-print/core/component`);
const emailBody = new Component(); const emailBody = new Component('email-body');
console.log('entra');
module.exports = { module.exports = {
name: 'blank-notification', name: 'blank-notification',
components: { components: {
'email-body': emailBody.build(), 'email-body': emailBody.build()
}, },
props: { props: {
title: { title: {
@ -12,8 +11,10 @@ module.exports = {
required: true required: true
}, },
text: { text: {
type: String, type: String
required: true },
subject: {
type: String
} }
} }
}; };