|
| 1 | +const { connector } = require("./databaseUtil"); |
| 2 | + |
| 3 | +const CollegeSchema = { |
| 4 | + userId: { |
| 5 | + type: String, |
| 6 | + required: true, |
| 7 | + unique: true, |
| 8 | + }, |
| 9 | + AdmissionYear: { |
| 10 | + type: String, |
| 11 | + required: true, |
| 12 | + }, |
| 13 | + StudentCode: { |
| 14 | + type: String, |
| 15 | + }, |
| 16 | + Rollno: { |
| 17 | + type: String, |
| 18 | + }, |
| 19 | + AdmissionStatus: { |
| 20 | + type: String, |
| 21 | + required: true, |
| 22 | + }, |
| 23 | + AdmissionPattern: { |
| 24 | + type: String, |
| 25 | + }, |
| 26 | + Admissioncategory: { |
| 27 | + type: String, |
| 28 | + required: true, |
| 29 | + }, |
| 30 | + SeatDesc: { |
| 31 | + type: String, |
| 32 | + }, |
| 33 | + QuotaType: { |
| 34 | + type: String, |
| 35 | + required: true, |
| 36 | + }, |
| 37 | + QuotaType: { |
| 38 | + type: String, |
| 39 | + required: true, |
| 40 | + }, |
| 41 | + Boarder: { |
| 42 | + type: Boolean, |
| 43 | + }, |
| 44 | + Seattype: { |
| 45 | + type: String, |
| 46 | + required: true, |
| 47 | + }, |
| 48 | + Seatsubtype: { |
| 49 | + type: String, |
| 50 | + required: true, |
| 51 | + }, |
| 52 | + EligibilityNo: { |
| 53 | + type: String, |
| 54 | + required: true, |
| 55 | + }, |
| 56 | + EnrollmentNo: { |
| 57 | + type: String, |
| 58 | + required: true, |
| 59 | + unique: true, |
| 60 | + }, |
| 61 | +}; |
| 62 | + |
| 63 | +const College = new connector.model("College", CollegeSchema); |
| 64 | + |
| 65 | +export const AddCollegeDetails = async (req, res) => { |
| 66 | + const id = req.body.id; |
| 67 | + const newCollegeDetails = new College({ |
| 68 | + userId: id, |
| 69 | + ...req.body, |
| 70 | + }); |
| 71 | + try { |
| 72 | + const data = await College.findById(id); |
| 73 | + if (data) |
| 74 | + return res.status(400).send("One user can have only one college details"); |
| 75 | + |
| 76 | + await newCollegeDetails.save(); |
| 77 | + res.status(201).send("user has been created"); |
| 78 | + } catch (error) { |
| 79 | + console.log(error); |
| 80 | + } |
| 81 | +}; |
| 82 | +export const GetCollegeDetails = async (req, res) => { |
| 83 | + const id = req.params.id; |
| 84 | + try { |
| 85 | + const data = await College.findById(id); |
| 86 | + if (!data) |
| 87 | + return res |
| 88 | + .status(400) |
| 89 | + .send("No data found for this id please add your data"); |
| 90 | + |
| 91 | + res.status(200).json(data); |
| 92 | + } catch (error) { |
| 93 | + console.log(error); |
| 94 | + } |
| 95 | +}; |
| 96 | + |
| 97 | +export const updateCollegeDetails = async (req, res) => { |
| 98 | + const id = req.body.id; |
| 99 | + try { |
| 100 | + const finddata = await College.findById(id); |
| 101 | + if (!finddata) res.status(404).send("No data found for this user"); |
| 102 | + |
| 103 | + const data = await College.findByIdAndUpdate( |
| 104 | + req.params.id, |
| 105 | + { $set: req.body }, |
| 106 | + { new: true } |
| 107 | + ); |
| 108 | + console.log(data); |
| 109 | + } catch (error) { |
| 110 | + console.log(error); |
| 111 | + } |
| 112 | +}; |
| 113 | +export const deleteCollegeDetails = async (req, res) => { |
| 114 | + const id = req.body.id; |
| 115 | + try { |
| 116 | + const finddata = await College.findById(id); |
| 117 | + if (!finddata) res.status(404).send("No data found for this user"); |
| 118 | + await College.findByIdAndDelete(req.params.id); |
| 119 | + res.status(200).send("details deleted successfully"); |
| 120 | + } catch (error) { |
| 121 | + console.log(error); |
| 122 | + } |
| 123 | +}; |
0 commit comments