#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 => { module.exports = Self => {
Self.remoteMethod('createFromSales', { Self.remoteMethodCtx('createFromSales', {
description: 'Create a claim', description: 'Create a claim',
accessType: '', accessType: '',
accepts: [{ accepts: [{
@ -25,10 +25,14 @@ module.exports = Self => {
} }
}); });
Self.createFromSales = async params => { Self.createFromSales = async(ctx, params) => {
let model = Self.app.models; let model = Self.app.models;
let transaction = await Self.beginTransaction({}); let transaction = await Self.beginTransaction({});
try { 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 newClaim = await Self.create(params.claim, {transaction});
let promises = []; let promises = [];
for (let i = 0; i < params.sales.length; i++) { for (let i = 0; i < params.sales.length; i++) {

View File

@ -13,8 +13,7 @@ describe('Claim Create', () => {
let newClaim = { let newClaim = {
ticketFk: 2, ticketFk: 2,
clientFk: 101, clientFk: 101,
ticketCreated: newDate, ticketCreated: newDate
workerFk: 18
}; };
let newSale = [{ let newSale = [{
@ -24,9 +23,10 @@ describe('Claim Create', () => {
}]; }];
let params = {claim: newClaim, sales: newSale}; let params = {claim: newClaim, sales: newSale};
let ctx = {req: {accessToken: {userId: 1}}};
it('should create a new claim', async() => { 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.ticketFk).toEqual(newClaim.ticketFk);
expect(claim.clientFk).toEqual(newClaim.clientFk); 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() => { it('should not be able to create a claim if exists that sale', async() => {
let error; let error;
await app.models.Claim.createFromSales(params) await app.models.Claim.createFromSales(ctx, params)
.catch(e => { .catch(e => {
error = e; error = e;

View File

@ -180,8 +180,7 @@ class Controller {
let claim = { let claim = {
ticketFk: this.ticket.id, ticketFk: this.ticket.id,
clientFk: this.ticket.clientFk, clientFk: this.ticket.clientFk,
ticketCreated: this.ticket.shipped, ticketCreated: this.ticket.shipped
workerFk: this.ticket.client.salesPersonFk
}; };
let sales = this.getCheckedLines(); let sales = this.getCheckedLines();
for (let i = 0; i < sales.length; i++) for (let i = 0; i < sales.length; i++)