fix: refs #7524 backSuppliersPackaging
gitea/salix/pipeline/pr-master This commit looks good
Details
gitea/salix/pipeline/pr-master This commit looks good
Details
This commit is contained in:
parent
7e27026cbc
commit
52e8bac168
|
@ -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({
|
||||||
|
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());
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -12,6 +12,7 @@ module.exports = Self => {
|
||||||
require('../methods/supplier/campaignMetricsEmail')(Self);
|
require('../methods/supplier/campaignMetricsEmail')(Self);
|
||||||
require('../methods/supplier/newSupplier')(Self);
|
require('../methods/supplier/newSupplier')(Self);
|
||||||
require('../methods/supplier/getItemsPackaging')(Self);
|
require('../methods/supplier/getItemsPackaging')(Self);
|
||||||
|
require('../methods/supplier/getWithPackaging')(Self);
|
||||||
|
|
||||||
Self.validatesPresenceOf('name', {
|
Self.validatesPresenceOf('name', {
|
||||||
message: 'The social name cannot be empty'
|
message: 'The social name cannot be empty'
|
||||||
|
|
Loading…
Reference in New Issue