Skip to content

Commit

Permalink
Merge pull request #278 from glen15/fix/total
Browse files Browse the repository at this point in the history
[Server] Fix/total
  • Loading branch information
glen15 authored Nov 3, 2021
2 parents 4695271 + 8f71d39 commit da162c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 37 deletions.
32 changes: 1 addition & 31 deletions server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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`);
});

Expand Down
15 changes: 9 additions & 6 deletions server/data/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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],
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit da162c8

Please sign in to comment.