|
| 1 | +const Profile = require('../../Modules/Teacher/module.tprofile'); |
| 2 | + |
| 3 | +const createProfile = async (req, res) => { |
| 4 | + if(req.body) { |
| 5 | + const profile = new Profile(req.body); |
| 6 | + await profile.save() |
| 7 | + .then(data=>{ |
| 8 | + res.status(200).send({data: data}); |
| 9 | + }) |
| 10 | + .catch(error =>{ |
| 11 | + res.status(500).send({error: error.message}); |
| 12 | + }); |
| 13 | + } |
| 14 | +} |
| 15 | + |
| 16 | +const getAllProfiles = async (req, res) => { |
| 17 | + await Profile.find({}) |
| 18 | + .then(data=>{ |
| 19 | + res.status(200).send({data: data}); |
| 20 | + }) |
| 21 | + .catch(error =>{ |
| 22 | + res.status(500).send({error: error.message}); |
| 23 | + }); |
| 24 | +} |
| 25 | + |
| 26 | +const viewProfileById = async (req, res) => { |
| 27 | + if (req.params && req.params.id) { |
| 28 | + await Profile.findById(req.params.id) |
| 29 | + .populate('profile', '_id registrationNumber fName lName nic passportNumber address contactNumber email password editedDate') |
| 30 | + .then(response => { |
| 31 | + res.status(200).send({ data: response }); |
| 32 | + }) |
| 33 | + .catch(error => { |
| 34 | + res.status(500).send({ error: error.message }); |
| 35 | + }); |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | + |
| 40 | +const updateProfileById = async (req, res) => { |
| 41 | + const id = req.params.id; |
| 42 | + const {status} = req.body; |
| 43 | + const updateProfile = { |
| 44 | + status |
| 45 | + } |
| 46 | + const update = await Profile.findByIdAndUpdate(id, updateProfile) |
| 47 | + .then(() => { |
| 48 | + res.status(200).send({status: "Teacher Profile Updated"}) |
| 49 | + }).catch((err) => { |
| 50 | + console.log(err); |
| 51 | + res.status(500).send({status: " Error", error:err.message}); |
| 52 | + }) |
| 53 | +} |
| 54 | + |
| 55 | +const deleteProfileById = async (req, res) => { |
| 56 | + const id = req.params.id |
| 57 | + await Profile.findByIdAndRemove(id).exec() |
| 58 | + res.send('Teacher Profile Deleted'); |
| 59 | +} |
| 60 | + |
| 61 | +module.exports = { |
| 62 | + createProfile, |
| 63 | + getAllProfiles, |
| 64 | + viewProfileById, |
| 65 | + updateProfileById, |
| 66 | + deleteProfileById |
| 67 | +} |
0 commit comments