Merge branch 'dev' of https://git.verdnatura.es/salix into dev
This commit is contained in:
commit
834d779154
|
@ -1,7 +1,7 @@
|
|||
<vn-crud-model
|
||||
vn-id="model"
|
||||
url="item/api/Items/getDiary"
|
||||
filter="::$ctrl.filter"
|
||||
filter="$ctrl.filter"
|
||||
data="sales">
|
||||
</vn-crud-model>
|
||||
<vn-vertical>
|
||||
|
|
|
@ -10,12 +10,11 @@ class Controller {
|
|||
this.$window = $window;
|
||||
this.$translate = $translate;
|
||||
}
|
||||
/*
|
||||
$postLink() {
|
||||
if (this.item)
|
||||
this.filterBuilder();
|
||||
|
||||
get item() {
|
||||
return this._item;
|
||||
}
|
||||
*/
|
||||
|
||||
set item(value) {
|
||||
this._item = value;
|
||||
|
||||
|
@ -23,14 +22,12 @@ class Controller {
|
|||
where: {itemFk: this.$stateParams.id}
|
||||
};
|
||||
|
||||
this.$scope.$$postDigest(() => {
|
||||
if (this.$stateParams.warehouseFk)
|
||||
this.warehouseFk = this.$stateParams.warehouseFk;
|
||||
else if (value)
|
||||
this.warehouseFk = value.itemType.warehouseFk;
|
||||
}
|
||||
|
||||
get item() {
|
||||
return this._item;
|
||||
});
|
||||
}
|
||||
|
||||
set warehouseFk(value) {
|
||||
|
@ -41,6 +38,7 @@ class Controller {
|
|||
});
|
||||
|
||||
this.filter.where.warehouseFk = value;
|
||||
this.$scope.model.refresh();
|
||||
}
|
||||
|
||||
get warehouseFk() {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import './index.js';
|
||||
import {crudModel} from '../../../helpers/crudModelHelper';
|
||||
|
||||
describe('Item', () => {
|
||||
describe('Component vnItemDiary', () => {
|
||||
|
@ -20,7 +21,7 @@ describe('Item', () => {
|
|||
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||
$scope = $rootScope.$new();
|
||||
controller = $componentController('vnItemDiary', {$scope: $scope, $stateParams});
|
||||
controller.$scope.model = {};
|
||||
controller.$scope.model = crudModel;
|
||||
}));
|
||||
|
||||
describe('isToday()', () => {
|
||||
|
@ -75,16 +76,24 @@ describe('Item', () => {
|
|||
|
||||
describe('set item()', () => {
|
||||
it(`should set warehouseFk property based on itemType warehouseFk`, () => {
|
||||
spyOn(controller.$scope, '$$postDigest').and.callThrough();
|
||||
controller.item = {id: 1, itemType: {warehouseFk: 1}};
|
||||
|
||||
expect(controller.$scope.$$postDigest).toHaveBeenCalledWith(jasmine.any(Function));
|
||||
$scope.$digest();
|
||||
|
||||
expect(controller.warehouseFk).toEqual(1);
|
||||
expect(controller.item.id).toEqual(1);
|
||||
});
|
||||
|
||||
it(`should set warehouseFk property based on url query warehouseFk`, () => {
|
||||
spyOn(controller.$scope, '$$postDigest').and.callThrough();
|
||||
controller.$stateParams.warehouseFk = 4;
|
||||
controller.item = {id: 1, itemType: {warehouseFk: 1}};
|
||||
|
||||
expect(controller.$scope.$$postDigest).toHaveBeenCalledWith(jasmine.any(Function));
|
||||
$scope.$digest();
|
||||
|
||||
expect(controller.warehouseFk).toEqual(4);
|
||||
expect(controller.item.id).toEqual(1);
|
||||
});
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<vn-title>Niches</vn-title>
|
||||
<vn-horizontal ng-repeat="niche in niches track by $index">
|
||||
<vn-autocomplete
|
||||
disabled="niche.id != null"
|
||||
|
||||
url="/item/api/Warehouses"
|
||||
show-field="name"
|
||||
value-field="id"
|
||||
|
|
|
@ -12,6 +12,11 @@
|
|||
data="itemTags"
|
||||
form="form">
|
||||
</vn-watcher>
|
||||
<vn-crud-model
|
||||
url="/item/api/Tags"
|
||||
fields="['id','name','isFree', 'sourceTable']"
|
||||
data="tags">
|
||||
</vn-crud-model>
|
||||
<form name="form" ng-submit="$ctrl.onSubmit()">
|
||||
<vn-card pad-large>
|
||||
<vn-title>Tags</vn-title>
|
||||
|
@ -20,14 +25,12 @@
|
|||
vn-id="tag"
|
||||
vn-one
|
||||
field="itemTag.tagFk"
|
||||
url="/item/api/Tags"
|
||||
select-fields="['id','name','isFree']"
|
||||
data="tags"
|
||||
show-field="name"
|
||||
label="Tag"
|
||||
on-change="itemTag.value = null"
|
||||
vn-acl="buyer"
|
||||
vn-focus
|
||||
disabled="itemTag.id != null">
|
||||
vn-focus>
|
||||
</vn-autocomplete>
|
||||
<vn-textfield
|
||||
ng-show="tag.selection.isFree || tag.selection.isFree == undefined"
|
||||
|
|
|
@ -65,10 +65,10 @@ describe('Item', () => {
|
|||
.click(selectors.itemBasicData.basicDataButton)
|
||||
.wait(selectors.itemBasicData.nameInput)
|
||||
.click(selectors.itemTags.tagsButton)
|
||||
.waitForTextInInput(selectors.itemTags.firstTagSelect, 'Ancho de la base')
|
||||
.waitForTextInInput(selectors.itemTags.firstTagSelect, 'Diámetro')
|
||||
.getInputValue(selectors.itemTags.firstTagSelect)
|
||||
.then(result => {
|
||||
expect(result).toEqual('Ancho de la base');
|
||||
expect(result).toEqual('Diámetro');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -1,23 +1,9 @@
|
|||
const UserError = require('vn-loopback/common/helpers').UserError;
|
||||
|
||||
module.exports = Self => {
|
||||
/* Self.validateAsync('warehouseFk', validateWarehouseUniqueness, {
|
||||
message: `The warehouse can't be repeated`
|
||||
Self.rewriteDbError(function(err) {
|
||||
if (err.code === 'ER_DUP_ENTRY')
|
||||
return new UserError(`The warehouse can't be repeated`);
|
||||
return err;
|
||||
});
|
||||
|
||||
async function validateWarehouseUniqueness(err, done) {
|
||||
let where = {
|
||||
itemFk: this.itemFk,
|
||||
warehouseFk: this.warehouseFk
|
||||
};
|
||||
|
||||
if (this.id != null)
|
||||
where.id = {neq: this.id};
|
||||
|
||||
let warehouseExists = await Self.findOne({where: where});
|
||||
console.log(warehouseExists);
|
||||
|
||||
if (warehouseExists)
|
||||
err();
|
||||
|
||||
done();
|
||||
} */
|
||||
};
|
||||
|
|
|
@ -47,5 +47,7 @@
|
|||
"The warehouse can't be repeated": "El almacén no puede repetirse",
|
||||
"The tag can't be repeated": "El tag no puede repetirse",
|
||||
"The observation type can't be repeated": "El tipo de observación no puede repetirse",
|
||||
"A claim with that sale already exists": "Ya existe una reclamación para esta línea"
|
||||
"A claim with that sale already exists": "Ya existe una reclamación para esta línea",
|
||||
"asdas": "asdas",
|
||||
"Duplicated warehouse": "Duplicated warehouse"
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
module.exports = Self => {
|
||||
Self.rewriteDbError = function(replaceErrFunc) {
|
||||
this.once('attached', () => {
|
||||
let realUpsert = this.upsert;
|
||||
this.upsert = async(data, options, cb) => {
|
||||
if (options instanceof Function) {
|
||||
cb = options;
|
||||
options = null;
|
||||
}
|
||||
|
||||
try {
|
||||
await realUpsert.call(this, data, options);
|
||||
if (cb) cb();
|
||||
} catch (err) {
|
||||
let myErr = replaceErr(err, replaceErrFunc);
|
||||
if (cb)
|
||||
cb(myErr);
|
||||
else
|
||||
throw myErr;
|
||||
}
|
||||
};
|
||||
|
||||
let realCreate = this.create;
|
||||
this.create = async(data, options, cb) => {
|
||||
if (options instanceof Function) {
|
||||
cb = options;
|
||||
options = null;
|
||||
}
|
||||
|
||||
try {
|
||||
await realCreate.call(this, data, options);
|
||||
if (cb) cb();
|
||||
} catch (err) {
|
||||
let myErr = replaceErr(err, replaceErrFunc);
|
||||
if (cb)
|
||||
cb(myErr);
|
||||
else
|
||||
throw myErr;
|
||||
}
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
function replaceErr(err, replaceErrFunc) {
|
||||
if (Array.isArray(err)) {
|
||||
let errs = [];
|
||||
for (let e of err)
|
||||
errs.push(replaceErrFunc(e));
|
||||
return errs;
|
||||
}
|
||||
return replaceErrFunc(err);
|
||||
}
|
||||
};
|
|
@ -0,0 +1,19 @@
|
|||
const app = require('../../../../../item/server/server');
|
||||
|
||||
describe('Model rewriteDbError()', () => {
|
||||
it('should extend rewriteDbError properties to any model passed', () => {
|
||||
let exampleModel = app.models.ItemNiche;
|
||||
|
||||
expect(exampleModel.rewriteDbError).toBeDefined();
|
||||
});
|
||||
|
||||
it('should handle a duplicated warehouse error', async() => {
|
||||
let itemNiche = {itemFk: 1, warehouseFK: 1, code: 'A1'};
|
||||
let error;
|
||||
await app.models.ItemNiche.create(itemNiche).catch(e => {
|
||||
error = e;
|
||||
}).finally(() => {
|
||||
expect(error.message).toEqual(`The warehouse can't be repeated`);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,21 +1,11 @@
|
|||
let UserError = require('../helpers').UserError;
|
||||
|
||||
module.exports = Self => {
|
||||
require('../methods/item-tag/filterItemTags')(Self);
|
||||
|
||||
/* Self.validateAsync('tagFk', validateTagUniqueness, {
|
||||
message: `The tag can't be repeated`
|
||||
Self.rewriteDbError(function(err) {
|
||||
if (err.code === 'ER_DUP_ENTRY')
|
||||
return new UserError(`The tag can't be repeated`);
|
||||
return err;
|
||||
});
|
||||
|
||||
async function validateTagUniqueness(err, done) {
|
||||
let tagExists = await Self.findOne({
|
||||
where: {
|
||||
itemFk: this.itemFk,
|
||||
tagFk: this.tagFk
|
||||
}
|
||||
});
|
||||
|
||||
if (tagExists)
|
||||
err();
|
||||
|
||||
done();
|
||||
} */
|
||||
};
|
||||
|
|
|
@ -155,7 +155,7 @@ module.exports = function(Self) {
|
|||
});
|
||||
await Promise.all(promises);
|
||||
} catch (error) {
|
||||
throw error[0];
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
if (actions.create && actions.create.length) {
|
||||
|
@ -258,4 +258,5 @@ module.exports = function(Self) {
|
|||
|
||||
require('../methods/vn-model/installMethod')(Self);
|
||||
require('../methods/vn-model/validateBinded')(Self);
|
||||
require('../methods/vn-model/rewriteDbError')(Self);
|
||||
};
|
||||
|
|
|
@ -1,19 +1,9 @@
|
|||
module.exports = function(Self) {
|
||||
/* Self.validateAsync('observationTypeFk', validateObservationUniqueness, {
|
||||
message: `The observation type can't be repeated`
|
||||
const UserError = require('vn-loopback/common/helpers').UserError;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.rewriteDbError(function(err) {
|
||||
if (err.code === 'ER_DUP_ENTRY')
|
||||
return new UserError(`The observation type can't be repeated`);
|
||||
return err;
|
||||
});
|
||||
|
||||
async function validateObservationUniqueness(err, done) {
|
||||
let observationExists = await Self.findOne({
|
||||
where: {
|
||||
ticketFk: this.ticketFk,
|
||||
observationTypeFk: this.observationTypeFk
|
||||
}
|
||||
});
|
||||
|
||||
if (observationExists)
|
||||
err();
|
||||
|
||||
done();
|
||||
} */
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue