Commit 4949c01d authored by Yoon, Daeki's avatar Yoon, Daeki 😅
Browse files

Merge branch 'main' into file-upload

parents 6a24c10c 80a2b663
import { Survey, ISurvey } from "../models";
export const findUserBySurveyId = async (surveyId: string) => {
const survey = await Survey.findById(surveyId).populate("user");
console.log(survey);
if (survey !== null) {
console.log(survey.user);
return survey.user;
}
return null;
};
export const createSurvey = async (survey: ISurvey) => {
const newSurvey = await Survey.create(survey);
return newSurvey;
};
export const getSurveyById = async (surveyId: string) => {
console.log("survey id", surveyId);
const survey = await Survey.findById(surveyId).populate("questions");
return survey;
};
export const updateSurvey = async (survey: ISurvey) => {
const newSurvey = await Survey.findOneAndUpdate({ _id: survey._id }, survey);
return newSurvey;
};
import { model, Schema, Types } from "mongoose";
import { model, ObjectId, Schema, Types } from "mongoose";
export interface IQuestion {
_id?: Types.ObjectId;
user?: Types.ObjectId;
type: string;
// id: string;
title?: string;
isRequired: boolean;
comment?: string;
content?: any;
}
const schema = new Schema<IQuestion>({
type:{type:String},
title: {type:String},
isRequired: {type:Boolean},
comment:{type: String},
content:{type: Object},
}, {toJSON: {
versionKey: false
}});
}
export default model<IQuestion>("Question", schema);
const schema = new Schema<IQuestion>(
{
user: { type: Schema.Types.ObjectId, ref: "User" },
type: { type: String },
title: { type: String },
isRequired: { type: Boolean },
comment: { type: String },
content: { type: Object },
},
{
toJSON: {
versionKey: false,
},
}
);
export default model<IQuestion>("Question", schema);
import { model, Schema, Types } from "mongoose";
export interface ISurvey {
title: string;
comment: string;
questions: Types.ObjectId[]
}
_id?: Types.ObjectId;
title?: string;
comment?: string;
user: Types.ObjectId;
questions: Types.ObjectId[];
}
const schema = new Schema<ISurvey>({
title: {type:String},
comment: {type:String},
questions: [{ type: Schema.Types.ObjectId, ref: 'Question' }],
});
export default model<ISurvey>("Survey", schema);
const schema = new Schema<ISurvey>({
title: { type: String },
comment: { type: String },
user: { type: Schema.Types.ObjectId, ref: "User" },
questions: [{ type: Schema.Types.ObjectId, ref: "Question" }],
});
export default model<ISurvey>("Survey", schema);
import express from "express";
import { questionCtrl } from "../controllers";
import { authCtrl, questionCtrl } from "../controllers";
const router = express.Router();
router
.route("/create")
.post(questionCtrl.createQuestion);
.post(authCtrl.requireLogin, questionCtrl.createQuestion);
router
.route("/update/:questionId")
.put(
authCtrl.requireLogin,
authCtrl.authenticate,
questionCtrl.updateQuestion
);
router
.route("/delete/:questionId")
.delete(
authCtrl.requireLogin,
authCtrl.authenticate,
questionCtrl.deleteQuestionById
);
router.param("questionId", questionCtrl.userByQuestionId);
export default router;
import express from "express";
import { surveyCtrl } from "../controllers";
import { authCtrl, surveyCtrl } from "../controllers";
const router = express.Router();
router.route("/create").post(authCtrl.requireLogin, surveyCtrl.createSurvey);
router
.route("/create")
.post(surveyCtrl.createSurvey);
.route("/edit/:surveyId")
.get(authCtrl.requireLogin, authCtrl.authenticate, surveyCtrl.getSurveyById)
.put(authCtrl.requireLogin, authCtrl.authenticate, surveyCtrl.updateSurvey);
router.param("surveyId", surveyCtrl.userBySurveyId);
export default router;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment