Browse Source

Update some controller with count

and return structure like DRF
master
sipp11 9 years ago
parent
commit
cc5f7e896b
  1. 12
      api/controllers/FlagController.js
  2. 7
      api/controllers/NationalityController.js
  3. 7
      api/controllers/ObjReferenceController.js
  4. 59
      api/controllers/ObjRevisionController.js
  5. 7
      api/controllers/PrefixController.js
  6. 62
      api/controllers/UserActivityController.js
  7. 20
      config/connections.js
  8. 17
      config/env/development/connections.js
  9. 4
      config/policies.js

12
api/controllers/FlagController.js

@ -9,10 +9,10 @@ module.exports = {
search: function(req, res) { search: function(req, res) {
var word = req.param('query'), var word = req.param('query'),
flagQuery = Flag.find(); query = Flag.find();
if (word != undefined) if (word != undefined)
flagQuery = Flag.find({ query = Flag.find({
where: { where: {
or: [ or: [
{english: {contains: word}}, {english: {contains: word}},
@ -20,13 +20,11 @@ module.exports = {
{iso2: word}, {iso2: word},
] ]
}, },
sort: { sort: { thai: 1, english: 1 }
thai: 1,
english: 1
}
}); });
flagQuery.limit(10).exec(function(err, flags) { page = ((req.query.page != undefined) ? +req.query.page : 1);
query.paginate({page: page, limit: 10}).exec(function(err, items) {
if (err) { if (err) {
res.send(400); res.send(400);
} else { } else {

7
api/controllers/NationalityController.js

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

7
api/controllers/ObjReferenceController.js

@ -9,10 +9,10 @@ module.exports = {
search: function(req, res) { search: function(req, res) {
var word = req.param('query'), var word = req.param('query'),
refQuery = ObjReference.find(); query = ObjReference.find();
if (word != undefined) if (word != undefined)
refQuery = ObjReference.find({ query = ObjReference.find({
where: { where: {
or: [ or: [
{team: word}, {team: word},
@ -26,7 +26,8 @@ module.exports = {
} }
}); });
refQuery.limit(10).exec(function(err, items) { page = ((req.query.page != undefined) ? +req.query.page : 1);
query.paginate({page: page, limit: 10}).exec(function(err, items) {
if (err) { if (err) {
res.send(400); res.send(400);
} else { } else {

59
api/controllers/ObjRevisionController.js

@ -9,10 +9,10 @@ module.exports = {
search: function(req, res) { search: function(req, res) {
var word = req.param('query'), var word = req.param('query'),
revisionQuery = ObjRevision.find(); query = ObjRevision.find();
if (word != undefined) if (word != undefined)
revisionQuery = ObjRevision.find({ query = ObjRevision.find({
where: { where: {
or: [ or: [
{obj: {jarvisId: {contains: word}}}, {obj: {jarvisId: {contains: word}}},
@ -24,7 +24,8 @@ module.exports = {
} }
}); });
revisionQuery.limit(10).exec(function(err, items) { page = ((req.query.page != undefined) ? +req.query.page : 1);
query.paginate({page: page, limit: 10}).exec(function(err, items) {
if (err) { if (err) {
res.send(400); res.send(400);
} else { } else {
@ -35,39 +36,51 @@ module.exports = {
jarvisid: function(req, res) { jarvisid: function(req, res) {
var word = req.param('query'), var word = req.param('query'),
revisionQuery = ObjRevision.find(); _options = {},
_count, query;
if (word != undefined) if (word != undefined)
revisionQuery = ObjRevision.find({ _options['jarvisId'] = word;
jarvisId: word, _options['sort'] = {date: -1};
sort: { date: 1}
});
revisionQuery.limit(10).exec(function(err, items) { query = ObjRevision.find(_options);
if (err) { page = ((req.query.page != undefined) ? +req.query.page : 1);
ObjRevision.count(_options).exec(function(err, total) {
if (err)
res.send(400); res.send(400);
} else {
res.send(items); query.paginate({page: page, limit: 10}).exec(function(err, items) {
} if (err) {
res.send(400);
} else {
res.send({count: total, results: items});
}
});
}); });
}, },
bbapi: function(req, res) { bbapi: function(req, res) {
var word = req.param('query'), var word = req.param('query'),
revisionQuery = ObjRevision.find(); _options = {},
_count, query;
if (word != undefined) if (word != undefined)
revisionQuery = ObjRevision.find({ _options['bbApi'] = word;
bbApi: word, _options['sort'] = {date: -1};
sort: { date: 1}
});
revisionQuery.limit(10).exec(function(err, items) { query = ObjRevision.find(_options);
if (err) { page = ((req.query.page != undefined) ? +req.query.page : 1);
ObjRevision.count(_options).exec(function(err, total) {
if (err)
res.send(400); res.send(400);
} else {
res.send(items); query.paginate({page: page, limit: 10}).exec(function(err, items) {
} if (err) {
res.send(400);
} else {
res.send({count: total, results: items});
}
});
}); });
} }

7
api/controllers/PrefixController.js

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

62
api/controllers/UserActivityController.js

@ -24,7 +24,8 @@ module.exports = {
} }
}); });
refQuery.limit(10).exec(function(err, items) { page = ((req.query.page != undefined) ? +req.query.page : 1);
refQuery.paginate({page: page, limit: 10}).exec(function(err, items) {
if (err) { if (err) {
res.send(400); res.send(400);
} else { } else {
@ -35,46 +36,55 @@ module.exports = {
oneteam: function(req, res) { oneteam: function(req, res) {
var teamQ = req.param('team'), var teamQ = req.param('team'),
refQuery = UserActivity.find(); _options = {},
_count, query;
if (teamQ != undefined) if (teamQ != undefined)
refQuery = UserActivity.find({ _options['team'] = teamQ;
team: teamQ, _options['sort'] = {date: -1};
sort: {
date: -1
}
});
refQuery.limit(10).exec(function(err, items) { query = UserActivity.find(_options);
if (err) { page = ((req.query.page != undefined) ? +req.query.page : 1);
UserActivity.count(_options).exec(function(err, total) {
if (err)
res.send(400); res.send(400);
} else {
res.send(items); query.paginate({page: page, limit: 10}).exec(function(err, items) {
} if (err) {
res.send(400);
} else {
res.send({count: total, results: items});
}
});
}); });
}, },
oneuser: function(req, res) { oneuser: function(req, res) {
var teamQ = req.param('team'), var teamQ = req.param('team'),
usernameQ = req.param('username'), usernameQ = req.param('username'),
refQuery = UserActivity.find(); _options = {},
_count, query;
if ((teamQ != undefined) && (usernameQ != undefined)) if ((teamQ != undefined) && (usernameQ != undefined))
refQuery = UserActivity.find({ _options = {team: teamQ, username: usernameQ};
team: teamQ, _options['sort'] = {date: -1};
username: usernameQ,
sort: {
date: -1
}
});
refQuery.limit(10).exec(function(err, items) { query = UserActivity.find(_options);
if (err) { page = ((req.query.page != undefined) ? +req.query.page : 1);
UserActivity.count(_options).exec(function(err, total) {
if (err)
res.send(400); res.send(400);
} else {
res.send(items); query.paginate({page: page, limit: 10}).exec(function(err, items) {
} if (err) {
res.send(400);
} else {
res.send({count: total, results: items});
}
});
}); });
} }

20
config/connections.js

@ -56,23 +56,9 @@ module.exports.connections = {
* Run: npm install sails-mongo * * Run: npm install sails-mongo *
* * * *
***************************************************************************/ ***************************************************************************/
// someMongoDBServer: {
hackintoshMongo: { // adapter: 'sails-mongo',
adapter: 'sails-mongo', // },
host: '10hackintosh',
port: 27017,
// user: 'username',
// password: 'password',
database: 'sails',
},
jarvisBlackboard: {
adapter: 'sails-mongo',
host: '10hackintosh',
port: 27017,
// user: 'username',
// password: 'password',
database: 'jarvis-bb',
},
/*************************************************************************** /***************************************************************************
* * * *
* PostgreSQL is another officially supported relational database. * * PostgreSQL is another officially supported relational database. *

17
config/env/development/connections.js vendored

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

4
config/policies.js

@ -47,12 +47,16 @@ module.exports.policies = {
}, },
'objrevision': { 'objrevision': {
'*': 'sessionAuth', '*': 'sessionAuth',
'index': true,
'find': true,
'search': true, 'search': true,
'jarvisid': true, 'jarvisid': true,
'bbapi': true, 'bbapi': true,
}, },
'objreference': { 'objreference': {
'*': 'sessionAuth', '*': 'sessionAuth',
'index': true,
'find': true,
'search': true, 'search': true,
}, },
'useractivity': { 'useractivity': {

Loading…
Cancel
Save