41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
|
module.exports = Self => {
|
||
|
Self.remoteMethodCtx('importTicketSales', {
|
||
|
description: 'Imports lines from claimBeginning to a new ticket with specific shipped, landed dates, agency and company',
|
||
|
accessType: 'WRITE',
|
||
|
accepts: [{
|
||
|
arg: 'params',
|
||
|
type: 'object',
|
||
|
http: {source: 'body'}
|
||
|
}],
|
||
|
returns: {
|
||
|
type: ['Object'],
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/importTicketSales`,
|
||
|
verb: 'POST'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.importTicketSales = async(ctx, params) => {
|
||
|
let models = Self.app.models;
|
||
|
let userId = ctx.req.accessToken.userId;
|
||
|
let worker = await models.Worker.findOne({where: {userFk: userId}});
|
||
|
|
||
|
let ticketSales = await models.Sale.find({
|
||
|
where: {ticketFk: params.ticketFk}
|
||
|
});
|
||
|
|
||
|
let claimEnds = [];
|
||
|
ticketSales.forEach(sale => {
|
||
|
claimEnds.push({
|
||
|
saleFk: sale.id,
|
||
|
claimFk: params.claimFk,
|
||
|
workerFk: worker.id
|
||
|
});
|
||
|
});
|
||
|
|
||
|
return await Self.create(claimEnds);
|
||
|
};
|
||
|
};
|