module.exports = Self => { Self.remoteMethod('crud', { description: 'Client contact crud', accepts: [{ arg: 'data', type: 'object', http: {source: 'body'} }], returns: { root: true, type: 'boolean' }, http: { verb: 'post', path: '/crud' } }); Self.crud = async data => { let models = Self.app.models; await Promise.all(data.delete.map(contactId => { return models.ClientContact.destroyById(contactId); })); let upsert = data.update.concat(data.create); await Promise.all(upsert.map(contact => { return models.ClientContact.upsert(contact); })); }; };