refs #5094 add scopes #1540
|
@ -4,25 +4,25 @@ module.exports = Self => {
|
||||||
Self.remoteMethodCtx('deliveryNoteEmail', {
|
Self.remoteMethodCtx('deliveryNoteEmail', {
|
||||||
description: 'Sends the delivery note email with an docuware attached PDF',
|
description: 'Sends the delivery note email with an docuware attached PDF',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
|
accessScopes: ['docuwareDeliveryNoteEmail'],
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The ticket id',
|
description: 'The ticket id',
|
||||||
http: {source: 'path'}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
arg: 'recipient',
|
|
||||||
type: 'string',
|
|
||||||
description: 'The recipient email',
|
|
||||||
required: true,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'recipientId',
|
arg: 'recipientId',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: 'The client id',
|
description: 'The client id',
|
||||||
required: false
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'recipient',
|
||||||
|
type: 'string',
|
||||||
|
description: 'The recipient email',
|
||||||
|
required: false,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
returns: [
|
returns: [
|
||||||
|
@ -41,12 +41,13 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
http: {
|
http: {
|
||||||
path: '/:id/delivery-note-email',
|
path: '/delivery-note-email',
|
||||||
verb: 'POST'
|
verb: 'POST'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.deliveryNoteEmail = async(ctx, id) => {
|
Self.deliveryNoteEmail = async(ctx, id, recipientId, recipient) => {
|
||||||
|
const models = Self.app.models;
|
||||||
const args = Object.assign({}, ctx.args);
|
const args = Object.assign({}, ctx.args);
|
||||||
const params = {
|
const params = {
|
||||||
recipient: args.recipient,
|
recipient: args.recipient,
|
||||||
|
@ -57,9 +58,11 @@ module.exports = Self => {
|
||||||
for (const param in args)
|
for (const param in args)
|
||||||
params[param] = args[param];
|
params[param] = args[param];
|
||||||
|
|
||||||
|
if (!recipient) params.recipient = models.Client.findById(recipientId, {fields: ['email']});
|
||||||
|
|
||||||
const email = new Email('delivery-note', params);
|
const email = new Email('delivery-note', params);
|
||||||
|
|
||||||
const docuwareFile = await Self.app.models.Docuware.download(ctx, id, 'deliveryNote');
|
const docuwareFile = await models.Docuware.download(ctx, id, 'deliveryNote');
|
||||||
|
|
||||||
return email.send({
|
return email.send({
|
||||||
overrideAttachments: true,
|
overrideAttachments: true,
|
||||||
|
|
|
@ -142,9 +142,10 @@ class Controller extends Section {
|
||||||
|
|
||||||
sendPdfDeliveryNote($data) {
|
sendPdfDeliveryNote($data) {
|
||||||
let query = `tickets/${this.id}/delivery-note-email`;
|
let query = `tickets/${this.id}/delivery-note-email`;
|
||||||
if (this.hasDocuwareFile) query = `docuwares/${this.id}/delivery-note-email`;
|
if (this.hasDocuwareFile) query = `docuwares/delivery-note-email`;
|
||||||
|
|
||||||
return this.vnEmail.send(query, {
|
return this.vnEmail.send(query, {
|
||||||
|
id: this.id,
|
||||||
recipientId: this.ticket.client.id,
|
recipientId: this.ticket.client.id,
|
||||||
recipient: $data.email
|
recipient: $data.email
|
||||||
});
|
});
|
||||||
|
|
|
@ -141,6 +141,7 @@ describe('Ticket Component vnTicketDescriptorMenu', () => {
|
||||||
|
|
||||||
const $data = {email: 'brucebanner@gothamcity.com'};
|
const $data = {email: 'brucebanner@gothamcity.com'};
|
||||||
const params = {
|
const params = {
|
||||||
|
id: 16,
|
||||||
recipient: $data.email,
|
recipient: $data.email,
|
||||||
recipientId: ticket.client.id
|
recipientId: ticket.client.id
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue