4492-item.create-same-as-item.isLaid #1125

Merged
pau merged 10 commits from 4492-item.create-same-as-item.isLaid into dev 2022-11-16 08:04:56 +00:00
3 changed files with 23 additions and 0 deletions
Showing only changes of commit ff5e601a1e - Show all commits

View File

@ -51,6 +51,16 @@ module.exports = Self => {
const item = await models.Item.create(params, myOptions);
// set the item.isLaid to be the same as itemType.isLaid (itemType comes from item.typeFk)
pau marked this conversation as resolved Outdated
Outdated
Review

Mover esta linea arriba del create para poder crearlo directamente con el valor de la propiedad isLaid

Mover esta linea arriba del create para poder crearlo directamente con el valor de la propiedad isLaid
const itemType = await models.ItemType.findById(item.typeFk, myOptions);
// Update the item with the new isLaid value
pau marked this conversation as resolved Outdated
Outdated
Review

Evitar el save para no hacer dos consultas a la bd

Evitar el save para no hacer dos consultas a la bd
item.isLaid = itemType.isLaid;
await item.save(myOptions);
const typeTags = await models.ItemTypeTag.find({
where: {itemTypeFk: item.typeFk}
}, myOptions);

View File

@ -15,6 +15,11 @@ describe('item new()', () => {
};
let item = await models.Item.new(itemParams, options);
let itemType = await models.ItemType.findById(item.typeFk, options);
item.isLaid = itemType.isLaid;
const temporalNameTag = await models.Tag.findOne({where: {name: 'Nombre temporal'}}, options);
const temporalName = await models.ItemTag.findOne({
@ -26,9 +31,14 @@ describe('item new()', () => {
item = await models.Item.findById(item.id, null, options);
itemType = await models.ItemType.findById(item.typeFk, options);
item.isLaid = itemType.isLaid;
expect(item.intrastatFk).toEqual(5080000);
expect(item.originFk).toEqual(1);
expect(item.typeFk).toEqual(2);
expect(item.isLaid).toEqual(0);
expect(item.name).toEqual('planta');
expect(temporalName.value).toEqual('planta');

View File

@ -26,6 +26,9 @@
},
"isUnconventionalSize": {
"type": "number"
},
"isLaid": {
"type": "number"
pau marked this conversation as resolved Outdated
Outdated
Review

boolean

boolean
}
},
"relations": {