Commit 7fcf7da7 authored by 이재연's avatar 이재연
Browse files

aa

parent a4bff5ef
...@@ -4,11 +4,7 @@ import fs from "fs"; ...@@ -4,11 +4,7 @@ import fs from "fs";
import cookieParser from "cookie-parser"; import cookieParser from "cookie-parser";
import mainRouter from "./routes/index.js"; import mainRouter from "./routes/index.js";
// fs.readdir('uploads', (error) => {
// if (error) {
// fs.mkdirSync('uploads');
// }
// })
const app = express(); const app = express();
......
...@@ -10,6 +10,11 @@ const signup = async (payload) => { ...@@ -10,6 +10,11 @@ const signup = async (payload) => {
return data; return data;
}; };
const userApi = { login, signup }; const profileimg = async(formData)=>{
const {data} = await axios.put("/api/profileimg",formData);
return data;
}
const userApi = { login, signup, profileimg };
export default userApi; export default userApi;
import User from "../Room/User"; import userApi from "../../apis/user.api";
// const INIT_ACCOUNT = {
// name: "",
// id:"",
// }
const Info = () => { const Info = () => {
return ( return (
......
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import React, { useState } from "react"; import React, { useEffect, useState } from "react";
import userApi from "../../apis/user.api";
const INIT_PROFILE = {
id: "",
avatarUrl: "",
};
const InfoUpdate = () => { const InfoUpdate = () => {
// const INIT_ACCOUNT={
// name:"",
// }
// const [account, setAccount] = useState(INIT_ACCOUNT) const [profile, setProfile] = useState(INIT_PROFILE);
// useEffect(()=>{
// setProfile()
// },[profile])
// const handleChange = (e)=>{ const handleChange = async (event) => {
// const {name, value, files}=e.target const { name, files } = event.target;
// if(files){ let formData = new FormData;
// setAccount({...account,[name]:files}) formData.append("avatarUrl", files[0]);
// console.log('aaaaaaa') const res = await userApi.profileimg(formData);
// } else{ console.log(res.img)
// setAccount({...account, [name]:value}) console.log(res.id)
// } setProfile({ ...profile, avatarUrl: res.img})
// } setProfile({ ...profile, id:res.id})
};
const{id,avatarUrl}=profile;
const id = 1;
const number = 1234;
return ( return (
<div className="container" style={{ background: "#FCF4FF" }}> <div className="container" style={{ background: "#FCF4FF" }}>
<div className="row"> <div className="row">
...@@ -30,7 +39,7 @@ const InfoUpdate = () => { ...@@ -30,7 +39,7 @@ const InfoUpdate = () => {
> >
프로필 정보 프로필 정보
</label> </label>
<Link to={`/profile/${id}`}> <Link to={`/profile/${profile.id}`}>
<button <button
type="button" type="button"
className="btn btn-outline-white " className="btn btn-outline-white "
...@@ -54,7 +63,7 @@ const InfoUpdate = () => { ...@@ -54,7 +63,7 @@ const InfoUpdate = () => {
style={{ position: "relative" }} style={{ position: "relative" }}
> >
<img <img
src="/cherry.jpg" src='/user.png'
id="imgfile" id="imgfile"
className="rounded-circle mt-2" className="rounded-circle mt-2"
style={{ height: "320px", width: "320px" }} style={{ height: "320px", width: "320px" }}
...@@ -63,24 +72,25 @@ const InfoUpdate = () => { ...@@ -63,24 +72,25 @@ const InfoUpdate = () => {
className="d-flex justify-content-end" className="d-flex justify-content-end"
style={{ position: "absolute", left: "295px", top: "30px" }} style={{ position: "absolute", left: "295px", top: "30px" }}
> >
<label for="inputfile"> <label for="inputfile">
<img <img
className="rounded-circle" className="rounded-circle"
src="/infoimg.jpg" src="/infoimg.jpg"
// onChange={handleChange} style={{
style={{ width: "50px",
width: "50px", height: "50px",
height: "50px", backgroundColor: "white",
backgroundColor: "white", }}
}} />
</label>
<input
onChange={handleChange}
name="avatarUrl"
type="file"
accept="image/*"
id="inputfile"
style={{ display: "none" }}
/> />
</label>
<input
type="file"
accept="image/*"
id="inputfile"
style={{ display: "none" }}
/>
</div> </div>
</div> </div>
...@@ -104,7 +114,7 @@ const InfoUpdate = () => { ...@@ -104,7 +114,7 @@ const InfoUpdate = () => {
className="justify-content-center ms-2 my-4" className="justify-content-center ms-2 my-4"
style={{ fontSize: "25px", fontWeight: "bold" }} style={{ fontSize: "25px", fontWeight: "bold" }}
> >
#{number} #{profile.id}
</div> </div>
</div> </div>
...@@ -120,6 +130,7 @@ const InfoUpdate = () => { ...@@ -120,6 +130,7 @@ const InfoUpdate = () => {
현재 비밀번호 현재 비밀번호
</label> </label>
<input <input
onChange={handleChange}
type="text" type="text"
class="form-control" class="form-control"
style={{ height: "38px", width: "200px" }} style={{ height: "38px", width: "200px" }}
......
...@@ -2,15 +2,26 @@ import { User } from "../models/index.js"; ...@@ -2,15 +2,26 @@ import { User } from "../models/index.js";
import jwt from "jsonwebtoken"; import jwt from "jsonwebtoken";
import config from "../config/app.config.js"; import config from "../config/app.config.js";
const test = async (req, res) => { const multer = require('multer');
const uploadimg = multer({ dest: 'uploads/' });
const imgUpload = uploadimg.fields([
{ name: 'avatarUrl', maxCount: 1 }
])
const update = async (req, res) => {
try { try {
console.log(req); const avatar = req.files['avatarUrl'][0]
res.json("안녕"); const avatarUrl = avatar.filename
console.log(avatarUrl)
await User.update({'img':avatarUrl},{where :{id:'9999'}} )
const userId = await User.findOne({where : {id:'9999'}})
return res.json(userId)
} catch (error) { } catch (error) {
console.log(error); console.log(error);
return res.status(500).send("test 중 에러"); res.status(500).send('이미지 업데이트 실패')
} }
}; }
const login = async (req, res) => { const login = async (req, res) => {
try { try {
...@@ -52,7 +63,8 @@ const signup = async (req, res) => { ...@@ -52,7 +63,8 @@ const signup = async (req, res) => {
}; };
export default { export default {
test,
login, login,
signup, signup,
imgUpload,
update,
}; };
...@@ -25,7 +25,7 @@ const UserModel = (sequelize) => { ...@@ -25,7 +25,7 @@ const UserModel = (sequelize) => {
type: DataTypes.STRING, type: DataTypes.STRING,
}, },
img: { img: {
type: DataTypes.ARRAY(DataTypes.INTEGER), type: DataTypes.STRING,
}, },
roomNumber: { roomNumber: {
type: DataTypes.ARRAY(DataTypes.STRING), type: DataTypes.ARRAY(DataTypes.STRING),
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
"express": "4.17.1", "express": "4.17.1",
"http": "0.0.1-security", "http": "0.0.1-security",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"multer": "^1.4.2",
"nodemon": "^2.0.7", "nodemon": "^2.0.7",
"pg": "^8.6.0", "pg": "^8.6.0",
"pg-hstore": "^2.3.4", "pg-hstore": "^2.3.4",
......
...@@ -6,4 +6,7 @@ const router = express.Router(); ...@@ -6,4 +6,7 @@ const router = express.Router();
router.route("/login").post(userCtrl.login); router.route("/login").post(userCtrl.login);
router.route("/signup").post(userCtrl.signup); router.route("/signup").post(userCtrl.signup);
router.route("/profileimg")
.put(userCtrl.imgUpload, userCtrl.update)
export default router; export default router;
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