Commit 984a1deb authored by 우지원's avatar 우지원
Browse files

Merge remote-tracking branch 'origin/young' into jiweon827

parents 0afa135b d80d2238
import Profile from "../models/profile.js"
import bcrypt from "bcryptjs";
import jwt from 'jsonwebtoken'
import config from "../config.js"
const getimage = async (req, res) => {
const defaultimg = 'https://t1.daumcdn.net/cfile/tistory/2761AA4558A05CBE2A'
// const newImg = await new Profile({
// defaultimg
// //required를 하였기 때문에 이중 하나라도 없으면 에러 발생
// }).save()
}
export default { getimage }
\ No newline at end of file
......@@ -4,20 +4,14 @@ import isEmail from 'validator/lib/isEmail.js'
import bcrypt from "bcryptjs";
import jwt from 'jsonwebtoken'
import config from "../config.js"
//꼭 js붙여주기!!
//sign validation해야됨
const signup = async (req, res) => {
const { username, nickname, email, password } = req.body
//req.body를 구조분해하여 각각 보이게함 -> 모든정보들이 한줄에 보임
console.log(username, nickname, email, password)
try {
if (!isLength(username, { min: 3, max: 10 })) {
//이범위를 벗어나면 error발생
return res.status(422).send('이름은 3-10자 사이입니다')
//422 : 형식이 잘못되었다는 error발생
} else if (!isLength(nickname, { min: 2, max: 10 })) {
return res.status(422).send('별명은 2-10자 사이입니다.')
} else if (!isLength(password, { min: 6 })) {
......@@ -25,36 +19,21 @@ const signup = async (req, res) => {
} else if (!isEmail(email)) {
return res.status(422).send('유효하지 않은 이메일 형식입니다')
}
// else if (!isLength(nickname, { min: 3, max: 10 })) {
// return res.status(422).send('Nickname must be 3-10 characters')
// } else if (!isEmail(email, {
// allow_display_name: true,
// require_display_name: true,
// allow_utf8_local_part: false,
// })) {
// return res.status(422).send('Email does not fit the format')
// } else if (!isLength(password, { min: 6, max: 25 })) {
// return res.status(422).send('Nickname must be 6-25 characters')
// }
// 기존의 email이 있으면 나오는 error (unique)
const user = await User.findOne({ email })
if (user) {
return res.status(422).send(`${email}이 이미 사용중입니다.`)
}
const hash = await bcrypt.hash(password, 10)
//promise이므로 await사용함
const newUser = await new User({
username,
nickname,
email,
password: hash,
//required를 하였기 때문에 이중 하나라도 없으면 에러 발생
}).save()
//save시 user schema형식에 맞는지 확인후 틀리면 error발생 맞으면 mongooDb로 들어감
//save(promise)붙일 시 fuction 앞에 await 붙여주기 + async 함수 앞에 붙여주기
console.log(newUser)
res.json(newUser)
......@@ -69,8 +48,6 @@ const hello = async (req, res) => {
return res.json(users)
}
const logineduser = async (req, res) => {
try {
let user = await User.findOne(req.body).select('username email nickname').exec()
......
import mongoose from 'mongoose'
const {String} = mongoose.Schema.Types
const { String } = mongoose.Schema.Types
const ChatSchema = new mongoose.Schema({
roomId: {
type: String,
// default:() => nanoid(),
unique: true
//ref:'Room' -> Room의 형식을 참고할 수 있다.
},
name: {
type: String,
room: {
type: ObjectId,
required: true,
ref: 'Room',
},
interest: {
username: {
type: String,
required: true,
select: false
ref: 'User',
},
isOpen: {
type: Boolean,
required: true,
}
message: String,
}, {
timestamps: true
})
export default mongoose.models.ChatSchema || mongoose.model('chat', ChatSchema)
\ No newline at end of file
export default mongoose.models.ChatSchema || mongoose.model('Chat', ChatSchema)
\ No newline at end of file
import mongoose from 'mongoose'
const {String} = mongoose.Schema.Types
const RoomSchema = new mongoose.Schema({
name: {
type: String,
required: true,
},
interest: {
type: String,
required: true,
select: false
},
isOpen: {
type: String,
required: true,
default: 'user',
enum: ['user', 'admin', 'root']
}
}, {
timestamps: true
})
export default mongoose.models.RoomSchema || mongoose.model('Room', RoomSchema)
import mongoose from 'mongoose'
const { String } = mongoose.Schema.Types
const ProfileSchema = new mongoose.Schema({
defaultImg: {
type: String,
required: true,
},
}, {
timestamps: true
})
export default mongoose.models.ProfileSchema || mongoose.model('profile', ProfileSchema)
\ No newline at end of file
import express from 'express'
import profileCtrl from "../controllers/profile.controller.js";
const router = express.Router()
router.route('/profile')
.get(profileCtrl.getimage)
export default router
\ No newline at end of file
......@@ -2,8 +2,6 @@ import express from 'express'
import connectDb from './utils/connectDb.js'
import userRouter from './routes/user.routes.js'
import authRouter from './routes/auth.routes.js'
import profileRouter from './routes/profile.routes.js'
import cors from "cors";
import bodyParser from "body-parser";
import http from "http";
import { Server } from 'socket.io';
......@@ -45,14 +43,8 @@ io.on("connection", (socket) => { // 기본 연결
//이부분을 body 파싱함
app.use(bodyParser.json());
// app.use(cors());
// app.use('/', indexRouter);
//express가 req.body라는곳을 자동으로만들어서 json형식으로 보낸것을 객체형식으로 넣음
//이부분 다음부터는 req.body라는 부분을 실행할 수 있음
app.use(userRouter)
app.use(authRouter)
app.use(profileRouter)
//userRouter로 이동
app.get('/', (req, res) => {
......@@ -63,9 +55,5 @@ server.listen(3030, () => {
console.log('Listening on port 3030')
})
/////////////////////////////////////////////////////////
// export default server
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