module.exports = Self => { Self.remoteMethod('summary', { description: 'Returns the information of a route showed in the route summary', accessType: 'READ', accepts: [{ arg: 'id', type: 'number', required: true, description: 'The route id', http: {source: 'path'} }], returns: { type: 'object', root: true }, http: { path: `/:id/summary`, verb: 'GET' } }); Self.summary = async id => { let summary = {}; let filter = { where: {id: id}, include: [ { relation: 'agencyMode', scope: { fields: ['id', 'name'] } }, { relation: 'worker', scope: { fields: ['id'], include: [ { relation: 'user', scope: { fields: ['id', 'name'] } } ] } }, { relation: 'vehicle', scope: { fields: ['id', 'm3', 'numberPlate'] } }, ] }; summary.route = await Self.app.models.Route.findOne(filter); summary.tickets = await Self.app.models.Route.getTickets({id: id, order: 'priority ASC'}); return summary; }; };