2018-08-10 09:40:48 +00:00
|
|
|
|
2018-12-21 19:22:13 +00:00
|
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
2018-08-10 09:40:48 +00:00
|
|
|
|
2018-03-15 13:36:09 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('listPackaging', {
|
|
|
|
description: 'Returns all packages including item',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'filter',
|
2021-10-07 07:57:07 +00:00
|
|
|
type: 'object',
|
2018-03-15 13:36:09 +00:00
|
|
|
required: false,
|
|
|
|
description: 'Filter defining where and paginated data',
|
|
|
|
http: {source: 'query'}
|
|
|
|
}],
|
|
|
|
returns: {
|
2021-10-07 07:57:07 +00:00
|
|
|
type: ['object'],
|
2018-03-15 13:36:09 +00:00
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/listPackaging`,
|
|
|
|
verb: 'get'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
Self.listPackaging = async(filter, options) => {
|
|
|
|
const conn = Self.dataSource.connector;
|
|
|
|
const myOptions = {};
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
|
|
|
const stmt = new ParameterizedSQL(
|
2018-08-17 12:53:25 +00:00
|
|
|
`SELECT name, itemFk, packagingFk
|
|
|
|
FROM (SELECT i.name, i.id itemFk, p.id packagingFk
|
|
|
|
FROM item i
|
2019-03-05 13:59:18 +00:00
|
|
|
JOIN packaging p ON i.id = p.itemFk
|
2019-10-21 07:16:52 +00:00
|
|
|
WHERE i.name <> '' AND p.isPackageReturnable) p`
|
2018-08-10 09:40:48 +00:00
|
|
|
);
|
2018-03-15 13:36:09 +00:00
|
|
|
|
2018-11-07 12:32:09 +00:00
|
|
|
stmt.merge(conn.makeSuffix(filter));
|
2021-10-07 07:57:07 +00:00
|
|
|
|
|
|
|
return conn.executeStmt(stmt, myOptions);
|
2018-03-15 13:36:09 +00:00
|
|
|
};
|
|
|
|
};
|