Added poll create route in backend✔️
This commit is contained in:
23
backend/src/services/poll.service.js
Normal file
23
backend/src/services/poll.service.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import mongoose from "mongoose";
|
||||
import { createPollByData } from "../repositories/poll.repo.js";
|
||||
|
||||
export async function createPollService(title, description, options, userId) {
|
||||
try {
|
||||
const optionsData = options.map(option => ({
|
||||
name: option,
|
||||
_id : new mongoose.Types.ObjectId()
|
||||
}));
|
||||
|
||||
const data = {
|
||||
title,
|
||||
description,
|
||||
options : optionsData,
|
||||
creatorId: userId
|
||||
}
|
||||
const poll = await createPollByData(data);
|
||||
return poll;
|
||||
}
|
||||
catch(err){
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user