You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.9 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  1. //File: controllers/userController.js
  2. var mongoose = require('mongoose');
  3. var userModel = mongoose.model('userModel');
  4. var notificationModel = mongoose.model('notificationModel');
  5. var travelModel = mongoose.model('travelModel');
  6. var config = require('../config');
  7. var pageSize=config.pageSize;
  8. /* */
  9. var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens
  10. var express = require("express");
  11. var app = express();
  12. var config = require('../config'); // get our config file
  13. app.set('superSecret', config.secret); // secret variable
  14. var crypto = require('crypto');
  15. /* */
  16. exports.searchByString = function (req, res) {
  17. console.log(req.params.searchstring);
  18. userModel.find({
  19. username: new RegExp(req.params.searchstring, "i")
  20. })//perquè retorni tots els objectes que continguin l'string sense necessitat de que sigui exactament la mateixa string
  21. .limit(pageSize)
  22. .skip(pageSize * Number(req.query.page))
  23. .lean()
  24. .select('username avatar')
  25. .exec(function (err, users) {
  26. if (err) return res.send(500, err.message);
  27. travelModel.find({
  28. $or:[
  29. {'from.name': new RegExp(req.params.searchstring, "i")},
  30. {'to.name': new RegExp(req.params.searchstring, "i")},
  31. {title: new RegExp(req.params.searchstring, "i")}
  32. ]
  33. })//perquè retorni tots els objectes que continguin l'string sense necessitat de que sigui exactament la mateixa string
  34. .limit(pageSize)
  35. .skip(pageSize * Number(req.query.page))
  36. .lean()
  37. .select('title from to date type')
  38. .exec(function (err, travels) {
  39. if (err) return res.send(500, err.message);
  40. res.json({
  41. users: users,
  42. travels: travels
  43. });
  44. });//travels
  45. });//users
  46. };