add fonction notifFonction.js
continuous-integration/drone/push Build encountered an error Details

master
Bastien OLLIER 2 years ago
parent 5919090a0e
commit 650b298767

@ -59,3 +59,5 @@ export const unFollowUser = (followerId, idToUnFollow) => {
.catch((err) => console.log(err));
};
};

@ -1,10 +1,11 @@
import React, {useEffect} from 'react';
import {isEmpty} from "./Utils";
import {useSelector} from "react-redux";
import axios from "axios";
const Notif = ({message} ) => {
const usersData = useSelector((state) => state.users.users);
import { useDispatch } from 'react-redux';
const Notif = ({message} ) => {
return (
<div className='conteneur_notif'>
<div className={'contenue_notif'}>

@ -0,0 +1,12 @@
const UserModel = require("../models/user.model");
module.exports.addNotification = (userId, notification) => {
UserModel.findById(userId, (err, user) => {
if (err) {
console.log(err);
} else {
user.notif.push(notification);
user.save();
}
});
};

@ -7,6 +7,21 @@ const ObjectID = require("mongoose").Types.ObjectId;
const fs = require("fs");
const { promisify } = require("util");
//import { addNotification } from "./notifFonction";
const {addNotification} = require("./notifFonction");
//const UserModel = require("../models/user.model");
/*const addNotification = (userId, notification) => {
UserModel.findById(userId, (err, user) => {
if (err) {
console.log(err);
} else {
user.notif.push(notification);
user.save();
}
});
};*/
module.exports.readPost = (req, res) => {
PostModel.find((err, docs) => {
if (!err) res.send(docs);
@ -60,7 +75,15 @@ module.exports.deletePost = (req, res) => {
});
};
module.exports.likePost = async (req, res) => {
addNotification("63b835de3f9be509b614df36", {
typeNotif: "like",
id_user: "5f1a32c2f9f9ab74a1b7a6c8",
id_post1: "5f1a32c2f9f9ab74a1b7a6c8",
id_post2: ""
});
if (!ObjectID.isValid(req.params.id))
return res.status(400).send("ID unknown : " + req.params.id);

@ -1,4 +1,4 @@
const mongoose = require('mongoose');
const mongoose = require('mongoose');
//trim pour supprimer les espaces
const postSchema = new mongoose.Schema(

@ -5,6 +5,25 @@ const { isEmail } = require('validator');
const bcrypt = require('bcrypt');
const NotifSchema = new mongoose.Schema({
typeNotif: {
type: String,
required: true
},
id_user: {
type: String,
required: true
},
id_post1: {
type: String,
required: true
},
id_post2: {
type: String,
required: true
}
});
//trim pour supprimer les espaces
const userSchema = new mongoose.Schema(
{
@ -46,7 +65,8 @@ const userSchema = new mongoose.Schema(
},
likes: {
type: [String]
}
},
notif: [NotifSchema]
},
{
timestamps: true,

@ -21,7 +21,6 @@ router.delete('/:id', userController.deleteUser);
router.patch('/follow/:id', userController.follow);
router.patch('/unfollow/:id', userController.unfollow);
//upload pb avec postman
router.post("/upload", upload.single('file'), uploadController.uploadProfil);

Loading…
Cancel
Save