diff --git a/client/route/src/create/create.html b/client/route/src/create/create.html index d1f8d77e9..06049e378 100644 --- a/client/route/src/create/create.html +++ b/client/route/src/create/create.html @@ -20,7 +20,12 @@ - + + + diff --git a/services/auth/server/boot/routes.js b/services/auth/server/boot/routes.js index a2c808860..f29e648f9 100644 --- a/services/auth/server/boot/routes.js +++ b/services/auth/server/boot/routes.js @@ -53,11 +53,11 @@ module.exports = function(app) { loginUrl = applications[apiKey]; - res.send(JSON.stringify({ + res.json({ token: token.id, continue: continueUrl, loginUrl: loginUrl - })); + }); } function findCb(err, instance) { if (err || !instance || instance.password !== md5(password)) { @@ -78,13 +78,14 @@ module.exports = function(app) { } function badLogin() { res.status(401); - res.send(JSON.stringify({ + res.json({ message: 'Login failed' - })); + }); } }); app.get('/logout', function(req, res) { + console.log(req.accessToken); User.logout(req.accessToken.id, () => res.redirect('/')); }); diff --git a/services/mailer/application/auth.js b/services/mailer/application/auth.js index 11f8f0025..4b954f800 100644 --- a/services/mailer/application/auth.js +++ b/services/mailer/application/auth.js @@ -25,17 +25,13 @@ module.exports = { database.pool.query(query, [this.getToken()], (error, result) => { let token = result[0]; - if (error) - return this.response.status(401).send({status: 'REJECT', data: {message: error.code}}); - - if (result.length == 0) - return this.response.status(401).send({status: 'REJECT', data: {message: 'No token found'}}); + if (error || result.length == 0) + return this.response.status(401).send({message: 'Invalid token'}); if (this.isTokenExpired(token.created, token.ttl)) - return this.response.status(401).send({status: 'REJECT', data: {message: 'Token expired'}}); + return this.response.status(401).send({message: 'Token expired'}); this.request.userId = token.userId; - this.next(); }); }, diff --git a/services/mailer/application/locale.js b/services/mailer/application/locale.js index ac2cc8b0c..496d48bb8 100644 --- a/services/mailer/application/locale.js +++ b/services/mailer/application/locale.js @@ -17,12 +17,12 @@ module.exports = { if (error) { fs.stat(defaultLocaleFile, (error, stats) => { if (error) - return cb({status: 'REJECT', data: {message: 'Translation not found for template ' + template + '.'}}); + return cb(new Error('Translation not found for template ' + template)); - cb({status: 'ACCEPT', data: {locale: require(defaultLocaleFile)}}); + cb(null, {locale: require(defaultLocaleFile)}); }); } else { - cb({status: 'ACCEPT', data: {locale: require(localeFile)}}); + cb(null, {locale: require(localeFile)}); } }); }, diff --git a/services/mailer/application/mail.js b/services/mailer/application/mail.js index 878595a5a..5e3e6abb0 100644 --- a/services/mailer/application/mail.js +++ b/services/mailer/application/mail.js @@ -50,12 +50,12 @@ module.exports = { this.log(params.sender, params.recipient, recipient, subject, body, params.message, status); if (error) - return cb({status: 'REJECT', data: {message: 'Email not sent: ' + error}}); + return cb(new Error('Email not sent: ' + error)); if (settings.app().debug) console.log('Mail sent ' + info.messageId + ' [' + info.response + ']'); - cb({status: 'ACCEPT', data: {message: 'Email sent'}}); + cb(); }); }, @@ -66,12 +66,15 @@ module.exports = { * @param {Object} cb - Callback */ sendWithTemplate: function(tplName, params, cb) { - template.get(tplName, params, result => { - if (result.status == 'REJECT') - return cb(result); + template.get(tplName, params, (error, result) => { + if (error) + return cb(error); - this.send(result.data.recipient, result.data.subject, result.data.body, result.data.attachments, params, result => { - cb(result); + this.send(result.recipient, result.subject, result.body, result.attachments, params, error => { + if (error) + return cb(error); + + cb(); }); }); }, diff --git a/services/mailer/application/route/manuscript.js b/services/mailer/application/route/manuscript.js index 1ec5984c1..d2d7392d4 100644 --- a/services/mailer/application/route/manuscript.js +++ b/services/mailer/application/route/manuscript.js @@ -1,17 +1,24 @@ var express = require('express'); var router = new express.Router(); var mail = require('../mail.js'); -var auth = require('../auth.js'); - -// Auth middleware -var requestToken = function(request, response, next) { - auth.init(request, response, next); -}; // Payment method changes -router.post('/payment-update/:clientId', requestToken, function(request, response, next) { - mail.sendWithTemplate('payment-update', {recipient: request.params.clientId}, result => { - return response.json(result); +router.post('/payment-update/:clientId', function(request, response, next) { + mail.sendWithTemplate('payment-update', {recipient: request.params.clientId}, error => { + if (error) + return response.status(400).json({message: error.message}); + + return response.json(); + }); +}); + +// Printer setup +router.post('/printer-setup/:clientId', function(request, response, next) { + mail.sendWithTemplate('printer-setup', {recipient: request.params.clientId}, error => { + if (error) + return response.status(400).json({message: error.message}); + + return response.json(); }); }); diff --git a/services/mailer/application/route/notification.js b/services/mailer/application/route/notification.js index 508aed386..e5d5e4beb 100644 --- a/services/mailer/application/route/notification.js +++ b/services/mailer/application/route/notification.js @@ -3,12 +3,6 @@ var router = new express.Router(); var mail = require('../mail.js'); var database = require('../database.js'); var settings = require('../settings.js'); -var auth = require('../auth.js'); - -// Auth middleware -var requestToken = function(request, response, next) { - auth.init(request, response, next); -}; // Single user notification /* router.post('/:recipient/noticeUserSend', function(request, response) { @@ -71,7 +65,7 @@ var requestToken = function(request, response, next) { }); */ // Send notification to alias solunion on client deactivate -router.post('/client-deactivate/:clientId', requestToken, function(request, response) { +router.post('/client-deactivate/:clientId', function(request, response) { var params = { alias: 'solunion', code: 'clientDeactivate', @@ -80,8 +74,11 @@ router.post('/client-deactivate/:clientId', requestToken, function(request, resp } }; - mail.sendWithTemplate('notification-alias', params, result => { - return response.json(result); + mail.sendWithTemplate('notification-alias', params, error => { + if (error) + response.status(400).json({message: error.message}); + + return response.json(); }); }); diff --git a/services/mailer/application/router.js b/services/mailer/application/router.js index 201548632..b51b8a195 100644 --- a/services/mailer/application/router.js +++ b/services/mailer/application/router.js @@ -4,7 +4,7 @@ var settings = require('./settings.js'); // Mailer default page router.get('/', function(request, response) { - response.send(settings.app().name + ' v' + settings.app().version); + response.json({}); }); // Manuscripts diff --git a/services/mailer/application/template.js b/services/mailer/application/template.js index 4da1d7a80..aebfbfd9f 100644 --- a/services/mailer/application/template.js +++ b/services/mailer/application/template.js @@ -5,13 +5,13 @@ var path = require('path'); var inlineCss = require('inline-css'); module.exports = { - /** - * Obtiene la plantilla. - * @param {String} template - Nombre de la plantilla - * @param {Object} countryCode - Código del idioma - * @param {Object} params - Datos a reemplazar. - * @param {Object} cb - Callback - */ +/** + * Get template. + * @param {String} template - Template name + * @param {Object} countryCode - Language code + * @param {Object} params - Params + * @param {Object} cb - Callback + */ get: function(template, params, cb) { var templatePath = path.join(__dirname, 'template', `${template}`, `index.html`); var classPath = path.join(__dirname, 'template', `${template}`, `${template}.js`); @@ -19,65 +19,68 @@ module.exports = { fs.stat(templatePath, (error, stat) => { if (error) - return cb(null, 'Template ' + template + ' not found'); + return cb(new Error('Template ' + template + ' not found')); let TemplateClass = require(classPath); let instance = new TemplateClass(); let getRenderedStyles = body => { - this.renderStyles(stylePath, body, body => { + this.renderStyles(stylePath, body, (error, body) => { params.subject = params.subject || instance.subject; if (params.subject == undefined) params.subject = body.match(new RegExp('(.*?)', 'i'))[1]; - this.getAttachments(template, body, attachments => { - cb({status: 'ACCEPT', data: {recipient: instance.recipient, subject: params.subject, body: body, attachments: attachments}}); + this.getAttachments(template, body, (error, attachments) => { + if (error) + return cb(error); + + cb(null, {recipient: instance.recipient, subject: params.subject, body: body, attachments: attachments}); }); }); }; let getDataCb = () => { - this.render(templatePath, instance, body => getRenderedStyles(body)); + this.render(templatePath, instance, (error, result) => getRenderedStyles(result)); }; - instance.getData(params, result => { - if (result.status == 'REJECT') - return cb(result); + instance.getData(params, (error, result) => { + if (error) + return cb(error); - locale.load(template, instance.countryCode, result => { - if (result.status == 'REJECT') - return cb(result); + locale.load(template, instance.countryCode, (error, result) => { + if (error) + return cb(error); - instance._ = result.data.locale; - getDataCb(result); + instance._ = result.locale; + getDataCb(null, result); }); }); }); }, - /** - * Renderiza las plantillas - * @param {String} path - Ruta de la plantilla - * @param {Object} data - Listado de parámetros a remplazar - * @param {Object} cb - Callback - */ +/** + * Render template + * @param {String} path - Template path + * @param {Object} data - Params + * @param {Object} cb - Callback + */ render: function(path, data, cb) { fs.readFile(path, 'utf8', function(error, body) { mustache.parse(body); - cb(mustache.render(body, data)); + cb(null, mustache.render(body, data)); }); }, - /** - * Renderiza los estilos de las plantillas. - * @param {String} path - Ruta de la hoja de estilos - * @param {String} body - Html renderizado - * @param {Object} cb - Callback - */ +/** + * Render template style. + * @param {String} path - Stylesheet path + * @param {String} body - Rendered html + * @param {Object} cb - Callback + */ renderStyles: function(path, html, cb) { fs.stat(path, error => { - if (error) return cb(null, 'Template stylesheet not found'); + if (error) return cb(new Error('Template stylesheet not found')); fs.readFile(path, 'utf8', (error, css) => { let style = ''; let body = style + html; @@ -85,42 +88,67 @@ module.exports = { inlineCss(body, options) .then(function(body) { - cb(body); + cb(null, body); }); }); }); }, - /** - * Obtiene todos los ficheros adjuntos de la plantilla - * @param {String} template - Nombre de la plantilla - * @param {String} body - html de la plantilla - * @param {Object} cb - Callback - */ +/** + * Get template attachments + * @param {String} template - Template name + * @param {String} body - template body + * @param {Object} cb - Callback + */ getAttachments: function(template, body, cb) { - var attachments = []; - var tplAttachments = body.match(new RegExp('src="cid:(.*?)"', 'ig')); + let attachments = []; + let tplAttachments = body.match(new RegExp('src="cid:(.*?)"', 'ig')); + // Template default attachments for (var i = 0; i < tplAttachments.length; i++) { - var name = tplAttachments[i].replace('src="cid:', '').replace('"', ''); - var attachmentPath = path.join(__dirname, 'template/default/image', name); + let name = tplAttachments[i].replace('src="cid:', '').replace('"', ''); + let attachmentPath = path.join(__dirname, 'template/default/image', name); attachments.push({filename: name, path: attachmentPath, cid: name}); } - var attachmentsPath = path.join(__dirname, 'template', `${template}`, 'attachment.json'); + // Template attachment files + let attachmentsPath = path.join(__dirname, 'template', `${template}`, 'attachment.json'); fs.stat(attachmentsPath, (error, stats) => { - if (error) return cb(null, 'Could not load attachments from template ' + template); + if (error) + return cb(new Error(`Could not load attachments.js from template ${template}`)); - var attachObj = require(attachmentsPath); + let attachObj = require(attachmentsPath); for (var i = 0; i < attachObj.length; i++) { - var attachmentPath = path.join(__dirname, 'template', `${template}`, 'attachment', attachObj[i]); - attachments.push({filename: attachObj[i], path: attachmentPath, cid: attachObj[i]}); + let filename = attachObj[i]; + let attachmentPath = path.join(__dirname, 'template', `${template}`, 'attachment', filename); + + attachments.push({filename: filename, path: attachmentPath, cid: filename}); } - cb(attachments); + this.checkAttachments(attachments, error => { + if (error) + return cb(error); + cb(null, attachments); + }); }); + }, + +/** + * Check all template attachments + * @param {Object} attachments - Attachments object + * @param {Object} cb - Callback + */ + checkAttachments: function(attachments, cb) { + for (var i = 0; i < attachments.length; i++) { + var attachment = attachments[i]; + fs.stat(attachment.path, error => { + if (error) + return cb(new Error(`Could not load attachment file ${attachment.path}`)); + }); + } + cb(); } }; diff --git a/services/mailer/application/template/UNUSED/printer-setup/printer-setup.js b/services/mailer/application/template/UNUSED/printer-setup/printer-setup.js deleted file mode 100644 index 73fdb89c1..000000000 --- a/services/mailer/application/template/UNUSED/printer-setup/printer-setup.js +++ /dev/null @@ -1,41 +0,0 @@ -var path = require('path'); -var database = require(path.join(__dirname, '../../database.js')); -var format = require(path.join(__dirname, '../../util/format.js')); - -module.exports = class PaymentUpdate { - getData(params, cb) { - let query = `SELECT - pm.id payMethodFk, - pm.name payMethodName, - c.dueDay, - c.iban, - LOWER(ct.code) countryCode, - c.email recipient - FROM client c - JOIN payMethod pm ON pm.id = c.paymentMethodFk - JOIN country ct ON ct.id = c.countryFk - WHERE c.id = ?`; - database.pool.query(query, [params.recipient], (error, result) => { - if (error || result.length == 0) - return cb({status: 'REJECT', data: {message: 'No data found', error: error}}); - - Object.assign(this, result[0]); - cb({status: 'ACCEPT', data: {}}); - }); - } - - get paymentDay() { - if (this.payMethodFk != 5) { - return `
${this._.paymentDay}: ${this.dueDay} ${this._.everyMonth}
`; - } - } - - get paymentAdvice() { - switch (this.payMethodFk) { - case 4: - return `${this._.accountPaymentAdviceBefore} ${format.partialAccountAddress(this.iban)} ${this._.accountPaymentAdviceAfter}`; - case 5: - return this._.cardPaymentAdvice; - } - } -}; diff --git a/services/mailer/application/template/notification-alias/notification-alias.js b/services/mailer/application/template/notification-alias/notification-alias.js index 132d037f4..937e1bf8c 100644 --- a/services/mailer/application/template/notification-alias/notification-alias.js +++ b/services/mailer/application/template/notification-alias/notification-alias.js @@ -12,10 +12,10 @@ module.exports = class NotificationAlias { database.pool.query(query, [params.alias], (error, result) => { if (error || result.length == 0) - return cb({status: 'REJECT', data: {message: 'No data found', error: error}}); + return cb(new Error('No template data found')); Object.assign(this, result[0]); - cb({status: 'ACCEPT', data: {}}); + cb(); }); } diff --git a/services/mailer/application/template/payment-update/payment-update.js b/services/mailer/application/template/payment-update/payment-update.js index 73fdb89c1..0dbb69798 100644 --- a/services/mailer/application/template/payment-update/payment-update.js +++ b/services/mailer/application/template/payment-update/payment-update.js @@ -17,10 +17,10 @@ module.exports = class PaymentUpdate { WHERE c.id = ?`; database.pool.query(query, [params.recipient], (error, result) => { if (error || result.length == 0) - return cb({status: 'REJECT', data: {message: 'No data found', error: error}}); + return cb(new Error('No template data found')); Object.assign(this, result[0]); - cb({status: 'ACCEPT', data: {}}); + cb(); }); } diff --git a/services/mailer/application/template/printer-setup/attachment.json b/services/mailer/application/template/printer-setup/attachment.json new file mode 100644 index 000000000..7294783a8 --- /dev/null +++ b/services/mailer/application/template/printer-setup/attachment.json @@ -0,0 +1 @@ +["model.ezp"] \ No newline at end of file diff --git a/services/mailer/application/template/printer-setup/attachment/model.ezp b/services/mailer/application/template/printer-setup/attachment/model.ezp new file mode 100644 index 000000000..297df3d21 Binary files /dev/null and b/services/mailer/application/template/printer-setup/attachment/model.ezp differ diff --git a/services/mailer/application/template/UNUSED/printer-setup/index.html b/services/mailer/application/template/printer-setup/index.html similarity index 50% rename from services/mailer/application/template/UNUSED/printer-setup/index.html rename to services/mailer/application/template/printer-setup/index.html index caec77e90..86ae8e31a 100644 --- a/services/mailer/application/template/UNUSED/printer-setup/index.html +++ b/services/mailer/application/template/printer-setup/index.html @@ -23,12 +23,49 @@

{{_.dear}},

{{_.bodyDescription}}

+

-

{{_.paymentMethod}}: {{payMethodName}}
- {{{paymentDay}}} + Puede utilizar como guía, el video del montaje del ribon y la cinta https://www.youtube.com/watch?v=qhb0kgQF3o8. + También necesitará el QLabel, el programa para imprimir las cintas.

+ +

Puede descargarlo desde este enlace http://www.godexintl.com/en/product/type/Download/2967

+ +

Utilización de QLabel

+ +

Para utilizar el programa de impresión de cintas siga estos pasos:

+ +
    +
  1. Abra el programa QLabel.
  2. +
  3. Haga click en el icono de la carpeta.
  4. +
  5. Seleccione el archivo plantilla llamado "MODEL.ezp".
  6. +
  7. Haga click ENCIMA DEL TEXTO con el boton secundario del ratÓn.
  8. +
  9. Elija la primera opcion "SETUP".
  10. +
  11. Cambie el texto para imprimir.
  12. +
  13. Haga click en el boton OK.
  14. +
  15. Desplácese con el raton para ver la medida máxima.
  16. +
  17. Haga click ENCIMA DEL TEXTO con el boton secundario del raton.
  18. +
  19. Elija la primera opcion "SETUP PRINTER".
  20. +
  21. Haga click en la primera pestalla "Label Setup".
  22. +
  23. Y modifique la propidad "Paper Height".
  24. +
  25. Haga click en el boton OK.
  26. +
  27. Haga click sobre el icono de la impresora.
  28. +
  29. Haga click en "Print".
  30. +
+ +

¿Necesita ayuda?

+ +

Si necesita ayuda, descárguese nuestro programa de soporte para poder conectarnos remotamente a su pc y hacerle la instalación. + Proporciónenos un horario de contacto para atenderle, y contactaremos con usted.

+ +

Puede descargarse el programa desde este enlace http://soporte.verdnatura.es

+ +

+

Soy tu comercial y mi nombre es: {{_.salesPersonName}}
+
Teléfono y whatsapp: {salesMan_phone}
+
Email: {salesMan_mail}

-

{{paymentAdvice}}

-

{{_.notifyError}}

+ +
diff --git a/services/mailer/application/template/UNUSED/printer-setup/locale/es.json b/services/mailer/application/template/printer-setup/locale/es.json similarity index 60% rename from services/mailer/application/template/UNUSED/printer-setup/locale/es.json rename to services/mailer/application/template/printer-setup/locale/es.json index 144cdc346..a856dd827 100644 --- a/services/mailer/application/template/UNUSED/printer-setup/locale/es.json +++ b/services/mailer/application/template/printer-setup/locale/es.json @@ -1,15 +1,8 @@ { - "subject": "Cambios en las condiciones de pago", - "title": "Cambio en las condiciones", + "subject": "Instalación y configuración de impresora", + "title": "¡GRACIAS POR SU CONFIANZA!", "dear": "Estimado cliente", - "bodyDescription": "Le informamos que han cambiado las condiciones de pago de su cuenta. A continuación le indicamos las nuevas condiciones:", - "paymentMethod": "Método de pago", - "paymentDay": "Día de pago", - "everyMonth": "de cada mes", - "cardPaymentAdvice": "Su modo de pago actual implica que deberá abonar el importe de los pedidos realizados en el mismo día para que se puedan enviar.", - "accountPaymentAdviceBefore": "Su modo de pago actual implica que se le pasará un cargo a la cuenta", - "accountPaymentAdviceAfter": "por el importe pendiente, al vencimiento establecido en las condiciones.", - "notifyError": "En el caso de detectar algún error en los datos indicados o para cualquier aclaración, debe dirigirse a su comercial.", + "bodyDescription": "Siga las intrucciones especificadas en este correo para llevar a cabo la instalación de la impresora.", "actionButton": "Visita nuestra Web", "infoButton": "Ayúdanos a mejorar", "fiscalAddress": "VERDNATURA LEVANTE SL, B97367486 Avda. Espioca, 100, 46460 Silla _ www.verdnatura.es _ clientes@verdnatura.es", diff --git a/services/mailer/application/template/printer-setup/printer-setup.js b/services/mailer/application/template/printer-setup/printer-setup.js new file mode 100644 index 000000000..c8b25ffed --- /dev/null +++ b/services/mailer/application/template/printer-setup/printer-setup.js @@ -0,0 +1,23 @@ +var path = require('path'); +var database = require(path.join(__dirname, '../../database.js')); +var format = require(path.join(__dirname, '../../util/format.js')); + +module.exports = class PaymentUpdate { + getData(params, cb) { + let query = `SELECT + CONCAT(w.name, ' ', w.firstName) salesPersonName, + LOWER(ct.code) countryCode, + c.email recipient + FROM client c + LEFT JOIN worker w ON w.id = c.workerFk + JOIN country ct ON ct.id = c.countryFk + WHERE c.id = ?`; + database.pool.query(query, [params.recipient], (error, result) => { + if (error || result.length == 0) + return cb(new Error('No template data found')); + + Object.assign(this, result[0]); + cb(); + }); + } +}; diff --git a/services/mailer/server.js b/services/mailer/server.js index d58e8eb0e..a8fd68638 100644 --- a/services/mailer/server.js +++ b/services/mailer/server.js @@ -7,11 +7,19 @@ var bodyParser = require('body-parser'); var settings = require('./application/settings.js'); var mail = require('./application/mail.js'); var database = require('./application/database.js'); +var auth = require('./application/auth.js'); // Body parser middleware app.use(bodyParser.json()); app.use(bodyParser.urlencoded({extended: true})); +// Auth middleware +var requestToken = function(request, response, next) { + auth.init(request, response, next); +}; + +app.use(requestToken); + // Load routes app.use('/', require('./application/router.js')); diff --git a/services/route/common/methods/drivers.js b/services/route/common/methods/drivers.js new file mode 100644 index 000000000..bc23f139c --- /dev/null +++ b/services/route/common/methods/drivers.js @@ -0,0 +1,79 @@ +module.exports = (Delivery) => { + Delivery.remoteMethod('activeDrivers', { + description: 'returns actives employees with driver role', + accessType: 'READ', + accepts: [{ + arg: 'filter', + type: 'Object', + required: false, + description: 'Filter defining where and paginated data', + http: {source: 'query'} + }], + returns: { + arg: 'data', + type: 'Employee', + root: true + }, + http: { + path: `/activeDrivers`, + verb: 'get' + } + }); + + Delivery.activeDrivers = (filter, callback) => { + let skip = filter.skip || 0; + let limit = filter.limit || 10; + let where = getCondition(filter.where); + // TODO: change salesPerson role to Driver role when it will be created + let query = `SELECT em.id, em.name, em.surname + FROM Employee em + JOIN Account ac ON em.userFk = ac.id + JOIN Role ON Role.id = ac.roleFK + WHERE ac.active AND Role.\`name\`='salesPerson' ${where} + ORDER BY em.name ASC + LIMIT ${limit} OFFSET ${skip}`; + + Delivery.rawSql(query, [], callback) + .then(response => { + callback(null, formatDriver(response)); + }) + .catch(reject => { + callback(reject, null); + }); + }; + + function getCondition(where) { + let out = []; + if(typeof where === 'object') { + Object.keys(where).forEach((k) => { + let value = where[k]; + if (typeof value === 'number') { + out.push(`em.${k}=${value}`); + } else if (typeof value === 'string') { + out.push(`em.${k}='${value}'`); + } else if (typeof value === 'boolean' || value === null) { + out.push(`em.${k} IS ${String(value).toUpperCase()}`); + } else if (Object.keys(value).length) { + let firstProperty = Object.keys(value)[0]; + out.push(`em.${k} ${firstProperty} '${value[firstProperty]}'`); + } else { + throw new Error ('Error: unexpected type'); + } + }); + } + return out.length ? `AND (${out.join(' AND ')})` : ''; + } + + function formatDriver (response) { + let results = []; + + response.forEach( person => { + results.push({ + id: person.id, + name: `${person.name} ${person.surname}` + }); + }); + + return results; + } +}; \ No newline at end of file diff --git a/services/route/common/methods/filter.js b/services/route/common/methods/filter.js index 22e93afbd..47edb3dcd 100644 --- a/services/route/common/methods/filter.js +++ b/services/route/common/methods/filter.js @@ -16,16 +16,16 @@ module.exports = function(Delivery) { ] }, - skip: (params.page - 1) * params.size, - limit: params.size + skip: (parseInt(params.page, 10) - 1) * parseInt(params.size, 10), + limit: parseInt(params.size, 10) }; } function andWhere(params) { let filters = { where: {}, - skip: (params.page - 1) * params.size, - limit: params.size + skip: (parseInt(params.page, 10) - 1) * parseInt(params.size, 10), + limit: parseInt(params.size, 10) }; delete params.page; diff --git a/services/route/common/models/delivery.js b/services/route/common/models/delivery.js index 04b9610cf..90d8a1600 100644 --- a/services/route/common/models/delivery.js +++ b/services/route/common/models/delivery.js @@ -1,4 +1,5 @@ module.exports = function(Self) { require('../methods/filter.js')(Self); + require('../methods/drivers.js')(Self); };