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) {
var word = req.param('query'),
flagQuery = Flag.find();
query = Flag.find();
if (word != undefined)
flagQuery = Flag.find({
query = Flag.find({
where: {
or: [
{english: {contains: word}},
@ -20,13 +20,11 @@ module.exports = {
{iso2: word},
]
},
sort: {
thai: 1,
english: 1
}
sort: { 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) {
res.send(400);
} else {

7
api/controllers/NationalityController.js

@ -9,10 +9,10 @@ module.exports = {
search: function(req, res) {
var word = req.param('query'),
nationalityQuery = Nationality.find();
query = Nationality.find();
if (word != undefined)
nationalityQuery = Nationality.find({
query = Nationality.find({
where: {
or: [
{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) {
res.send(400);
} else {

7
api/controllers/ObjReferenceController.js

@ -9,10 +9,10 @@ module.exports = {
search: function(req, res) {
var word = req.param('query'),
refQuery = ObjReference.find();
query = ObjReference.find();
if (word != undefined)
refQuery = ObjReference.find({
query = ObjReference.find({
where: {
or: [
{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) {
res.send(400);
} else {

59
api/controllers/ObjRevisionController.js

@ -9,10 +9,10 @@ module.exports = {
search: function(req, res) {
var word = req.param('query'),
revisionQuery = ObjRevision.find();
query = ObjRevision.find();
if (word != undefined)
revisionQuery = ObjRevision.find({
query = ObjRevision.find({
where: {
or: [
{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) {
res.send(400);
} else {
@ -35,39 +36,51 @@ module.exports = {
jarvisid: function(req, res) {
var word = req.param('query'),
revisionQuery = ObjRevision.find();
_options = {},
_count, query;
if (word != undefined)
revisionQuery = ObjRevision.find({
jarvisId: word,
sort: { date: 1}
});
_options['jarvisId'] = word;
_options['sort'] = {date: -1};
revisionQuery.limit(10).exec(function(err, items) {
if (err) {
query = ObjRevision.find(_options);
page = ((req.query.page != undefined) ? +req.query.page : 1);
ObjRevision.count(_options).exec(function(err, total) {
if (err)
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) {
var word = req.param('query'),
revisionQuery = ObjRevision.find();
_options = {},
_count, query;
if (word != undefined)
revisionQuery = ObjRevision.find({
bbApi: word,
sort: { date: 1}
});
_options['bbApi'] = word;
_options['sort'] = {date: -1};
revisionQuery.limit(10).exec(function(err, items) {
if (err) {
query = ObjRevision.find(_options);
page = ((req.query.page != undefined) ? +req.query.page : 1);
ObjRevision.count(_options).exec(function(err, total) {
if (err)
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) {
var word = req.param('query'),
prefixQuery = Prefix.find();
query = Prefix.find();
if (word != undefined)
prefixQuery = Prefix.find({
query = Prefix.find({
where: {
or: [
{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) {
res.send(400);
} 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) {
res.send(400);
} else {
@ -35,46 +36,55 @@ module.exports = {
oneteam: function(req, res) {
var teamQ = req.param('team'),
refQuery = UserActivity.find();
_options = {},
_count, query;
if (teamQ != undefined)
refQuery = UserActivity.find({
team: teamQ,
sort: {
date: -1
}
});
_options['team'] = teamQ;
_options['sort'] = {date: -1};
refQuery.limit(10).exec(function(err, items) {
if (err) {
query = UserActivity.find(_options);
page = ((req.query.page != undefined) ? +req.query.page : 1);
UserActivity.count(_options).exec(function(err, total) {
if (err)
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) {
var teamQ = req.param('team'),
usernameQ = req.param('username'),
refQuery = UserActivity.find();
_options = {},
_count, query;
if ((teamQ != undefined) && (usernameQ != undefined))
refQuery = UserActivity.find({
team: teamQ,
username: usernameQ,
sort: {
date: -1
}
});
_options = {team: teamQ, username: usernameQ};
_options['sort'] = {date: -1};
refQuery.limit(10).exec(function(err, items) {
if (err) {
query = UserActivity.find(_options);
page = ((req.query.page != undefined) ? +req.query.page : 1);
UserActivity.count(_options).exec(function(err, total) {
if (err)
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 *
* *
***************************************************************************/
hackintoshMongo: {
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',
},
// someMongoDBServer: {
// adapter: 'sails-mongo',
// },
/***************************************************************************
* *
* 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: {
adapter: 'sails-mongo',
host: '10hackintosh.vnll',
host: '10hackintosh',
port: 27017,
// user: 'username',
// password: 'password',
database: 'sails',
},
jarvisBlackboard: {
adapter: 'sails-mongo',
host: '10hackintosh',
port: 27017,
// user: 'username',
// password: 'password',
database: 'feeder',
database: 'jarvis-bb',
}
};
*/

4
config/policies.js

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

Loading…
Cancel
Save