diff --git a/server/app.js b/server/app.js index 0e2de3c6..9a7dc050 100644 --- a/server/app.js +++ b/server/app.js @@ -3,8 +3,6 @@ import "express-async-errors"; import cors from "cors"; import cookieParser from "cookie-parser"; import morgan from "morgan"; -import swaggerUi from "swagger-ui-express"; -import swaggerJSDoc from "swagger-jsdoc"; import authRouter from "./router/auth.js"; import docRouter from "./router/doc.js"; import rankRouter from "./router/rank.js"; @@ -24,41 +22,13 @@ const corsOptions = { allowedHeaders: ["Content-type", "Authorization"], credentials: true, }; -const swaggerDefinition = { - info: { - title: "Winner's Record API", - version: "1.0.0", - description: "API description", - }, - host: "locahost:8080", - basePath: "/", - securityDefinitions: { - bearerAuth: { - type: "apiKey", - name: "Authorization", - scheme: "bearer", - in: "header", - }, - }, -}; -const options = { - swaggerDefinition, - apis: ["./router/*.js"], -}; - -const swaggerSpec = swaggerJSDoc(options); -app.get("/swagger.json", (req, res) => { - res.setHeader("Content-Type", "application/json"); - res.send(swaggerSpec); -}); app.use(express.json()); app.use(cors(corsOptions)); app.use(cookieParser()); app.use(morgan("tiny")); -app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec)); -app.use("/wr", (req, res, next) => { +app.get("/wr", (req, res, next) => { res.send(`Winner's Record`); }); diff --git a/server/data/doc.js b/server/data/doc.js index 7ef4e8d1..5e0bcdd5 100644 --- a/server/data/doc.js +++ b/server/data/doc.js @@ -168,10 +168,11 @@ export async function validType(type) { export async function editDoc(docId, data) { const img = data.img; //[string, string] - await db.Docs_Images.destroy({ - where: { docId }, - }); - if (!img.length) { + + if (Array.isArray(img) && !img.length) { + await db.Docs_Images.destroy({ + where: { docId }, + }); if (data.event === "tennis") { await db.Docs_Images.create({ docId, @@ -193,7 +194,10 @@ export async function editDoc(docId, data) { imgId: 58, }); } - } else { + } else if (Array.isArray(img)) { + await db.Docs_Images.destroy({ + where: { docId }, + }); for (let i = 0; i < img.length; i++) { const newImg = await db.Images.create({ link: img[i], @@ -229,7 +233,6 @@ export async function editDoc(docId, data) { const editedDoc = await db.Docs.findOne({ where: { id: docId }, }).catch((err) => console.log(err)); - return editedDoc; }