Bug/Test #1491, #1500 refactor new.js
gitea/salix/dev There was a failure building this commit Details

This commit is contained in:
Bernat 2019-06-03 10:05:22 +02:00
parent b034333cdb
commit fa7b79b1c8
5 changed files with 43 additions and 27 deletions

View File

@ -4,11 +4,24 @@ module.exports = Self => {
Self.remoteMethod('new', {
description: 'Create a new order and returns the new ID',
accessType: 'WRITE',
accepts: [{
arg: 'params',
type: 'object',
http: {source: 'body'}
}],
accepts: [
{
arg: 'landed',
description: 'The landed for the order',
type: 'date',
required: true
}, {
arg: 'addressId',
description: 'The address for the order',
type: 'number',
required: true
}, {
arg: 'agencyModeId',
description: 'The agencyMode for the order',
type: 'number',
required: true
}
],
returns: {
type: 'number',
root: true
@ -19,9 +32,9 @@ module.exports = Self => {
}
});
Self.new = async params => {
Self.new = async(landed, addressId, agencyModeId) => {
let address = await Self.app.models.Address.findOne({
where: {id: params.addressFk},
where: {id: addressId},
fields: ['clientFk'],
include: [
{relation: 'client',
@ -44,9 +57,9 @@ module.exports = Self => {
query = `CALL vn.orderListCreate(?, ?, ?, ?);`;
[result] = await Self.rawSql(query, [
params.landed,
params.agencyModeFk,
params.addressFk,
landed,
agencyModeId,
addressId,
'SALIX'
]);

View File

@ -23,11 +23,11 @@ module.exports = Self => {
where: {id: ticketFk}
});
let orderID = await Self.app.models.Order.new({
addressFk: ticket.addressFk,
landed: ticket.landed,
agencyModeFk: ticket.agencyModeFk
});
let landed = ticket.landed;
let addressFk = ticket.addressFk;
let agencyModeFk = ticket.agencyModeFk;
let orderID = await Self.app.models.Order.new(landed, addressFk, agencyModeFk);
return orderID;
};

View File

@ -12,9 +12,11 @@ describe('order new()', () => {
it('should throw an error if the client is frozen', async() => {
let error;
let params = {addressFk: 121};
let landed = new Date();
let addressFk = 121;
let agencyModeFk = 1;
await app.models.Order.new(params)
await app.models.Order.new(landed, addressFk, agencyModeFk)
.catch(e => {
error = e;
});
@ -24,9 +26,11 @@ describe('order new()', () => {
it('should throw an error if the client isnt frozen and isnt active', async() => {
let error;
let params = {addressFk: 6};
let landed = new Date();
let addressFk = 6;
let agencyModeFk = 1;
await app.models.Order.new(params)
await app.models.Order.new(landed, addressFk, agencyModeFk)
.catch(e => {
error = e;
});
@ -35,13 +39,11 @@ describe('order new()', () => {
});
it('should create a new order for the user with id 105 when all conditions are met', async() => {
let params = {
landed: new Date(),
agencyModeFk: 1,
addressFk: 125
};
let landed = new Date();
let addressFk = 125;
let agencyModeFk = 1;
orderId = await app.models.Order.new(params);
orderId = await app.models.Order.new(landed, addressFk, agencyModeFk);
let highestOrderIdInFixtures = 3;

View File

@ -31,5 +31,6 @@
label="Agency"
show-field="agency"
value-field="id"
rule="Order.agencyModeFk"
field="$ctrl.order.agencyModeFk">
</vn-autocomplete>

View File

@ -96,8 +96,8 @@ class Controller {
createOrder() {
let params = {
landed: this.order.landed,
addressFk: this.order.addressFk,
agencyModeFk: this.order.agencyModeFk
addressId: this.order.addressFk,
agencyModeId: this.order.agencyModeFk
};
this.$http.post(`order/api/Orders/new`, params).then(res => {
this.vnApp.showSuccess(this.translate.instant('Data saved!'));