Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const user = require('../models/model1').user;
- const chat = require('../models/model1').chat;
- const education = function (req, res) {
- chat.find({ categorie: "/education"}).
- populate('user').
- exec(function (err, chat) {
- if (err) return handleError(err);
- console.log( "&&&&&&&&&&&&&&&& ",chat);
- res.status(200).render('education',{message:chat});
- });
- };
- const message = function (req, res) { // storing the 50
- previous messages
- var new_chat;
- user.find(
- {email: req.query.y}, (err, user) =>{
- if (err) return res.status(500).send(err);
- var new_chat = new chat({
- body: req.query.x,
- date: new Date(),
- sender: user[0].id,
- categorie: req.query.z
- });
- new_chat.save(function(err) {
- if (err) throw err;
- console.log('message saved');
- });
- });
- };
- exports=module.exports={education,message};
- const mongoose = require('mongoose');
- Schema = mongoose.Schema;
- let user_schema = new Schema({
- email: {type: String, required: true, max: 100, unique
- :true},
- password: {type: String, required: true},
- username: {type: String},
- friends:{type: Schema.Types.ObjectId, ref: 'user'}
- });
- const user = mongoose.model('user', user_schema,'user');
- let chat_schema=new Schema({
- body :{type: String ,reqiured: true},
- date: {type:Date , reqiured: true},
- sender:{type: Schema.Types.ObjectId, ref: 'user', required:
- true},
- categorie: {type: String, required: true},
- receiver:{type: Schema.Types.ObjectId, ref: 'user',}
- });
- const chat = mongoose.model('chat',chat_schema,'chat' );
- exports =module.exports={chat,user};
Add Comment
Please, Sign In to add comment