|
1 | 1 | const { connector } = require("./databaseUtil"); |
2 | 2 |
|
3 | | -const CollegeSchema = { |
| 3 | +const StudentCollegeSchema = { |
4 | 4 | userId: { |
5 | 5 | type: String, |
6 | 6 | required: true, |
@@ -60,64 +60,9 @@ const CollegeSchema = { |
60 | 60 | }, |
61 | 61 | }; |
62 | 62 |
|
63 | | -const College = new connector.model("College", CollegeSchema); |
| 63 | +const studentcollegeCollege = new connector.model( |
| 64 | + "StudentCollegeSchema", |
| 65 | + StudentCollegeSchema |
| 66 | +); |
64 | 67 |
|
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 | | -}; |
| 68 | +module.exports = {}; |
0 commit comments