Commit 3be6ef0d authored by Kim, MinGyu's avatar Kim, MinGyu
Browse files

프로필 수정

parent e99115b3
......@@ -59,11 +59,7 @@ export default function Profile() {
formdata.append("nickname", nickname);
console.log("both");
await profileApi.picture(formdata);
} else if (!(file === undefined) && nickname === "") {
formdata.append("picture", file);
console.log("file");
await profileApi.picture(formdata);
} else if (file === undefined && !(nickname === "")) {
} else if (!(nickname === "")) {
formdata.append("nickname", nickname);
console.log("picture");
await profileApi.picture(formdata);
......
......@@ -9,7 +9,7 @@ export default function Header() {
return (
<div className="flex flex-col ">
<div className="flex py-10 ">
<button className="shrink-0 mx-5">
<button className="shrink-0 mx-5">
<Link to="/" className="hover:text-sky-300 focus:text-purple-500">
Travel Report
</Link>
......
......@@ -42,36 +42,26 @@ export const postPicture = asyncWrap(async (reqExp, res) => {
form.parse(req, (err, fields, files) => {
if (!Array.isArray(files.picture)) {
//파일 좁히기 중
if (Array.isArray(fields.nickname)) {
console.log(fields.nickname);
const nickname = fields.nickname.join();
const originalfilename = files.picture.originalFilename;
const newfilename = files.picture.newFilename;
const picturepath = files.picture.filepath;
userDb.postPicture(
userId,
originalfilename,
newfilename,
picturepath,
nickname
);
} else {
if (!Array.isArray(fields.nickname)) {
const nickname = fields.nickname;
const originalfilename = files.picture.originalFilename;
const newfilename = files.picture.newFilename;
const picturepath = files.picture.filepath;
userDb.postPicture(
userId,
originalfilename,
newfilename,
picturepath,
nickname
);
if (!(files.picture === undefined)) {
const originalfilename = files.picture.originalFilename;
const newfilename = files.picture.newFilename;
const picturepath = files.picture.filepath;
userDb.postPicture(
userId,
nickname,
originalfilename,
newfilename,
picturepath
);
} else {
userDb.postPicture(userId, nickname);
}
}
}
});
res.json();
});
......
......@@ -73,19 +73,32 @@ export const isValidUserId = async (userId: string) => {
export const postPicture = async (
userId: ObjectId,
originalfilename: string | null,
newfilename: string,
picturepath: string,
nickname: string
nickname: string,
originalfilename?: string | null,
newfilename?: string,
picturepath?: string
) => {
const profile = await User.findById(userId);
if (!(profile?.avatar === undefined)) {
await Avatar.findByIdAndUpdate(profile.avatar._id, {
originalfilename: originalfilename,
newfilename: newfilename,
picturepath: picturepath,
nickname: nickname,
});
if (originalfilename === null) {
await Avatar.findByIdAndUpdate(profile.avatar._id, {
nickname: nickname,
});
} else if (nickname === "") {
await Avatar.findByIdAndUpdate(profile.avatar._id, {
originalfilename: originalfilename,
newfilename: newfilename,
picturepath: picturepath,
});
} else {
await Avatar.findByIdAndUpdate(profile.avatar._id, {
originalfilename: originalfilename,
newfilename: newfilename,
picturepath: picturepath,
nickname: nickname,
});
}
}
};
......
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