Added delete poll route in backend
This commit is contained in:
@@ -45,6 +45,32 @@ export async function getAllCreatedPollsService(id) {
|
||||
const polls = await findPollsByCreatorId(id);
|
||||
return polls;
|
||||
}
|
||||
catch(err){
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
export async function deletePollService(pollId, user) {
|
||||
try {
|
||||
const userId = user._id;
|
||||
const poll = await findPollById(pollId);
|
||||
if (!poll) {
|
||||
throw {
|
||||
statusCode: 404,
|
||||
message: "Poll not found"
|
||||
}
|
||||
}
|
||||
console.log(poll?.creatorId._id.toString(), userId.toString(), user);
|
||||
if (poll.creatorId._id.toString() !== userId.toString()) {
|
||||
throw {
|
||||
statusCode: 401,
|
||||
message: "Unauthorized"
|
||||
}
|
||||
}
|
||||
const deletedPoll = await deletePollService(pollId);
|
||||
return deletedPoll;
|
||||
}
|
||||
|
||||
catch(err){
|
||||
throw err;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user