34 lines
848 B
JavaScript
34 lines
848 B
JavaScript
module.exports = Self => {
|
|
Self.remoteMethodCtx('newSupplier', {
|
|
description: 'Creates a new supplier and returns it',
|
|
accessType: 'WRITE',
|
|
accepts: [{
|
|
arg: 'name',
|
|
type: 'string'
|
|
}],
|
|
returns: {
|
|
type: 'string',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/newSupplier`,
|
|
verb: 'POST'
|
|
}
|
|
});
|
|
|
|
Self.newSupplier = async(ctx, options) => {
|
|
const models = Self.app.models;
|
|
const args = ctx.args;
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
delete args.ctx;
|
|
const data = {...args, ...{nickname: args.name}};
|
|
const supplier = await models.Supplier.create(data, myOptions);
|
|
|
|
return supplier;
|
|
};
|
|
};
|