Commit 5135892d authored by Lee Soobeom's avatar Lee Soobeom
Browse files

debugging

parent 35f8698d
...@@ -17,7 +17,7 @@ export default function BoardPage() { ...@@ -17,7 +17,7 @@ export default function BoardPage() {
const location = useLocation() as Newpost; const location = useLocation() as Newpost;
const newPost = location.state; const newPost = location.state;
// console.log("get newPost Info", newPost); console.log("get newPost Info", newPost);
const setNewPosts = (newpost: PostType) => { const setNewPosts = (newpost: PostType) => {
const postArr = posts?.splice(-1, 0, newPost); const postArr = posts?.splice(-1, 0, newPost);
......
import React, { FormEvent, useState } from "react"; import React, { FormEvent, MouseEventHandler, useState } from "react";
import { useNavigate, useLocation } from "react-router-dom"; import { useNavigate, useLocation, Link } from "react-router-dom";
import isLength from "validator/lib/isLength"; import isLength from "validator/lib/isLength";
import equals from "validator/lib/equals"; import equals from "validator/lib/equals";
import { catchErrors } from "../helpers"; import { catchErrors } from "../helpers";
...@@ -65,8 +65,8 @@ export function EditPost() { ...@@ -65,8 +65,8 @@ export function EditPost() {
if (postingFormMatch(user) === true) { if (postingFormMatch(user) === true) {
setLoading(true); setLoading(true);
const res = updateImg2Db(file); const updateRes = await updateImg2Db(file);
navigate("/board", { replace: true }); navigate("/board", { replace: true, state: updateRes });
setSuccess(true); setSuccess(true);
setError(""); setError("");
...@@ -164,6 +164,12 @@ export function EditPost() { ...@@ -164,6 +164,12 @@ export function EditPost() {
setUser(newUser); setUser(newUser);
}; };
const GoBack = () => {
if (confirm("취소하시겠습니까?") == true) {
navigate(-1);
}
};
const oldFileShow = (post: PostType) => { const oldFileShow = (post: PostType) => {
const res = post.file?.map((file, i) => ( const res = post.file?.map((file, i) => (
<img <img
...@@ -185,6 +191,7 @@ export function EditPost() { ...@@ -185,6 +191,7 @@ export function EditPost() {
}; };
return ( return (
<div>
<form onSubmit={reWriteSubmit} className="flex flex-col w-full"> <form onSubmit={reWriteSubmit} className="flex flex-col w-full">
<div className="flex flex-row h-10 gap-x-1 justify-end"> <div className="flex flex-row h-10 gap-x-1 justify-end">
<div className="place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300"> <div className="place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300">
...@@ -270,5 +277,14 @@ export function EditPost() { ...@@ -270,5 +277,14 @@ export function EditPost() {
/> />
</div> </div>
</form> </form>
<div className="flex md:mb-20 justify-center">
<button
onClick={GoBack}
className=" mt-5 h-12 w-40 text-lg border-2 border-sky-500 place-self-center"
>
취소
</button>
</div>
</div>
); );
} }
...@@ -13,6 +13,8 @@ export function IntoPost() { ...@@ -13,6 +13,8 @@ export function IntoPost() {
const post = location.state; const post = location.state;
const navigate = useNavigate(); const navigate = useNavigate();
console.log("user info", post.user);
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [error, setError] = useState(""); const [error, setError] = useState("");
const [addSuccess, setAddSuccess] = useState(false); const [addSuccess, setAddSuccess] = useState(false);
...@@ -56,7 +58,7 @@ export function IntoPost() { ...@@ -56,7 +58,7 @@ export function IntoPost() {
<div className="flex h-10 items-center border-t-2 border-sky-200 md:flex-row justify-between bg-slate-50 text-sm"> <div className="flex h-10 items-center border-t-2 border-sky-200 md:flex-row justify-between bg-slate-50 text-sm">
<div className="flex whitespace-nowrap pr-5 "> <div className="flex whitespace-nowrap pr-5 ">
작성자: {post.user.slice(0, 8)} 작성자: {post.user.name}
</div> </div>
<div className="flex divide-x divide-slate-300 "> <div className="flex divide-x divide-slate-300 ">
......
import React, { FormEvent, useEffect, useState } from "react"; import React, { FormEvent, useEffect, useState } from "react";
import { useNavigate } from "react-router-dom"; import { useNavigate, Link } from "react-router-dom";
import isLength from "validator/lib/isLength"; import isLength from "validator/lib/isLength";
import equals from "validator/lib/equals"; import equals from "validator/lib/equals";
import { catchErrors } from "../helpers"; import { catchErrors } from "../helpers";
...@@ -21,11 +21,15 @@ export default function Posting() { ...@@ -21,11 +21,15 @@ export default function Posting() {
theme: "", theme: "",
city: "", city: "",
date: "", date: "",
user: "", user: {
_id: "",
name: "",
},
counts: 0, counts: 0,
_id: "", _id: "",
file: [ file: [
{ {
_id: "",
originalfilename: "", originalfilename: "",
newfilename: "", newfilename: "",
picturepath: "", picturepath: "",
...@@ -69,12 +73,10 @@ export default function Posting() { ...@@ -69,12 +73,10 @@ export default function Posting() {
try { try {
if (confirm("게시물을 작성하시겠습니까?") == true) { if (confirm("게시물을 작성하시겠습니까?") == true) {
setError(""); setError("");
// console.log("user data", user);
if (postingFormMatch(user, file)) { if (postingFormMatch(user, file)) {
setLoading(true); setLoading(true);
if (file) { if (file) {
const postRes = await sendImg2Db(file); const postRes = await sendImg2Db(file);
// console.log("Newpost Info", postRes);
navigate("/board", { replace: true, state: postRes }); navigate("/board", { replace: true, state: postRes });
} }
setSuccess(true); setSuccess(true);
...@@ -174,7 +176,14 @@ export default function Posting() { ...@@ -174,7 +176,14 @@ export default function Posting() {
} }
}; };
const GoBack = () => {
if (confirm("취소하시겠습니까?") == true) {
navigate(-1);
}
};
return ( return (
<div>
<form onSubmit={handlePostSubmit} className="flex flex-col w-full"> <form onSubmit={handlePostSubmit} className="flex flex-col w-full">
<div className="flex flex-row gap-x-1 justify-end h-10 "> <div className="flex flex-row gap-x-1 justify-end h-10 ">
<div className="place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300"> <div className="place-self-center w-16 h-6 border-2 border-sky-400 transition delay-150 bg-white-400 hover:-translate-y-1 hover:scale-110 hover:bg-gray-300 duration-300">
...@@ -260,5 +269,14 @@ export default function Posting() { ...@@ -260,5 +269,14 @@ export default function Posting() {
/> />
</div> </div>
</form> </form>
<div className="flex md:mb-20 justify-center">
<button
onClick={GoBack}
className=" mt-5 h-12 w-40 text-lg border-2 border-sky-500 place-self-center"
>
취소
</button>
</div>
</div>
); );
} }
...@@ -20,9 +20,13 @@ export interface PostType { ...@@ -20,9 +20,13 @@ export interface PostType {
date: string; date: string;
counts: number; counts: number;
_id: string; _id: string;
user: string; user: {
_id: string;
name: string;
};
file: [ file: [
{ {
_id: string;
originalfilename: string; originalfilename: string;
newfilename: string; newfilename: string;
picturepath: string; picturepath: string;
......
...@@ -22,6 +22,7 @@ export const authenticate = asyncWrap( ...@@ -22,6 +22,7 @@ export const authenticate = asyncWrap(
if (req.auth) { if (req.auth) {
const { userId } = req.auth; const { userId } = req.auth;
const user = req.user; const user = req.user;
// const adminId =
if (user && user.id === userId) { if (user && user.id === userId) {
return next(); return next();
} else { } else {
......
...@@ -18,7 +18,7 @@ export const userByPostId = ( ...@@ -18,7 +18,7 @@ export const userByPostId = (
next(); next();
}; };
export const subTract = (oldSet: Set<string>, newSet: Set<string>) => { export const SubTract = (oldSet: Set<string>, newSet: Set<string>) => {
const keep = new Array<string>(); //유지 const keep = new Array<string>(); //유지
const drop = new Array<string>(); //삭제 const drop = new Array<string>(); //삭제
const add = new Array<string>(); //추가 const add = new Array<string>(); //추가
...@@ -234,7 +234,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => { ...@@ -234,7 +234,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
console.log("NewSet", newSet); console.log("NewSet", newSet);
//유지, 삭제, 추가 구분하기 //유지, 삭제, 추가 구분하기
const trdPart = subTract(oldSet, newSet); const trdPart = SubTract(oldSet, newSet);
console.log("keep", trdPart.keep); console.log("keep", trdPart.keep);
console.log("drop", trdPart.drop); console.log("drop", trdPart.drop);
...@@ -294,7 +294,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => { ...@@ -294,7 +294,7 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
console.log("NewSet", newSet); console.log("NewSet", newSet);
//유지, 삭제, 추가 구분하기 //유지, 삭제, 추가 구분하기
const trdPart = subTract(oldSet, newSet); const trdPart = SubTract(oldSet, newSet);
//삭제 //삭제
for (var i = 0; i < trdPart.drop.length; i++) { for (var i = 0; i < trdPart.drop.length; i++) {
......
...@@ -34,8 +34,11 @@ export const createFilesRow = async ( ...@@ -34,8 +34,11 @@ export const createFilesRow = async (
//Read //Read
export const getPosts = async () => { export const getPosts = async () => {
const posts = await Post.find().populate("file").sort({ date: -1 }); const posts = await Post.find()
console.log(posts); .populate("file")
.populate("user")
.sort({ date: -1 });
console.log("file nickname", posts);
return posts; return posts;
}; };
......
...@@ -4,13 +4,11 @@ export interface IFileInfo { ...@@ -4,13 +4,11 @@ export interface IFileInfo {
originalfilename: string; originalfilename: string;
newfilename: string; newfilename: string;
picturepath: string; picturepath: string;
nickname?: string;
} }
const schema = new Schema<IFileInfo>({ const schema = new Schema<IFileInfo>({
originalfilename: { type: String, unique: true }, originalfilename: { type: String, unique: true },
newfilename: { type: String }, newfilename: { type: String },
nickname: { type: String },
picturepath: { type: String }, picturepath: { type: String },
}); });
......
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