salix/services/ticket/common/methods/packaging/listPackaging.js

37 lines
1.0 KiB
JavaScript

const ParameterizedSQL = require('vn-loopback/node_modules/loopback-connector').ParameterizedSQL;
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 => {
let stmt = new ParameterizedSQL(
`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`
);
stmt.merge(Self.buildSuffix(filter));
return Self.rawStmt(stmt);
};
};