forked from akshat-sachan/EventM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterest.js
29 lines (26 loc) · 870 Bytes
/
interest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const Interest = require("../models/interestModel");
let addInterest = async (req, res) => {
try {
const { interestName } = req.body;
if (!interestName || !interestName.trim())
res.status(400).json({ error: "Please enter interest name properly" });
else {
const interest = await Interest.create({interestName: interestName});
console.log(interest);
res.status(201).json({ message: "Interest added" });
}
} catch (error) {
console.log(error);
res.status(500).json({ message: "Internal server error" });
}
};
let getAllInterests = async (req, res) => {
try {
const interests = await Interest.find();
res.status(200).json(interests);
} catch (error) {
console.log(error);
res.status(500).json({ message: "Internal server error" });
}
};
module.exports = { addInterest, getAllInterests };