7322-addSelectAddressOnTicketTransfer #3363

Open
jtubau wants to merge 2 commits from 7322-addSelectAddressOnTicketTransfer into dev
1 changed files with 7 additions and 3 deletions

View File

@ -12,6 +12,10 @@ module.exports = Self => {
arg: 'clientFk', arg: 'clientFk',
type: 'number', type: 'number',
required: true, required: true,
}, {
arg: 'addressFk',
type: 'number',
required: false,
}], }],
http: { http: {
path: `/:id/transferClient`, path: `/:id/transferClient`,
@ -19,7 +23,7 @@ module.exports = Self => {
} }
}); });
Self.transferClient = async(ctx, id, clientFk, options) => { Self.transferClient = async(ctx, id, clientFk, options, addressFk) => {
Review

la variabla options siempre la dejamos la última

la variabla options siempre la dejamos la última
const models = Self.app.models; const models = Self.app.models;
const myOptions = {}; const myOptions = {};
let tx; let tx;
@ -43,10 +47,10 @@ module.exports = Self => {
const client = await models.Client.findById(clientFk, const client = await models.Client.findById(clientFk,
{fields: ['id', 'defaultAddressFk']}, myOptions); {fields: ['id', 'defaultAddressFk']}, myOptions);
const address = await models.Address.findById(client.defaultAddressFk, const address = await models.Address.findById(addressFk ? addressFk : client.defaultAddressFk,
{fields: ['id', 'nickname']}, myOptions); {fields: ['id', 'nickname']}, myOptions);
const attributes = {clientFk, addressFk: client.defaultAddressFk, nickname: address.nickname}; const attributes = {clientFk, addressFk: address.id, nickname: address.nickname};
const tickets = []; const tickets = [];
const ticketIds = []; const ticketIds = [];