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

- ))}
+ placeholder="제목을 입력해 주세요!"
+ className="flex w-96 border-2 border-sky-500 rounded"
+ />
+
+
+ {imgSrc?.map((img, i) => (
+

+ ))}
+
+ placeholder="여행 후기를 알려주세요!"
+ className="flex w-96 h-96 border-2 border-sky-500 rounded"
+ />
diff --git a/src/controllers/post.controller.ts b/src/controllers/post.controller.ts
index 69af3821dbb27480e840bfd1dc18120123cfdf1d..49127bc8e174eb0aaeedd479cf23fff3a166dd9b 100644
--- a/src/controllers/post.controller.ts
+++ b/src/controllers/post.controller.ts
@@ -7,10 +7,6 @@ import { TypedRequest } from "../types";
export const createImgAndPost = asyncWrap(async (reqExp, res, next) => {
const req = reqExp as TypedRequestAuth<{ userId: string }>;
- // const { date, counts } = req.body as {
- // date: "";
- // counts: 0;
- // };
const { userId } = req.auth;
@@ -20,43 +16,43 @@ export const createImgAndPost = asyncWrap(async (reqExp, res, next) => {
multiples: true,
});
- const fileIdArr = new Array();
-
form.parse(req, (err, fields, files) => {
- const title = fields.title?.[0];
- const text = fields.text?.[0];
- const theme = fields.theme?.[0];
- const city = fields.city?.[0];
-
if (Array.isArray(files.picture)) {
for (var i = 0; i < files.picture.length; i++) {
- if (!(files.picture?.[i].originalFilename === null)) {
- const originalfilename = files.picture?.[i].originalFilename;
- const newfilename = files.picture?.[i].newFilename;
- const filepath = files.picture?.[i].filepath;
-
- const filesRes = postDb.createFilesRow(
- originalfilename,
- newfilename,
- filepath
- );
+ const originalfilename = files.picture?.[i].originalFilename;
+ const newfilename = files.picture?.[i].newFilename;
+ const filepath = files.picture?.[i].filepath;
+
+ const filesRes = postDb.createFilesRow(
+ originalfilename,
+ newfilename,
+ filepath
+ );
+ }
+ } // create fileinfos row
+
+ if (!Array.isArray(fields.title)) {
+ const title = fields.title;
+ if (!Array.isArray(fields.text)) {
+ const text = fields.text;
+ if (!Array.isArray(fields.theme)) {
+ const theme = fields.theme;
+ if (!Array.isArray(fields.city)) {
+ const city = fields.city;
+
+ const postRes = postDb.createPostRow({
+ title,
+ text,
+ theme,
+ city,
+ date: Date.now(),
+ counts: 0,
+ user: userId,
+ }); // create posts
+ }
}
}
- } else {
- console.log("업로드한 사진이 없습니다.");
}
-
- const postRes = postDb.createPostRow({
- title,
- text,
- theme,
- city,
- date: Date.now(),
- counts: 0,
- user: userId,
- });
-
- console.log("createPostRow", postRes);
});
});
diff --git a/src/db/post.db.ts b/src/db/post.db.ts
index 1b16277df239d1f92f6febec8880727c7d371127..9ce3319a567ba4af70ddd5034a64d2d297678dbf 100644
--- a/src/db/post.db.ts
+++ b/src/db/post.db.ts
@@ -28,6 +28,11 @@ export const createFilesRow = async (
return newFileRow;
};
+export const findFile = async (postId: string) => {
+ const fileInfo = await Post.findById({ postId }).populate("file");
+ return fileInfo;
+};
+
export const findFileByPostInfo = async (title: string, usreId: string) => {
const posts = await Post.find({ title: title, userId: usreId });
return posts;
diff --git a/src/db/user.db.ts b/src/db/user.db.ts
index 0cb5a434c5e9bf934051ff819f413910735f3e0e..0ef20e331b2612cb954cbf00753161105e0b983b 100644
--- a/src/db/user.db.ts
+++ b/src/db/user.db.ts
@@ -102,7 +102,7 @@ export const postPicture = async (
}
};
-export const deleteUser = async (userId: string) => {
+export const deleteUser = async (userId: ObjectId) => {
const user = await User.findById(userId);
if (user && user.avatar) {
const file = await FileInfo.findById(user.avatar._id);