parent
bbb00b98dc
commit
0dd7e528dd
|
@ -1,5 +1,5 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('createFromSales', {
|
||||
Self.remoteMethodCtx('createFromSales', {
|
||||
description: 'Create a claim',
|
||||
accessType: '',
|
||||
accepts: [{
|
||||
|
@ -25,10 +25,14 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.createFromSales = async params => {
|
||||
Self.createFromSales = async(ctx, params) => {
|
||||
let model = Self.app.models;
|
||||
let transaction = await Self.beginTransaction({});
|
||||
try {
|
||||
let userId = ctx.req.accessToken.userId;
|
||||
let worker = await Self.app.models.Worker.findOne({where: {userFk: userId}});
|
||||
|
||||
params.claim.workerFk = worker.id;
|
||||
let newClaim = await Self.create(params.claim, {transaction});
|
||||
let promises = [];
|
||||
for (let i = 0; i < params.sales.length; i++) {
|
||||
|
|
|
@ -13,8 +13,7 @@ describe('Claim Create', () => {
|
|||
let newClaim = {
|
||||
ticketFk: 2,
|
||||
clientFk: 101,
|
||||
ticketCreated: newDate,
|
||||
workerFk: 18
|
||||
ticketCreated: newDate
|
||||
};
|
||||
|
||||
let newSale = [{
|
||||
|
@ -24,9 +23,10 @@ describe('Claim Create', () => {
|
|||
}];
|
||||
|
||||
let params = {claim: newClaim, sales: newSale};
|
||||
let ctx = {req: {accessToken: {userId: 1}}};
|
||||
|
||||
it('should create a new claim', async() => {
|
||||
let claim = await app.models.Claim.createFromSales(params);
|
||||
let claim = await app.models.Claim.createFromSales(ctx, params);
|
||||
|
||||
expect(claim.ticketFk).toEqual(newClaim.ticketFk);
|
||||
expect(claim.clientFk).toEqual(newClaim.clientFk);
|
||||
|
@ -44,7 +44,7 @@ describe('Claim Create', () => {
|
|||
it('should not be able to create a claim if exists that sale', async() => {
|
||||
let error;
|
||||
|
||||
await app.models.Claim.createFromSales(params)
|
||||
await app.models.Claim.createFromSales(ctx, params)
|
||||
|
||||
.catch(e => {
|
||||
error = e;
|
||||
|
|
|
@ -180,8 +180,7 @@ class Controller {
|
|||
let claim = {
|
||||
ticketFk: this.ticket.id,
|
||||
clientFk: this.ticket.clientFk,
|
||||
ticketCreated: this.ticket.shipped,
|
||||
workerFk: this.ticket.client.salesPersonFk
|
||||
ticketCreated: this.ticket.shipped
|
||||
};
|
||||
let sales = this.getCheckedLines();
|
||||
for (let i = 0; i < sales.length; i++)
|
||||
|
|
Loading…
Reference in New Issue