Skip to content

Commit

Permalink
프론트와 병합 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
IsthisLee committed Dec 10, 2021
1 parent 1fbd115 commit f45e0bf
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 16 deletions.
8 changes: 6 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ const cors = require("cors");
const bodyParser = require("body-parser");

const corsOptions = {
origin: "",
"Access-Control-Allow-Origin":
"http://test-go99.s3-website.ap-northeast-2.amazonaws.com/",
"Access-Control-Request-Method": "POST, GET, DELETE, PATCH, PUT",
"Access-Control-Request-Headers": "X-Custom-Header",
credentials: true,
};

app.use(cors());
app.use(cors(corsOptions));

const connect = require("./models");
connect();
Expand Down
23 changes: 17 additions & 6 deletions middlewares/date-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ const circles = require("../models/circles");
module.exports = async (req, res, next) => {
const { circles_id } = req.body;

console.log(req.body);

const now = new Date();
const year = now.getFullYear();
const month = now.getMonth();
const date = now.getDate();
const utc = now.getTime() + now.getTimezoneOffset() * 60 * 1000;
const KR_TIME_DIFF = 9 * 60 * 60 * 1000;
const kr_curr = new Date(utc + KR_TIME_DIFF);

const year = kr_curr.getFullYear();
const month = kr_curr.getMonth() + 1;
const date = kr_curr.getDate();

const circles_date = await circles.findOne({ circles_id: circles_id });
const [circles_date_year, circles_date_month, circles_date_date] =
Expand All @@ -15,15 +21,20 @@ module.exports = async (req, res, next) => {
const today_time = new Date(year, month, date).getTime();
const circles_time = new Date(
circles_date_year,
circles_date_month - 1,
circles_date_month,
circles_date_date
).getTime();

if (circles_time < today_time) {
return res.status(412).send({
errorMessage: "이전 날짜의 TodoList는 수정할 수 있습니다.",
errorMessage: `이전 날짜의 TodoList는 수정할 수 있습니다.
circles_id : ${circles_id},
circle : ${circles_date_year}-${circles_date_month}-${circles_date_date},
${circles_time}
today : ${year}-${month}-${date},
${today_time}`,
});
}

console.log("여기를 지나감");
next();
};
28 changes: 24 additions & 4 deletions routers/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ router.post("/projects", async (req, res) => {
const { project_title } = req.body;
let newProject = 1;

let check_title = project_title.split(" ");

if (check_title[0] === "") {
res.status(412).send({
errorMessage: "공란은 입력할 수 없습니다.",
});
}

try {
last = await Project.find({}).sort({ projects_id: -1 }).limit(1);
newProject = last[0].projects_id + 1;
Expand All @@ -32,13 +40,16 @@ router.post("/projects", async (req, res) => {

let num = 0;
let newDate = new Date();
const utc = newDate.getTime() + newDate.getTimezoneOffset() * 60 * 1000;
const KR_TIME_DIFF = 9 * 60 * 60 * 1000;
const kr_curr = new Date(utc + KR_TIME_DIFF);
for (let i = 1; i < 100; i++) {
// let newCircle = i;
let feedback = "";
newDate.setDate(newDate.getDate() + num);
const year = newDate.getFullYear();
const month = newDate.getMonth() + 1;
const date = newDate.getDate();
kr_curr.setDate(kr_curr.getDate() + num);
const year = kr_curr.getFullYear();
const month = kr_curr.getMonth() + 1;
const date = kr_curr.getDate();
const new_date = `${year}-${month}-${date}`;
if (i >= 1) {
num = 1;
Expand Down Expand Up @@ -89,6 +100,15 @@ router.delete("/projects/:projects_id", async (req, res, next) => {
router.put("/projects/:projects_id", async (req, res, next) => {
const { projects_id } = req.params;
const { userId, project_title } = req.body;

let check_title = project_title.split(" ");

if (check_title[0] === "") {
res.status(412).send({
errorMessage: "공란은 입력할 수 없습니다.",
});
}

await Project.updateOne(
{
projects_id: projects_id,
Expand Down
13 changes: 9 additions & 4 deletions routers/todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ router.post("/todos", dateMiddleware, async (req, res) => {
router.put("/todos/:todos_id", dateMiddleware, async (req, res) => {
const { todos_id } = req.params;
const { todo_content, circles_id } = req.body;
console.log("여기를 지나감");

await Todos.updateOne(
{
Expand All @@ -62,7 +63,7 @@ router.delete("/todos/:todos_id", dateMiddleware, async (req, res) => {
await Todos.deleteOne({ todos_id: todos_id });

const circle_detail = await Todos.find({ circles_id: circles_id });

console.log(circle_detail);
res.send({ result: circle_detail });
});

Expand All @@ -72,9 +73,13 @@ router.patch("/todos/:todos_id", async (req, res) => {
const { todo_check, circles_id } = req.body;

const now = new Date();
const year = now.getFullYear();
const month = now.getMonth() + 1;
const date = now.getDate();
const utc = now.getTime() + now.getTimezoneOffset() * 60 * 1000;
const KR_TIME_DIFF = 9 * 60 * 60 * 1000;
const kr_curr = new Date(utc + KR_TIME_DIFF);

const year = kr_curr.getFullYear();
const month = kr_curr.getMonth() + 1;
const date = kr_curr.getDate();

const today_date = `${year}-${month}-${date}`;
const circles_date = await circles.findOne({ circles_id: circles_id });
Expand Down
1 change: 1 addition & 0 deletions routers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ router.post("/login", async (req, res) => {

res.send({
token: token,
nickname: user.nickname,
});
});

Expand Down

0 comments on commit f45e0bf

Please sign in to comment.