Tarea #1573 order.catalog No deben de mostrar familias vacias
This commit is contained in:
parent
7e1eba53f1
commit
fa4fd15450
|
@ -0,0 +1,57 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('getItemTypeAvailable', {
|
||||
description: 'Gets the item types available for an rder and item category ',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'order id',
|
||||
http: {source: 'path'}
|
||||
},
|
||||
{
|
||||
arg: 'itemCategoryId',
|
||||
type: 'number',
|
||||
required: true
|
||||
}],
|
||||
returns: {
|
||||
type: 'number',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/getItemTypeAvailable`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getItemTypeAvailable = async(orderId, itemCategoryId) => {
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
|
||||
let order = await app.models.Order.findById(orderId);
|
||||
stmt = new ParameterizedSQL('call vn.available_calc(?, ?, ?)', [
|
||||
order.landed,
|
||||
order.addressFk,
|
||||
order.agencyModeFk
|
||||
]);
|
||||
stmts.push(stmt);
|
||||
stmt = new ParameterizedSQL(`SELECT it.id, it.name
|
||||
FROM tmp.availableCalc ac
|
||||
JOIN cache.available a ON a.calc_id = ac.calcFk
|
||||
JOIN item i ON i.id = a.item_id
|
||||
JOIN itemType it ON it.id = i.typeFk
|
||||
WHERE it.categoryFk = ?
|
||||
GROUP BY it.id`, [
|
||||
itemCategoryId
|
||||
]);
|
||||
let categoriesIndex = stmts.push(stmt) - 1;
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
let result = await Self.rawStmt(sql);
|
||||
|
||||
return result[categoriesIndex];
|
||||
};
|
||||
};
|
|
@ -0,0 +1,19 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('order getItemTypeAvailable()', () => {
|
||||
it('should call the getItemTypeAvailable method with a valid order and item category', async() => {
|
||||
let orderId = 11;
|
||||
let itemCategoryId = 1;
|
||||
let result = await app.models.Order.getItemTypeAvailable(orderId, itemCategoryId);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should call the getItemTypeAvailable method with the same order and different item category', async() => {
|
||||
let orderId = 11;
|
||||
let itemCategoryId = 4;//
|
||||
let result = await app.models.Order.getItemTypeAvailable(orderId, itemCategoryId);
|
||||
|
||||
expect(result.length).toEqual(0);
|
||||
});
|
||||
});
|
|
@ -13,4 +13,5 @@ module.exports = Self => {
|
|||
require('../methods/order/updateBasicData')(Self);
|
||||
require('../methods/order/confirm')(Self);
|
||||
require('../methods/order/filter')(Self);
|
||||
require('../methods/order/getItemTypeAvailable')(Self);
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@ class Controller {
|
|||
constructor($scope, $state) {
|
||||
this.$scope = $scope;
|
||||
this.$state = $state;
|
||||
this.$stateParams = $state.params;
|
||||
|
||||
// Static autocomplete data
|
||||
this.wayList = [
|
||||
|
|
|
@ -91,8 +91,12 @@ class Controller {
|
|||
* Refreshes item type dropdown data
|
||||
*/
|
||||
updateItemTypes() {
|
||||
const query = `/item/api/ItemCategories/${this.category.id}/itemTypes`;
|
||||
this.$http.get(query).then(res => {
|
||||
let params = {
|
||||
itemCategoryId: this.category.id
|
||||
};
|
||||
|
||||
const query = `/api/Orders/${this.order.id}/getItemTypeAvailable`;
|
||||
this.$http.get(query, {params}).then(res => {
|
||||
this.itemTypes = res.data;
|
||||
});
|
||||
}
|
||||
|
@ -195,6 +199,6 @@ ngModule.component('vnCatalogFilter', {
|
|||
catalog: '^vnOrderCatalog'
|
||||
},
|
||||
bindings: {
|
||||
order: '<',
|
||||
order: '<'
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import './index.js';
|
||||
import crudModel from 'core/mocks/crud-model';
|
||||
|
||||
describe('Order', () => {
|
||||
fdescribe('Order', () => {
|
||||
describe('Component vnCatalogFilter', () => {
|
||||
let $scope;
|
||||
let $state;
|
||||
|
@ -30,7 +30,7 @@ describe('Order', () => {
|
|||
|
||||
describe('order() setter', () => {
|
||||
it(`should call scope $applyAsync() method and apply filters from state params`, () => {
|
||||
$httpBackend.expect('GET', `/item/api/ItemCategories/1/itemTypes`).respond();
|
||||
$httpBackend.expect('GET', `/api/Orders/4/getItemTypeAvailable?itemCategoryId=1`).respond();
|
||||
spyOn(controller.$scope, '$applyAsync').and.callThrough();
|
||||
controller.order = {id: 4};
|
||||
|
||||
|
@ -53,6 +53,7 @@ describe('Order', () => {
|
|||
|
||||
it(`should set category property and then call updateStateParams() and applyFilters() methods`, () => {
|
||||
spyOn(controller, 'updateStateParams');
|
||||
controller._order = {id: 4};
|
||||
controller.category = {id: 2, value: 'My category'};
|
||||
|
||||
expect(controller.updateStateParams).toHaveBeenCalledWith();
|
||||
|
|
Loading…
Reference in New Issue