From cd20dd0740d05bdb92f67ca81fc85b349882177e Mon Sep 17 00:00:00 2001
From: Vytor Calixto <vytorcalixto@gmail.com>
Date: Wed, 18 Jan 2017 10:09:48 -0200
Subject: [PATCH] Add search to city route

Related: simcaq/SCRUM#210
---
 src/libs/routes/city.js | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/libs/routes/city.js b/src/libs/routes/city.js
index 41b22a66..3214f7f9 100644
--- a/src/libs/routes/city.js
+++ b/src/libs/routes/city.js
@@ -43,7 +43,20 @@ rqf.addField({
         foreign: 'fk_estado_id',
         foreignTable: 'municipio'
     }
-});
+}).addField({
+    name: 'search',
+    field: false,
+    where: true
+}).addValueToField({
+    name: 'name',
+    table: 'municipio',
+    tableField: 'nome',
+    where: {
+        relation: 'LIKE',
+        type: 'string',
+        field: 'nome'
+    }
+}, 'search');;
 
 // Return all cities
 cityApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
@@ -51,4 +64,4 @@ cityApp.get('/', rqf.parse(), rqf.build(), (req, res, next) => {
     next();
 }, query, response('city'));
 
-module.exports = cityApp;
\ No newline at end of file
+module.exports = cityApp;
-- 
GitLab