-
-
-
- {imgSrc?.map((img, i) => (
-

- ))}
+
+
+
+
+
+
+
+ {imgSrc?.map((img, i) => (
+

+ ))}
+
+
-
+
+
+
-
+
);
}
diff --git a/frontend/src/types/index.tsx b/frontend/src/types/index.tsx
index 31e91388ba5de23ccb66f261cbcea14ee96355d1..94cefa5556f49349dbd9afe1ce4d72d6a75802ec 100644
--- a/frontend/src/types/index.tsx
+++ b/frontend/src/types/index.tsx
@@ -20,7 +20,18 @@ export interface PostType {
date: string;
counts: number;
_id: string;
- user: string;
+ user: {
+ _id: string;
+ name: string;
+ };
+ file: [
+ {
+ _id: string;
+ originalfilename: string;
+ newfilename: string;
+ picturepath: string;
+ }
+ ];
}
export interface SignupUser {
@@ -37,7 +48,6 @@ export interface Profile {
originalfilename: string;
newfilename: string;
picturepath: string;
- nickname: string;
};
}
diff --git a/src/controllers/fileinfo.controller.ts b/src/controllers/fileinfo.controller.ts
index a3d1c435950c8bc3dc95028830431aaab84f38f6..330b21c0cef35c7f1b42cf6cbd459ca5c6a989ac 100644
--- a/src/controllers/fileinfo.controller.ts
+++ b/src/controllers/fileinfo.controller.ts
@@ -4,7 +4,11 @@ import { TypedRequest } from "../types";
export const uploadFile = asyncWrap(async (reqExp, res, next) => {
const req = reqExp as TypedRequest;
- const form = formidable({ multiples: false, uploadDir: "uploads" });
+ const form = formidable({
+ multiples: false,
+ uploadDir: "uploads",
+ keepExtensions: true,
+ });
await new Promise((resolve, reject) => {
form.parse(req, (err, fields, files) => {
@@ -25,7 +29,11 @@ export const uploadFile = asyncWrap(async (reqExp, res, next) => {
export const uploadFiles = asyncWrap(async (reqExp, res, next) => {
const req = reqExp as TypedRequest;
- const form = formidable({ multiples: true, uploadDir: "uploads" });
+ const form = formidable({
+ multiples: true,
+ uploadDir: "uploads",
+ keepExtensions: true,
+ });
await new Promise((resolve, reject) => {
form.parse(req, (err, fields, files) => {
diff --git a/src/controllers/mainimg.controller.ts b/src/controllers/mainimg.controller.ts
index 02267198e9027bc43b39c5c7887943760ff7bd06..3946c1236da0c0900577e7164321e3a00acca625 100644
--- a/src/controllers/mainimg.controller.ts
+++ b/src/controllers/mainimg.controller.ts
@@ -1,11 +1,11 @@
import { NextFunction, Request, Response } from "express";
import isLength from "validator/lib/isLength";
-import { TypedRequestAuth } from "./auth.controller";
import { asyncWrap } from "../helpers";
import { mainimgDb } from "../db";
import { TypedRequest } from "../types";
import { ObjectId } from "mongoose";
import formidable from "formidable";
+import { TypedRequestAuth } from "./auth.controller";
export const createMainimg = asyncWrap(async (reqExp, res) => {
const req = reqExp as TypedRequestAuth<{ userId: ObjectId }>;
@@ -65,49 +65,58 @@ export const deleteMainimg = asyncWrap(async (req, res) => {
});
export const updateMainimg = asyncWrap(async (reqExp, res) => {
- const req = reqExp as TypedRequestAuth<{ userId: ObjectId }>;
+ const req = reqExp as TypedRequest;
- const form = formidable({
- uploadDir: "uploads",
- keepExtensions: true,
- multiples: false,
- });
+ // const { id } = reqExp.params;
+ const { id, theme, city, title } = req.body;
+ const { updatemainimg }: { updatemainimg: formidable.File } = req.files;
+console.log("전부 제대로", id,theme, city, title, updatemainimg)
+ const img = await mainimgDb.updateOneMainimg(id, theme,city,title, updatemainimg);
- form.parse(req, (err, fields, files) => {
- if (!Array.isArray(files.updatemainimg)) {
- //파일 좁히기 중
- if (
- !(
- Array.isArray(fields.id) ||
- Array.isArray(fields.city) ||
- Array.isArray(fields.title) ||
- Array.isArray(fields.theme)
- )
- ) {
- const id = fields.id;
- const city = fields.city;
- const title = fields.title;
- const theme = fields.theme;
- console.log("error");
- if (!(files.updatemainimg === undefined)) {
- const originalfilename = files.updatemainimg?.originalFilename;
- const newfilename = files.updatemainimg.newFilename;
- if (!(originalfilename === null || newfilename === undefined)) {
- const imgRes = mainimgDb.updateOneMainimg(
- id,
- theme,
- city,
- title,
- originalfilename,
- newfilename
- );
- return res.json(imgRes);
- }
- } else {
- const imgRes = mainimgDb.updateOneMainimg(id, theme, city, title);
- return res.json(imgRes);
- }
- }
- }
- });
-});
+ res.json(img);
+})
+// const form = formidable({
+// uploadDir: "uploads",
+// keepExtensions: true,
+// multiples: false,
+// });
+
+// form.parse(req, (err, fields, files) => {
+// if (!Array.isArray(files.updatemainimg)) {
+// //파일 좁히기 중
+// if (
+// !(
+// Array.isArray(fields.id) ||
+// Array.isArray(fields.city) ||
+// Array.isArray(fields.title) ||
+// Array.isArray(fields.theme)
+// )
+// ) {
+// const id = fields.id;
+// const city = fields.city;
+// const title = fields.title;
+// const theme = fields.theme;
+// console.log("error");
+// if (!(files.updatemainimg === undefined)) {
+// const originalfilename = files.updatemainimg?.originalFilename;
+// const newfilename = files.updatemainimg.newFilename;
+// if (!(originalfilename === null || newfilename === undefined)) {
+// const imgRes = mainimgDb.updateOneMainimg(
+// id,
+// theme,
+// city,
+// title,
+// // fileInfo
+// originalfilename,
+// newfilename
+// );
+// return res.json(imgRes);
+// }
+// } else {
+// const imgRes = mainimgDb.updateOneMainimg(id, theme, city, title);
+// return res.json(imgRes);
+// }
+// }
+// }
+// });
+// });
diff --git a/src/controllers/post.controller.ts b/src/controllers/post.controller.ts
index 45d58014981a6751830cdc4d5dc976b0342476fd..caa273522a09fd640b2dc20c92004ffdaa4f7a44 100644
--- a/src/controllers/post.controller.ts
+++ b/src/controllers/post.controller.ts
@@ -1,9 +1,11 @@
import { NextFunction, Request, Response } from "express";
import formidable, { Fields, Files } from "formidable";
import { TypedRequestAuth } from "./auth.controller";
+import equals from "validator/lib/equals";
import { asyncWrap } from "../helpers";
import { postDb, userDb } from "../db";
import { TypedRequest } from "../types";
+import { Types } from "mongoose";
export const userByPostId = (
reqExp: Request,
@@ -16,6 +18,60 @@ export const userByPostId = (
next();
};
+export const SubTract = (oldSet: Set
, newSet: Set) => {
+ const keep = new Array(); //유지
+ const drop = new Array(); //삭제
+ const add = new Array(); //추가
+
+ oldSet.forEach((oldname) => {
+ drop.push(oldname);
+ newSet.forEach((newname) => {
+ add.push(newname);
+ if (oldname === newname) {
+ keep.push(oldname);
+ }
+ });
+ });
+
+ const addSet = new Set(add);
+ const newAdd = [...addSet];
+
+ // console.log("before delete drop ", drop);
+ // console.log("before delete add ", add);
+
+ for (var i = 0; i < drop.length; i++) {
+ for (var j = 0; j < keep.length; j++) {
+ if (drop[i] === keep[j]) {
+ drop.splice(i, 1);
+ }
+ }
+ }
+
+ for (var i = 0; i < newAdd.length; i++) {
+ for (var j = 0; j < keep.length; j++) {
+ if (newAdd[i] === keep[j]) {
+ newAdd.splice(i, 1);
+ }
+ }
+ }
+
+ // console.log("spliced add", add);
+
+ const dropSet = new Set(drop);
+ const newDrop = [...dropSet];
+
+ const reAddSet = new Set(newAdd);
+ const reNewAdd = [...reAddSet];
+
+ const res = {
+ keep: keep,
+ drop: newDrop,
+ add: reNewAdd,
+ };
+
+ return res;
+};
+
//Create
export const createFileAndPost = asyncWrap(async (reqExp, res, next) => {
const req = reqExp as TypedRequestAuth<{ userId: string }>;
@@ -112,23 +168,22 @@ export const addCounts = asyncWrap(async (req, res) => {
return res.json(updateCounts);
});
-export const updatePost = asyncWrap(async (reqExp, res) => {
+export const updateOnePost = asyncWrap(async (reqExp, res) => {
const req = reqExp as TypedRequestAuth<{ userId: string }>;
-
- const userId = req.auth.userId;
+ const { userId } = req.auth;
const { postId } = req.params;
+ const oldSet = new Set();
+ const newSet = new Set();
+
+ const fileIdArr = new Array();
+
const form = formidable({
uploadDir: "uploads",
keepExtensions: true,
multiples: true,
});
- const fileIdArr = new Array();
-
- const oldSet = new Set();
- const newSet = new Set();
-
form.parse(req, async (err, fields, files) => {
if (!Array.isArray(fields.title)) {
const title = fields.title;
@@ -138,83 +193,149 @@ export const updatePost = asyncWrap(async (reqExp, res) => {
const theme = fields.theme;
if (!Array.isArray(fields.city)) {
const city = fields.city;
- if (!Array.isArray(fields.change)) {
- const change = fields.change;
-
- const oldFiles = await postDb.getFilesByPostId(postId);
- if (!(oldFiles === undefined)) {
- for (var i = 0; (i = oldFiles.length); i++) {
- const oldFileName = postDb.getOriginalFileName(oldFiles[i]);
- if (!(oldFileName === undefined)) {
- oldSet.add(oldFileName);
+
+ console.log("check files", files);
+
+ if (files.picture === undefined || files.picture === null) {
+ const postRes2 = await postDb.updatePostRow(
+ {
+ title,
+ text,
+ theme,
+ city,
+ date: Date.now(),
+ },
+ postId
+ );
+ 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]
+ );
+ if (!(name === undefined)) {
+ oldSet.add(name);
+ }
}
}
- }
+ console.log("OldSet", oldSet);
- if (Array.isArray(files.picture)) {
- for (var i = 0; i < files.picture.length; i++) {
- const newFileName = files.picture?.[i].originalFilename;
- if (!(newFileName === undefined)) {
- newSet.add(newFileName);
+ if (Array.isArray(files.picture)) {
+ for (var i = 0; i < files.picture.length; i++) {
+ const newFileName = files.picture?.[i].originalFilename;
+ if (!(newFileName === undefined || newFileName === null)) {
+ newSet.add(newFileName);
+ }
}
}
- }
+ console.log("NewSet", newSet);
- const deleteFiles = new Array();
- const addFiles = new Array();
+ //유지, 삭제, 추가 구분하기
+ const trdPart = SubTract(oldSet, newSet);
- oldSet.forEach((oldName) => {
- newSet.forEach((newName) => {
- if (!(oldName === newName)) {
- deleteFiles.push(oldName);
- addFiles.push(newName);
- }
- });
- });
+ console.log("keep", trdPart.keep);
+ console.log("drop", trdPart.drop);
+ console.log("add", trdPart.add);
- for (var i = 0; i < deleteFiles.length; i++) {
- const originalfilename = deleteFiles[i];
- const delRes = await postDb.deleteFileByName(originalfilename);
- }
+ // 삭제
+ for (var i = 0; i < trdPart.drop.length; i++) {
+ const dropRes = await postDb.deleteFileByName(
+ trdPart.drop[i]
+ );
+ console.log("delete counts", dropRes);
+ }
- if (Array.isArray(files.picture)) {
+ //유지
+ for (var i = 0; i < trdPart.keep.length; i++) {
+ const keepRes = await postDb.findByName(trdPart.keep[i]);
+ fileIdArr.push(keepRes[0]._id);
+ // console.log("keep Id", keepRes[0]._id);
+ }
+
+ //추가
for (var i = 0; i < files.picture.length; i++) {
const originalfilename = files.picture?.[i].originalFilename;
const newfilename = files.picture?.[i].newFilename;
const filepath = files.picture?.[i].filepath;
- for (var i = 0; i < addFiles.length; i++) {
- const original = addFiles[i];
- if (original === originalfilename) {
+ 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);
+ 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 updateRes = await postDb.updatedFileId(postId);
- const fileId = fileIdArr.concat(updateRes);
+ const newFileName = files.picture.originalFilename;
+ if (!(newFileName === undefined || newFileName === null)) {
+ newSet.add(newFileName);
+ }
+ console.log("NewSet", newSet);
- const postRes = await postDb.updatePostRow(
- {
- title,
- text,
- theme,
- city,
- date: Date.now(),
- user: userId,
- file: fileId,
- },
- postId
- );
- console.log("plzplzplzpllzplzlpzplzzplz", postRes);
- return res.json(postRes);
+ //유지, 삭제, 추가 구분하기
+ 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);
+ }
+ }
+ }
}
+ console.log("all fileId", fileIdArr);
+
+ //post정보 + file정보 update
+ const postRes1 = await postDb.updatePostRow(
+ {
+ title,
+ text,
+ theme,
+ city,
+ date: Date.now(),
+ file: fileIdArr,
+ },
+ postId
+ );
}
}
}
@@ -222,19 +343,11 @@ export const updatePost = asyncWrap(async (reqExp, res) => {
});
});
-//Delete
+// Delete
export const deleteOnePost = asyncWrap(async (req, res) => {
const { postId } = req.params;
- // console.log(postId);
- const deleteCount = await postDb.deletePost(postId);
- const deleteFileId = await postDb.getFilesByPostId(postId);
- if (!(deleteFileId === undefined)) {
- for (var i = 0; i < deleteFileId.length; i++) {
- const deleteId = deleteFileId[i];
- const deleteFile = await postDb.deleteFile(deleteId);
- }
- }
+ const deleteCount = await postDb.deletePost(postId);
return res.json(deleteCount);
});
diff --git a/src/db/index.ts b/src/db/index.ts
index b714af5b043b5377b84b3ba8e213d349e63d09a8..b4f157f405dc90a9f347269d84915fbe69e0bb93 100644
--- a/src/db/index.ts
+++ b/src/db/index.ts
@@ -1,4 +1,4 @@
export * as roleDb from "./role.db";
export * as postDb from "./post.db";
export * as userDb from "./user.db";
-export * as mainimgDb from "./mainimg.db"
\ No newline at end of file
+export * as mainimgDb from "./mainimg.db";
diff --git a/src/db/mainimg.db.ts b/src/db/mainimg.db.ts
index c01b8c2e9518e610695f50bfff3cf18ddeed2b2c..30a58de714733fef8282ae1329667c5628d0cba4 100644
--- a/src/db/mainimg.db.ts
+++ b/src/db/mainimg.db.ts
@@ -1,13 +1,14 @@
-import { ObjectId } from "mongoose";
+import { HydratedDocument, ObjectId } from "mongoose";
import { FileInfo, IFileInfo, Mainimg, MainimgType } from "../models";
import fs from "fs/promises";
import { fileInfoCtrl } from "../controllers";
+import formidable from "formidable";
export const createMainimg = async (mainimg: MainimgType, pic: IFileInfo) => {
const newPic = await FileInfo.create({
originalfilename: pic.originalfilename,
newfilename: pic.newfilename,
- pictureauth: pic.picturepath,
+ picturepath: pic.picturepath,
});
const newMainimg = await Mainimg.create({
@@ -43,41 +44,76 @@ export const updateOneMainimg = async (
theme: string,
city: string,
title: string,
- originalfilename?: string | null,
- newfilename?: string
+ fileInfo: formidable.File
+ // originalfilename?: string | null,
+ // newfilename?: string
) => {
- const newMainimg = await Mainimg.findById(_Id);
- console.log("error2", _Id);
- if (!(newMainimg?.fileInfo === undefined)) {
- if (originalfilename === undefined) {
- await Mainimg.findByIdAndUpdate(newMainimg._id, {
- theme: theme,
- city: city,
- title: title,
- });
- console.log("errrror4");
- } else if (
- !(originalfilename === undefined) &&
- (!(theme === undefined) ||
- !(city === undefined) ||
- !(title === undefined))
- ) {
- await Mainimg.findByIdAndUpdate(newMainimg._id, {
- theme: theme,
- city: city,
- title: title,
- });
- await FileInfo.findByIdAndUpdate(newMainimg.fileInfo._id, {
- originalfilename: originalfilename,
- newfilename: newfilename,
- });
- console.log("error6");
- } else {
- await FileInfo.findByIdAndUpdate(newMainimg.fileInfo._id, {
- originalfilename: originalfilename,
- newfilename: newfilename,
- });
- console.log("error5", newfilename, originalfilename, theme, city, title);
+ // const newMainimg = await Mainimg.findById(_Id)
+ const newMainimg = await Mainimg.findById(_Id).populate<{ fileInfo: IFileInfo }>(
+ "fileInfo"
+ );
+
+ console.log("error2", newMainimg);
+ if (!newMainimg) {
+ throw new Error("mainimg가 존재하지 않습니다")
+ }
+ if (
+ fileInfo.originalFilename &&
+ newMainimg?.fileInfo.originalfilename !== fileInfo.originalFilename
+ ) {
+ // 같지 않으면 기존의 파일을 디스크에서 삭제한 후
+ try {
+ console.log("picturepath", newMainimg.fileInfo.picturepath)
+ await fs.unlink(newMainimg.fileInfo.picturepath);
+ } catch (error) {
+ console.log("error", error);
}
- } else console.log("error3", newMainimg);
-};
+ const mainimgAvatar = newMainimg.fileInfo as HydratedDocument;
+ // 기존 fileinfo의 파일이름과 경로 변경 설정
+ mainimgAvatar.originalfilename = fileInfo.originalFilename;
+ mainimgAvatar.newfilename = fileInfo.newFilename;
+ mainimgAvatar.picturepath = fileInfo.filepath;
+ await mainimgAvatar.save();
+ }
+
+
+ newMainimg.theme = theme;
+ newMainimg.city = city;
+ newMainimg.title = title;
+ await newMainimg.save();
+ console.log("mainimg updated", newMainimg);
+ return newMainimg;
+}
+// if (!(newMainimg?.fileInfo === undefined)) {
+// if (originalfilename === undefined) {
+// await Mainimg.findByIdAndUpdate(newMainimg._id, {
+// theme: theme,
+// city: city,
+// title: title,
+// });
+// console.log("errrror4");
+// } else if (
+// !(originalfilename === undefined) &&
+// (!(theme === undefined) ||
+// !(city === undefined) ||
+// !(title === undefined))
+// ) {
+// await Mainimg.findByIdAndUpdate(newMainimg._id, {
+// theme: theme,
+// city: city,
+// title: title,
+// });
+// await FileInfo.findByIdAndUpdate(newMainimg.fileInfo._id, {
+// originalfilename: originalfilename,
+// newfilename: newfilename,
+// });
+// console.log("error6");
+// } else {
+// await FileInfo.findByIdAndUpdate(newMainimg.fileInfo._id, {
+// originalfilename: originalfilename,
+// newfilename: newfilename,
+// });
+// console.log("error5", newfilename, originalfilename, theme, city, title);
+// }
+// } else console.log("error3", newMainimg);
+// };
\ No newline at end of file
diff --git a/src/db/post.db.ts b/src/db/post.db.ts
index 68f04795e0ed989bd2c62e12cb10be820afe6bda..f131c686f0a48de4d65fe2695a19d34ba5a66c03 100644
--- a/src/db/post.db.ts
+++ b/src/db/post.db.ts
@@ -1,4 +1,5 @@
import { Types, ObjectId } from "mongoose";
+import fs from "fs/promises";
import { Post, PostType } from "../models";
import { FileInfo, IFileInfo } from "../models";
@@ -33,15 +34,14 @@ export const createFilesRow = async (
//Read
export const getPosts = async () => {
- const posts = await Post.find({}).sort({ date: -1 });
+ const posts = await Post.find()
+ .populate("file")
+ .populate("user")
+ .sort({ date: -1 });
+ console.log("file nickname", posts);
return posts;
};
-export const getFilesByPostId = async (postId: string) => {
- const files = await Post.findOne({ _id: postId }).populate("file");
- return files?.file;
-};
-
//Update
export const addOneCount = async (_id: string, counts: number) => {
const newCounts = await Post.findOneAndUpdate(
@@ -61,7 +61,6 @@ export const updatePostRow = async (post: PostType, postId: string) => {
theme: post.theme,
city: post.city,
date: post.date,
- user: post.user,
file: post.file,
},
{ new: true }
@@ -69,6 +68,11 @@ export const updatePostRow = async (post: PostType, postId: string) => {
return newPost;
};
+export const getFilesByPostId = async (postId: string) => {
+ const files = await Post.findOne({ _id: postId }).populate("file");
+ return files?.file; //file Types.ObjectId[]
+};
+
export const getOriginalFileName = async (_id: Types.ObjectId) => {
const file = await FileInfo.findOne({ _id: _id });
return file?.originalfilename;
@@ -79,15 +83,26 @@ export const updatedFileId = async (_id: string) => {
return updatedFile?.file;
};
-//Delete
-export const deletePost = async (_id: string) => {
- const res = await Post.deleteOne({ _id: _id });
- return res;
+export const findByName = async (originalfilename: string) => {
+ const fileId = await FileInfo.find({ originalfilename });
+ return fileId;
};
-export const deleteFile = async (_id: Types.ObjectId) => {
- const deleteOne = await FileInfo.deleteOne({ _id: _id });
- return deleteOne;
+//Delete
+export const deletePost = async (_id: string) => {
+ const post = await Post.findById(_id);
+ if (!(post?.file === undefined)) {
+ for (var i = 0; i < post.file.length; i++) {
+ const fileId = post.file[i];
+ const ref = await FileInfo.findById(fileId);
+ if (!(ref?.newfilename === undefined)) {
+ await fs.unlink("../travel/uploads/" + ref?.newfilename);
+ }
+ await FileInfo.deleteOne({ _id: fileId });
+ }
+ const res = await Post.deleteOne({ _id: _id });
+ return res;
+ }
};
export const deleteFileByName = async (originalfilename: string) => {
diff --git a/src/models/fileinfo.model.ts b/src/models/fileinfo.model.ts
index e9a1e544c97d3a970f736409bfeb9a2c41c7546a..644235cee74dc9d7d693fc18b394d23e0ffd5b3d 100644
--- a/src/models/fileinfo.model.ts
+++ b/src/models/fileinfo.model.ts
@@ -4,13 +4,11 @@ export interface IFileInfo {
originalfilename: string;
newfilename: string;
picturepath: string;
- nickname?: string;
}
const schema = new Schema({
originalfilename: { type: String, unique: true },
newfilename: { type: String },
- nickname: { type: String },
picturepath: { type: String },
});
diff --git a/src/models/post.model.ts b/src/models/post.model.ts
index be0df095d0236e4415d822ccb8bcdbe0985e6382..934a56931b93e7e3caa2a15cbb51ab3826bd17a7 100644
--- a/src/models/post.model.ts
+++ b/src/models/post.model.ts
@@ -7,7 +7,7 @@ export interface PostType {
city: string;
date: Date | number;
counts?: number;
- user: Types.ObjectId | string;
+ user?: Types.ObjectId | string;
file?: Array;
}
diff --git a/src/routes/mainimg.route.ts b/src/routes/mainimg.route.ts
index a89dfe161ed3fb3aefd6b851bdd2d448725727b1..83e53e1455d9dc69e6c66767e2c436673ffe3e5a 100644
--- a/src/routes/mainimg.route.ts
+++ b/src/routes/mainimg.route.ts
@@ -1,5 +1,5 @@
import express from "express";
-import { mainimgCtrl, authCtrl } from "../controllers";
+import { mainimgCtrl, authCtrl, fileInfoCtrl } from "../controllers";
const router = express.Router();
@@ -11,7 +11,7 @@ router
router
.route("/:imgId")
.delete(authCtrl.requireLogin,authCtrl.hasRole("admin"), mainimgCtrl.deleteMainimg)
- .put(authCtrl.requireLogin,authCtrl.hasRole("admin"), mainimgCtrl.updateMainimg);
+ .put(authCtrl.requireLogin,authCtrl.hasRole("admin"),fileInfoCtrl.uploadFile, mainimgCtrl.updateMainimg);
export default router;
diff --git a/src/routes/post.route.ts b/src/routes/post.route.ts
index df02fc9fc52cb6752a885270d96ff9acfe492900..7159cc44c607837ec5ded07fb3c54812b4182ed9 100644
--- a/src/routes/post.route.ts
+++ b/src/routes/post.route.ts
@@ -1,5 +1,5 @@
import express from "express";
-import { postCtrl, authCtrl, fileInfoCtrl } from "../controllers";
+import { postCtrl, authCtrl } from "../controllers";
const router = express.Router();
@@ -8,12 +8,11 @@ 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)
- .delete(authCtrl.requireLogin, postCtrl.deleteOnePost) // +authenticate
- .put(authCtrl.requireLogin, postCtrl.updatePost);
+ .delete(authCtrl.requireLogin, authCtrl.authenticate, postCtrl.deleteOnePost)
+ .put(authCtrl.requireLogin, postCtrl.updateOnePost);
router.param("postId", postCtrl.userByPostId);
export default router;