Commit 18f1a3f8 authored by Lee Soobeom's avatar Lee Soobeom
Browse files

update debugging

parent fbaae34c
......@@ -59,7 +59,7 @@ export default function Profile() {
const user: Profile = await profileApi.profile();
console.log("user in effect", user);
setEmail(user.email);
setAvatarUrl(user.avatar?.newfilename);
setAvatarUrl(user.fileInfo?.newfilename);
setProfile({ ...profile, name: user.name });
};
getProfile();
......
......@@ -18,7 +18,7 @@ export default function BoardPage() {
// posts
const getDataList = async () => {
const res = await postApi.getData();
setPosts(res);
setPosts(res); //posts = res
};
const titleHandleClick = async (event: MouseEvent<HTMLButtonElement>) => {
......
......@@ -39,6 +39,7 @@ export interface SignupUser {
export interface Profile {
_id: string;
email: string;
name: string;
fileInfo: {
originalfilename: string;
newfilename: string;
......
......@@ -209,10 +209,13 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
);
console.log("no files update", postRes2);
} else {
if (Array.isArray(files.picture)) {
const oldFilesId = await postDb.getFilesByPostId(postId);
if (!(oldFilesId === undefined)) {
for (var i = 0; i < oldFilesId?.length; i++) {
const name = await postDb.getOriginalFileName(oldFilesId[i]);
const name = await postDb.getOriginalFileName(
oldFilesId[i]
);
if (!(name === undefined)) {
oldSet.add(name);
}
......@@ -239,7 +242,9 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
// 삭제
for (var i = 0; i < trdPart.drop.length; i++) {
const dropRes = await postDb.deleteFileByName(trdPart.drop[i]);
const dropRes = await postDb.deleteFileByName(
trdPart.drop[i]
);
console.log("delete counts", dropRes);
}
......@@ -251,7 +256,6 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
}
//추가
if (Array.isArray(files.picture)) {
for (var i = 0; i < files.picture.length; i++) {
const originalfilename = files.picture?.[i].originalFilename;
const newfilename = files.picture?.[i].newFilename;
......@@ -265,6 +269,54 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
filepath
);
fileIdArr.push(addRes._id);
}
}
}
} else {
const oldFilesId = await postDb.getFilesByPostId(postId);
if (!(oldFilesId === undefined)) {
for (var i = 0; i < oldFilesId?.length; i++) {
const name = await postDb.getOriginalFileName(
oldFilesId[i]
);
if (!(name === undefined)) {
oldSet.add(name);
}
}
}
console.log("OldSet", oldSet);
const newFileName = files.picture.originalFilename;
if (!(newFileName === undefined || newFileName === null)) {
newSet.add(newFileName);
}
console.log("NewSet", newSet);
//유지, 삭제, 추가 구분하기
const trdPart = subTract(oldSet, newSet);
//삭제
for (var i = 0; i < trdPart.drop.length; i++) {
const dropRes = await postDb.deleteFileByName(
trdPart.drop[i]
);
console.log("delete counts", dropRes);
}
//추가
const originalfilename = files.picture.originalFilename;
const newfilename = files.picture.newFilename;
const filepath = files.picture.filepath;
for (var j = 0; j < trdPart.add.length; j++) {
const check = trdPart.add[j];
if (originalfilename === check) {
const addRes = await postDb.createFilesRow(
originalfilename,
newfilename,
filepath
);
fileIdArr.push(addRes._id);
}
}
......@@ -288,7 +340,6 @@ export const updateOnePost = asyncWrap(async (reqExp, res) => {
}
}
}
}
});
});
......
import express from "express";
import { postCtrl, authCtrl, fileInfoCtrl } from "../controllers";
import { postCtrl, authCtrl } from "../controllers";
const router = express.Router();
......@@ -8,7 +8,6 @@ router.route("/").get(postCtrl.getAllPost);
router.route("/files/:postId").get(authCtrl.requireLogin, postCtrl.getFiles);
// router.param("postId", postCtrl.userByPostId);
router
.route("/:postId")
.post(authCtrl.requireLogin, postCtrl.addCounts)
......
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