Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into dev
This commit is contained in:
commit
f586a30a1b
|
@ -177,7 +177,7 @@ export default {
|
||||||
closeItemSummaryPreview: 'vn-item-index [vn-id="preview"] button.close'
|
closeItemSummaryPreview: 'vn-item-index [vn-id="preview"] button.close'
|
||||||
},
|
},
|
||||||
itemCreateView: {
|
itemCreateView: {
|
||||||
name: `${components.vnTextfield}[name="name"]`,
|
temporalName: `${components.vnTextfield}[name="provisionalName"]`,
|
||||||
typeAutocomplete: `vn-autocomplete[field="$ctrl.item.typeFk"]`,
|
typeAutocomplete: `vn-autocomplete[field="$ctrl.item.typeFk"]`,
|
||||||
intrastatAutocomplete: `vn-autocomplete[field="$ctrl.item.intrastatFk"]`,
|
intrastatAutocomplete: `vn-autocomplete[field="$ctrl.item.intrastatFk"]`,
|
||||||
originAutocomplete: `vn-autocomplete[field="$ctrl.item.originFk"]`,
|
originAutocomplete: `vn-autocomplete[field="$ctrl.item.originFk"]`,
|
||||||
|
|
|
@ -49,7 +49,7 @@ describe('Item Create/Clone path', () => {
|
||||||
|
|
||||||
it('should create the Infinity Gauntlet item', async() => {
|
it('should create the Infinity Gauntlet item', async() => {
|
||||||
const result = await nightmare
|
const result = await nightmare
|
||||||
.type(selectors.itemCreateView.name, 'Infinity Gauntlet')
|
.type(selectors.itemCreateView.temporalName, 'Infinity Gauntlet')
|
||||||
.autocompleteSearch(selectors.itemCreateView.typeAutocomplete, 'Crisantemo')
|
.autocompleteSearch(selectors.itemCreateView.typeAutocomplete, 'Crisantemo')
|
||||||
.autocompleteSearch(selectors.itemCreateView.intrastatAutocomplete, 'Coral y materiales similares')
|
.autocompleteSearch(selectors.itemCreateView.intrastatAutocomplete, 'Coral y materiales similares')
|
||||||
.autocompleteSearch(selectors.itemCreateView.originAutocomplete, 'Holand')
|
.autocompleteSearch(selectors.itemCreateView.originAutocomplete, 'Holand')
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
let UserError = require('vn-loopback/util/user-error');
|
||||||
|
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('new', {
|
||||||
|
description: 'Create a new item and returns the new ID',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'params',
|
||||||
|
type: 'object',
|
||||||
|
http: {source: 'body'}
|
||||||
|
}],
|
||||||
|
returns: {
|
||||||
|
type: 'number',
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/new`,
|
||||||
|
verb: 'post'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.new = async params => {
|
||||||
|
let validUpdateParams = [
|
||||||
|
'provisionalName',
|
||||||
|
'typeFk',
|
||||||
|
'intrastatFk',
|
||||||
|
'originFk',
|
||||||
|
'relevancy'
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const key in params) {
|
||||||
|
if (validUpdateParams.indexOf(key) === -1)
|
||||||
|
throw new UserError(`You don't have enough privileges to do that`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let transaction = await Self.beginTransaction({});
|
||||||
|
try {
|
||||||
|
let provisionalName = params.provisionalName;
|
||||||
|
delete params.provisionalName;
|
||||||
|
|
||||||
|
let item = await Self.app.models.Item.create(params, {transaction: transaction});
|
||||||
|
|
||||||
|
let typeTags = await Self.app.models.ItemTypeTag.find({where: {itemTypeFk: item.typeFk}});
|
||||||
|
let query = `SET @isTriggerDisabled = TRUE`;
|
||||||
|
await Self.rawSql(query, null, {transaction: transaction});
|
||||||
|
|
||||||
|
let nameTag = await Self.app.models.Tag.findOne({where: {name: 'Nombre temporal'}});
|
||||||
|
|
||||||
|
let newTags = [];
|
||||||
|
|
||||||
|
newTags.push({itemFk: item.id, tagFk: nameTag.id, value: provisionalName, priority: '2'});
|
||||||
|
typeTags.forEach(typeTag => {
|
||||||
|
newTags.push({itemFk: item.id, tagFk: typeTag.tagFk, value: '', priority: typeTag.priority});
|
||||||
|
});
|
||||||
|
|
||||||
|
await Self.app.models.ItemTag.create(newTags, {transaction: transaction});
|
||||||
|
|
||||||
|
query = `SET @isTriggerDisabled = FALSE`;
|
||||||
|
await Self.rawSql(query, null, {transaction: transaction});
|
||||||
|
|
||||||
|
|
||||||
|
query = `CALL vn.itemRefreshTags(?)`;
|
||||||
|
await Self.rawSql(query, [item.id], {transaction: transaction});
|
||||||
|
await transaction.commit();
|
||||||
|
return item;
|
||||||
|
} catch (e) {
|
||||||
|
await transaction.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,35 @@
|
||||||
|
const app = require(`${serviceRoot}/server/server`);
|
||||||
|
|
||||||
|
describe('item new()', () => {
|
||||||
|
let item;
|
||||||
|
|
||||||
|
afterAll(async() => {
|
||||||
|
await app.models.Item.destroyById(item.id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create a new item, adding the name as a tag', async() => {
|
||||||
|
let itemParams = {
|
||||||
|
intrastatFk: 5080000,
|
||||||
|
originFk: 1,
|
||||||
|
provisionalName: 'planta',
|
||||||
|
typeFk: 2,
|
||||||
|
relevancy: 0
|
||||||
|
};
|
||||||
|
item = await app.models.Item.new(itemParams);
|
||||||
|
let temporalNameTag = await app.models.Tag.findOne({where: {name: 'Nombre temporal'}});
|
||||||
|
|
||||||
|
let temporalName = await app.models.ItemTag.findOne({
|
||||||
|
where: {
|
||||||
|
itemFk: item.id,
|
||||||
|
tagFk: temporalNameTag.id,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
item = await app.models.Item.findById(item.id);
|
||||||
|
|
||||||
|
expect(item.intrastatFk).toEqual(5080000);
|
||||||
|
expect(item.originFk).toEqual(1);
|
||||||
|
expect(item.typeFk).toEqual(2);
|
||||||
|
expect(item.name).toEqual('planta');
|
||||||
|
expect(temporalName.value).toEqual('planta');
|
||||||
|
});
|
||||||
|
});
|
|
@ -13,8 +13,7 @@
|
||||||
"description": "Identifier"
|
"description": "Identifier"
|
||||||
},
|
},
|
||||||
"value": {
|
"value": {
|
||||||
"type": "String",
|
"type": "String"
|
||||||
"required": true
|
|
||||||
},
|
},
|
||||||
"priority": {
|
"priority": {
|
||||||
"type": "Number",
|
"type": "Number",
|
||||||
|
|
|
@ -9,8 +9,8 @@ module.exports = Self => {
|
||||||
require('../methods/item/getSummary')(Self);
|
require('../methods/item/getSummary')(Self);
|
||||||
require('../methods/item/getCard')(Self);
|
require('../methods/item/getCard')(Self);
|
||||||
require('../methods/item/regularize')(Self);
|
require('../methods/item/regularize')(Self);
|
||||||
|
require('../methods/item/new')(Self);
|
||||||
|
|
||||||
Self.validatesPresenceOf('name', {message: 'Cannot be blank'});
|
|
||||||
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});
|
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});
|
||||||
|
|
||||||
Self.observe('before save', async function(ctx) {
|
Self.observe('before save', async function(ctx) {
|
||||||
|
|
|
@ -13,8 +13,7 @@
|
||||||
"description": "Identifier"
|
"description": "Identifier"
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
"type": "String",
|
"type": "String"
|
||||||
"required": true
|
|
||||||
},
|
},
|
||||||
"size": {
|
"size": {
|
||||||
"type": "Number"
|
"type": "Number"
|
||||||
|
@ -22,6 +21,10 @@
|
||||||
"category": {
|
"category": {
|
||||||
"type": "String"
|
"type": "String"
|
||||||
},
|
},
|
||||||
|
"typeFk": {
|
||||||
|
"type": "Number",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
"stems": {
|
"stems": {
|
||||||
"type": "Number"
|
"type": "Number"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<mg-ajax path="/item/api/Items" options="vnPost"></mg-ajax>
|
<mg-ajax path="/item/api/Items/new" options="vnPost"></mg-ajax>
|
||||||
<vn-watcher
|
<vn-watcher
|
||||||
vn-id="watcher"
|
vn-id="watcher"
|
||||||
data="$ctrl.item"
|
data="$ctrl.item"
|
||||||
|
@ -10,7 +10,12 @@
|
||||||
<vn-card pad-large>
|
<vn-card pad-large>
|
||||||
<vn-title>New item</vn-title>
|
<vn-title>New item</vn-title>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield vn-one label="Name" field="$ctrl.item.name" vn-focus></vn-textfield>
|
<vn-textfield
|
||||||
|
vn-one
|
||||||
|
label="Temporal name"
|
||||||
|
field="$ctrl.item.provisionalName"
|
||||||
|
vn-focus>
|
||||||
|
</vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-autocomplete vn-one
|
<vn-autocomplete vn-one
|
||||||
|
|
Loading…
Reference in New Issue