#1245 bug ticket line
gitea/salix/dev This commit looks good Details

This commit is contained in:
Javi Gallego 2019-03-21 14:56:09 +01:00
parent bbb00b98dc
commit 0dd7e528dd
3 changed files with 11 additions and 8 deletions

View File

@ -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++) {

View File

@ -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;

View File

@ -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++)