Advertisement
oranchu

Untitled

Feb 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. //////////////////////// entryModel.js ////////////////////////
  2. 'use strict';
  3.  
  4. var options = {},
  5. config = require('../../config'),
  6. mongoose = require('mongoose');
  7.  
  8. // Merge options with defaults
  9. const driverOptions = Object.assign(config.defaultOptions, options);
  10. // Use Promise from options (mongoose)
  11. mongoose.Promise = driverOptions.promiseLibrary;
  12. // Connect
  13. var node = mongoose.createConnection(config.dbPath, driverOptions);
  14.  
  15. var Schema = mongoose.Schema;
  16.  
  17. var EntrySchema = new Schema({
  18. entryID: Schema.Types.ObjectId,
  19. userID: {
  20. type: Number,
  21. Required: true
  22. },
  23. entryDate: {
  24. type: Date,
  25. Required: true
  26. },
  27. entryType: {
  28. type: String,
  29. Required: true
  30. },
  31. mainText: String,
  32. descText: String,
  33. eventDate: String,
  34. mediaUrl: String
  35. });
  36.  
  37. module.exports = node.model('entry', EntrySchema);
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. ////////////////////////////// entryController.js //////////////////////////////////////////////
  50. var options = {},
  51. config = require('../../config'),
  52. mongoose = require('mongoose');
  53.  
  54. // Merge options with defaults
  55. const driverOptions = Object.assign(config.defaultOptions, options);
  56. // Use Promise from options (mongoose)
  57. mongoose.Promise = driverOptions.promiseLibrary;
  58. // Connect
  59. var node = mongoose.createConnection(config.dbPath, driverOptions);
  60. var Entry = node.model("entrys");
  61.  
  62. exports.getUserEntries = function(req, res) {
  63. //Find all entries where the entry's userID matches the 'userID' passed
  64. Entry.find({ userID: req.params.userID }, function(err, entry){
  65. if (err)
  66. res.send(err);
  67. res.json(entry);
  68. });
  69. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement