51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
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, options) => {
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
const exists = await Self.app.models.Order.findOne({
|
|
where: {id: orderId},
|
|
fields: ['isConfirmed', 'clientFk'],
|
|
include: [
|
|
{relation: 'client',
|
|
scope: {
|
|
include: {
|
|
relation: 'type'
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}, myOptions);
|
|
|
|
if (exists && exists.client().type().code !== 'normal')
|
|
return true;
|
|
|
|
if (!exists || exists.isConfirmed === 1)
|
|
return false;
|
|
|
|
return true;
|
|
};
|
|
};
|