fix: refs #7524 backSuppliersPackaging #3074

Merged
sergiodt merged 3 commits from 7524-WhereWithoutLimit into master 2024-10-07 10:47:15 +00:00
3 changed files with 73 additions and 0 deletions
Showing only changes of commit 52e8bac168 - Show all commits

View File

@ -0,0 +1,40 @@
module.exports = Self => {
Self.remoteMethod('getWithPackaging', {
description: 'Returns the list of suppliers with an entry of type packaging',
accessType: 'READ',
returns: {
type: 'object',
root: true
},
http: {
path: `/getWithPackaging`,
verb: 'GET'
},
nolimit: true
});
Self.getWithPackaging = async options => {
const models = Self.app.models;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const entries = await models.Entry.find({
Review

ací en els que hagen tingut entries en el últim any hi ha suficient, si no tindrem sempre proveedors obsolets

ací en els que hagen tingut entries en el últim any hi ha suficient, si no tindrem sempre proveedors obsolets
Review

Modificat

Modificat
where: {typeFk: 'packaging'},
include: {
relation: 'supplier',
scope: {
fields: ['id', 'name']
}
},
fields: {supplierFk: true}
}, myOptions);
const result = entries.map(item => ({
id: item.supplier().id,
name: item.supplier().name
}));
return Array.from(new Map(result.map(entry => [entry.id, entry])).values());
};
};

View File

@ -0,0 +1,32 @@
const {models} = require('vn-loopback/server/server');
describe('Supplier getWithPackaging()', () => {
it('should return a list of suppliers with an entry of type packaging', async() => {
const typeFk = 'packaging';
const tx = await models.Supplier.beginTransaction({});
const myOptions = {transaction: tx};
try {
const entry = await models.Entry.findOne(
{
where: {
id: 1
},
myOptions
});
await entry.updateAttributes({
typeFk: typeFk,
});
const result = await models.Supplier.getWithPackaging(myOptions);
expect(result.length).toEqual(1);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -12,6 +12,7 @@ module.exports = Self => {
require('../methods/supplier/campaignMetricsEmail')(Self);
require('../methods/supplier/newSupplier')(Self);
require('../methods/supplier/getItemsPackaging')(Self);
require('../methods/supplier/getWithPackaging')(Self);
Self.validatesPresenceOf('name', {
message: 'The social name cannot be empty'