Guest User

Untitled

a guest
Feb 11th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. const user = require('../models/model1').user;
  2. const chat = require('../models/model1').chat;
  3.  
  4.  
  5. const education = function (req, res) {
  6.  
  7. chat.find({ categorie: "/education"}).
  8. populate('user').
  9. exec(function (err, chat) {
  10. if (err) return handleError(err);
  11. console.log( "&&&&&&&&&&&&&&&& ",chat);
  12. res.status(200).render('education',{message:chat});
  13. });
  14. };
  15.  
  16.  
  17. const message = function (req, res) { // storing the 50
  18. previous messages
  19.  
  20. var new_chat;
  21. user.find(
  22. {email: req.query.y}, (err, user) =>{
  23. if (err) return res.status(500).send(err);
  24.  
  25. var new_chat = new chat({
  26. body: req.query.x,
  27. date: new Date(),
  28. sender: user[0].id,
  29. categorie: req.query.z
  30. });
  31. new_chat.save(function(err) {
  32. if (err) throw err;
  33. console.log('message saved');
  34. });
  35. });
  36. };
  37.  
  38. exports=module.exports={education,message};
  39.  
  40. const mongoose = require('mongoose');
  41. Schema = mongoose.Schema;
  42.  
  43. let user_schema = new Schema({
  44. email: {type: String, required: true, max: 100, unique
  45. :true},
  46. password: {type: String, required: true},
  47. username: {type: String},
  48. friends:{type: Schema.Types.ObjectId, ref: 'user'}
  49. });
  50.  
  51. const user = mongoose.model('user', user_schema,'user');
  52. let chat_schema=new Schema({
  53.  
  54. body :{type: String ,reqiured: true},
  55. date: {type:Date , reqiured: true},
  56. sender:{type: Schema.Types.ObjectId, ref: 'user', required:
  57. true},
  58. categorie: {type: String, required: true},
  59. receiver:{type: Schema.Types.ObjectId, ref: 'user',}
  60. });
  61.  
  62. const chat = mongoose.model('chat',chat_schema,'chat' );
  63.  
  64. exports =module.exports={chat,user};
Add Comment
Please, Sign In to add comment