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',
|
|
|
|
type: 'Object',
|
|
|
|
required: false,
|
|
|
|
description: 'Filter defining where and paginated data',
|
|
|
|
http: {source: 'query'}
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: ["Object"],
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/listPackaging`,
|
|
|
|
verb: 'get'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.listPackaging = async filter => {
|
2018-11-07 12:32:09 +00:00
|
|
|
let conn = Self.dataSource.connector;
|
2018-08-10 09:40:48 +00:00
|
|
|
let 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
|
|
|
|
JOIN packaging p ON i.id = p.itemFk) 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));
|
|
|
|
return conn.executeStmt(stmt);
|
2018-03-15 13:36:09 +00:00
|
|
|
};
|
|
|
|
};
|