53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
|
module.exports = Self => {
|
||
|
Self.remoteMethod('getStockBought', {
|
||
|
description: 'Returns the stock bought for a given date',
|
||
|
accessType: 'READ',
|
||
|
accepts: [{
|
||
|
arg: 'dated',
|
||
|
type: 'date',
|
||
|
description: 'The date to filter',
|
||
|
}
|
||
|
],
|
||
|
returns: {
|
||
|
type: ['object'],
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/getStockBought`,
|
||
|
verb: 'GET'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.getStockBought = async(dated = Date.vnNew()) => {
|
||
|
const models = Self.app.models;
|
||
|
const today = Date.vnNew();
|
||
|
dated.setHours(0, 0, 0, 0);
|
||
|
today.setHours(0, 0, 0, 0);
|
||
|
|
||
|
if (dated.getTime() === today.getTime())
|
||
|
await models.StockBought.rawSql(`CALL vn.stockBought_calculate()`);
|
||
|
|
||
|
return models.StockBought.find(
|
||
|
{
|
||
|
where: {
|
||
|
dated: dated
|
||
|
},
|
||
|
include: [
|
||
|
{
|
||
|
relation: 'worker',
|
||
|
scope: {
|
||
|
include: [
|
||
|
{
|
||
|
relation: 'user',
|
||
|
scope: {
|
||
|
fields: ['id', 'name']
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
});
|
||
|
};
|
||
|
};
|