salix/services/loopback/common/methods/order/isEditable.js

31 lines
773 B
JavaScript
Raw Normal View History

2018-08-07 13:48:55 +00:00
module.exports = Self => {
Self.remoteMethod('isEditable', {
description: 'Check if an order is editable',
accessType: 'READ',
accepts: [{
arg: 'orderId',
type: 'number',
required: true,
description: 'orderId',
http: {source: 'path'}
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:orderId/isEditable`,
verb: 'get'
}
});
Self.isEditable = async orderId => {
let exists = await Self.app.models.Order.findOne({where: {id: orderId}, fields: ['isConfirmed']});
if (!exists || exists.isConfirmed === 1)
2018-09-17 12:30:39 +00:00
return false;
return true;
2018-08-07 13:48:55 +00:00
};
};