Browse Source

Update /search/ route

master
sipp11 9 years ago
parent
commit
6ab15abb07
  1. 28
      api/controllers/FlagController.js
  2. 28
      api/controllers/NationalityController.js
  3. 27
      api/controllers/PrefixController.js
  4. 44
      api/models/Flag.js
  5. 14
      api/models/Nationality.js
  6. 10
      api/models/Prefix.js
  7. 17
      config/connections.js
  8. 5
      config/cors.js
  9. 6
      config/env/development.js
  10. 13
      config/env/development/connections.js
  11. 12
      config/env/production/connections.js
  12. 3
      config/policies.js
  13. 5
      config/routes.js
  14. 3
      package.json

28
api/controllers/FlagController.js

@ -7,5 +7,31 @@
module.exports = {
};
search: function(req, res) {
var word = req.param('query'),
flagQuery = Flag.find();
if (word != undefined)
flagQuery = Flag.find({
where: {
or: [
{english: {contains: word}},
{thai: {contains: word}},
]
},
sort: {
thai: 1,
english: 1
}
});
flagQuery.limit(10).exec(function(err, flags) {
if (err) {
res.send(400);
} else {
res.send(flags);
}
});
}
};

28
api/controllers/NationalityController.js

@ -7,5 +7,31 @@
module.exports = {
};
search: function(req, res) {
var word = req.param('query'),
nationalityQuery = Nationality.find();
if (word != undefined)
nationalityQuery = Nationality.find({
where: {
or: [
{english: {contains: word}},
{thai: {contains: word}},
]
},
sort: {
thai: 1,
english: 1
}
});
nationalityQuery.limit(10).exec(function(err, items) {
if (err) {
res.send(400);
} else {
res.send(items);
}
});
}
};

27
api/controllers/PrefixController.js

@ -7,5 +7,32 @@
module.exports = {
search: function(req, res) {
var word = req.param('query'),
prefixQuery = Prefix.find();
if (word != undefined)
prefixQuery = Prefix.find({
where: {
or: [
{english: {contains: word}},
{thai: {contains: word}},
]
},
sort: {
thai: 1,
english: 1
}
});
prefixQuery.limit(10).exec(function(err, items) {
if (err) {
res.send(400);
} else {
res.send(items);
}
});
}
};

44
api/models/Flag.js

@ -9,6 +9,50 @@ module.exports = {
attributes: {
english: {
type: 'string',
required: true
},
thai: {
type: 'string',
required: true
},
iso2: {
type: 'string',
required: true
},
iso3: {
type: 'string',
required: true
},
continent: {
type: 'string',
required: true
},
phone_code: {
type: 'string'
},
currency: {
type: 'string'
},
capital: {
type: 'string'
},
languages: {
type: 'array'
},
top_level_domain: {
type: 'string'
}
}
};

14
api/models/Nationality.js

@ -9,6 +9,20 @@ module.exports = {
attributes: {
thai: {
type: 'string',
required: true
},
code: {
type: 'string',
required: true
},
english: {
type: 'string'
},
}
};

10
api/models/Prefix.js

@ -9,6 +9,16 @@ module.exports = {
attributes: {
thai: {
type: 'string',
required: true
},
code: {
type: 'string',
required: true
},
}
};

17
config/connections.js

@ -56,14 +56,7 @@ module.exports.connections = {
* Run: npm install sails-mongo *
* *
***************************************************************************/
someMongodbServer: {
adapter: 'sails-mongo',
host: '10hackintosh',
port: 27017,
// user: 'username',
// password: 'password',
// database: 'your_mongo_db_name_here'
},
hackintoshMongo: {
adapter: 'sails-mongo',
host: '10hackintosh.vnll',
@ -72,14 +65,6 @@ module.exports.connections = {
// password: 'password',
database: 'feeder',
},
nj2mongo: {
adapter: 'sails-mongo',
host: 'nj2',
port: 27017,
// user: 'username',
// password: 'password',
database: 'bbSailer',
},
/***************************************************************************
* *

5
config/cors.js

@ -37,7 +37,7 @@ module.exports.cors = {
* *
***************************************************************************/
// allRoutes: false,
allRoutes: true,
/***************************************************************************
* *
@ -47,7 +47,7 @@ module.exports.cors = {
* *
***************************************************************************/
// origin: '*',
origin: '*',
/***************************************************************************
* *
@ -65,6 +65,7 @@ module.exports.cors = {
***************************************************************************/
// methods: 'GET, POST, PUT, DELETE, OPTIONS, HEAD',
methods: 'GET, OPTIONS, HEAD',
/***************************************************************************
* *

6
config/env/development.js vendored

@ -17,8 +17,8 @@ module.exports = {
* environment (see config/connections.js and config/models.js ) *
***************************************************************************/
// models: {
// connection: 'someMongodbServer'
// }
models: {
connection: 'hackintoshMongo'
}
};

13
config/env/development/connections.js vendored

@ -0,0 +1,13 @@
/*module.exports.connections = {
hackintoshMongo: {
adapter: 'sails-mongo',
host: '10hackintosh.vnll',
port: 27017,
// user: 'username',
// password: 'password',
database: 'feeder',
}
};
*/

12
config/env/production/connections.js vendored

@ -0,0 +1,12 @@
module.exports.connections = {
njMongo: {
adapter: 'sails-mongo',
host: 'nj2',
port: 27017,
// user: 'username',
// password: 'password',
database: 'bbSailer',
}
};

3
config/policies.js

@ -31,16 +31,19 @@ module.exports.policies = {
'*': 'sessionAuth',
'index': true,
'find': true,
'search': true,
},
'prefix': {
'*': 'sessionAuth',
'index': true,
'find': true,
'search': true,
},
'flag': {
'*': 'sessionAuth',
'index': true,
'find': true,
'search': true,
},
/***************************************************************************

5
config/routes.js

@ -34,7 +34,7 @@ module.exports.routes = {
'/': {
view: 'homepage'
}
},
/***************************************************************************
* *
@ -45,5 +45,8 @@ module.exports.routes = {
* for configuration options and examples. *
* *
***************************************************************************/
'GET /nationality/search/:query': 'NationalityController.search',
'GET /flag/search/:query': 'FlagController.search',
'GET /prefix/search/:query': 'PrefixController.search',
};

3
package.json

@ -21,7 +21,8 @@
"include-all": "~0.1.3",
"rc": "~0.5.0",
"sails": "~0.11.0",
"sails-disk": "~0.10.0"
"sails-disk": "~0.10.0",
"sails-mongo": "^0.11.2"
},
"scripts": {
"debug": "node debug app.js",

Loading…
Cancel
Save