Commit 94aeb983 authored by Jiwon Yoon's avatar Jiwon Yoon
Browse files

question DB

parent 7650280d
import React, { useState } from "react";
import { Question } from "./Question";
import axios from "axios";
export interface BasicQuestionType {
type: string;
......@@ -119,6 +120,9 @@ const RatingQ: RatingType = {
export const CreateSurveyForm = () => {
const [currentId, setCurrentId] = useState<string>("");
const [error, setError] = useState("");
const [disabled, setDisabled] = useState(false);
const [success, setSuccess] = useState(false);
const [questionList, setQuestionList] = useState<Array<BasicQuestionType>>([
EssayQ,
RadioQ,
......@@ -138,7 +142,20 @@ export const CreateSurveyForm = () => {
setQuestionList(newList);
}
function addQuestion(): void {
async function addQuestion(event: React.MouseEvent<HTMLButtonElement>) {
event.preventDefault();
try {
const res = await axios.post("/api/question/create");
console.log("서버연결됬나요", res);
console.log("회원가입");
setSuccess(true);
setError("");
} catch (error) {
console.log("에러발생");
// catchErrors(error, setError)
} finally {
// setLoading(false);
}
//무작위로 12자리 ID제공, 추후에 질문을 DB에 생성하고 _id를 DB에서 가져오는 것으로 교체할 예정
function getRandomInt(min: number, max: number): string {
min = Math.ceil(min);
......
......@@ -10,7 +10,7 @@ import { QRating } from "./QRating";
type Props = {
questionList: BasicQuestionType[];
QuestionListChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
addQuestion: () => void;
addQuestion: (event: React.MouseEvent<HTMLButtonElement>) => void;
changeCurrentId: (event: React.MouseEvent<HTMLButtonElement>) => void;
};
......
export * as userCtrl from "./user.controller";
export * as authCtrl from "./auth.controller";
export * as questionCtrl from "./question.controller";
import { questionDb } from "../db";
import { asyncWrap } from "../helpers/asyncWrap";
export const createQuestion = asyncWrap(async (req, res) => {
const question = req.body;
console.log("question body", question);
const newQuestion = await questionDb.createQuestion(question);
return res.json(question);
});
export * as userDb from "./user.db";
export * as questionDb from "./question.db";
import { Question, IQuestion } from "../models";
export const createQuestion = async (question: IQuestion) => {
const newQuestion = await Question.create(question);
return newQuestion;
};
export { default as User, IUser } from "./user.model";
export { default as Question, IQuestion } from "./question.model";
import { model, Schema, Types } from "mongoose";
export interface IQuestion {
type: string;
id: string;
title?: string;
isRequired: boolean;
comment?: string;
content?: any;
}
const schema = new Schema<IQuestion>({
id: {type:String},
type:{type:String},
title: {type:String},
isRequired: {type:Boolean},
comment:{type: String},
content:{type: Object},
});
export default model<IQuestion>("Question", schema);
\ No newline at end of file
......@@ -15,7 +15,7 @@ const validateEmail = (email: string) => {
const schema = new Schema<IUser>({
email: {
type: String,
rquired: true,
required: true,
unique: true,
validate: [validateEmail, "이메일을 입력해주세요"],
},
......
import express from "express";
import userRouter from "./user.route";
import authRouter from "./auth.route";
import questionRouter from "./question.route";
const router = express.Router();
router.use("/users", userRouter);
router.use("/auth", authRouter);
router.use("/question", questionRouter)
export default router;
import express from "express";
import { questionCtrl } from "../controllers";
const router = express.Router();
router
.route("/create")
.get()
.post(questionCtrl.createQuestion);
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