Skip to content

Commit

Permalink
Merge pull request #142 from boostcampwm-2021/Feat/API/Image
Browse files Browse the repository at this point in the history
[ ddaynew365 ] userInfo 데이터 형식 수정
  • Loading branch information
ddaynew365 committed Nov 11, 2021
2 parents 9fb47af + 6fdb08e commit af4aee9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 47 deletions.
13 changes: 6 additions & 7 deletions server/src/api/chat/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import { Participant } from "../../db/models/participant";
import { Users } from "../../db/models/users";

export const findChatRoomInfo = async ({ uid }) => {
// uid로 chatRoom 정보 가져오고
// join으로 chatRoom에 대한 user 정보 가져오기
// const joinChatRooms = await findJoinChatRooms({ uid });
// console.log(joinChatRooms);
// const query = () => {

// }}

const query = ({ chatRoomId }) => {
console.log(chatRoomId);
return {
Expand All @@ -22,14 +26,11 @@ export const findChatRoomInfo = async ({ uid }) => {
attribute: [],
};
};
console.log({ uid });
const joinChatRooms = await findJoinChatRooms({ uid });
console.log(joinChatRooms);
const promiseArr = joinChatRooms.map((chatRoomId) => {
return Participant.findAll(query({ chatRoomId }));
});
const memberData = await Promise.all(promiseArr);
console.log(memberData);
const filteredMemberData = memberData.map((chatRoomMember) => {
return chatRoomMember.map((member) => {
return {
Expand All @@ -42,7 +43,6 @@ export const findChatRoomInfo = async ({ uid }) => {
};
});
});

// chatMessage
const datas = joinChatRooms.map((chatRoomId, idx) => {
return { ...chatRoomId, member: filteredMemberData[idx] };
Expand All @@ -54,7 +54,6 @@ export const findChatRoomInfo = async ({ uid }) => {
const filteredData = datas.map((unFildteredData, idx) => {
return { ...unFildteredData, chatMessage: chatMessages[idx] };
});

return filteredData;
};

Expand Down
6 changes: 3 additions & 3 deletions server/src/api/core/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ export const findAllRequest = async ({ uid }) => {
{
model: Users,
as: "info",
attributes: ["uid", "image", "location", "sex", "age"],
attributes: [["uid", "id"], "image", "location", "sex", "age"],
// attributes: ["uid", "image", "location", "sex", "age", "info"] // 나중에 info 컬럼 추가시 해당 열 사용
},
],
where: {
[Op.or]: [{ from: uid }, { to: uid }],
},
};
return await Request.findAll(query);
return await Request.findAll(query as object);
};

export const findUserInfo = async ({ uid }) => {
const query = {
attributes: ["uid", "image", "location", "sex", "age", "gid"],
attributes: [["uid", "id"], "image", "location", "sex", "age", "gid"],
// attributes: [["uid", "id"], "image", "location", "sex", "age", "info", "gid"],
where: { uid },
};
Expand Down
8 changes: 1 addition & 7 deletions server/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@ import coreRouter from "./core";
import teamRouter from "./team";

const router = Router();
// const goMain = (req, res) => {
// res.redirect("http://localhost:3000");
// };

router.use("/auth", authRouter);
router.use("/chat", chatRouter);
router.use("/team", teamRouter);
router.use("/core", coreRouter);
// router.get("/redirect", goMain);

//router.use("/profile");
//router.use("/request/info");

export default router;
2 changes: 0 additions & 2 deletions server/src/passport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import { Users } from "../db/models/users";

export default () => {
passport.serializeUser((user: Users, done) => {
console.log("in the serial");
// 로그인 시 실행, req.session 객체에 어떤 데이터를 저장할지 정하는 메서드
done(null, user.uid); // 일단은 사용자 정보가 들어있다고 생각, 첫 번째 인수는 에러 발생시 사용, 두 번째 인수에는 저장하고 싶은 데이터를 넣는다.
});

passport.deserializeUser((uid, done) => {
console.log("desrializeUser");
// 매 요청시 실행, passport.session 미들웨어가 이 메서드를 호출, serializeUser의 done 메서드의 두번째 인수로 넣었던 데이터가 deserializeUser의 매개변수가 된다.
Users.findOne({ where: { uid } }) // 데이터베이스에서 사용자 정보 조회
.then((user) => done(null, user)) // 조회한 정보를 req.user에 저장
Expand Down
29 changes: 1 addition & 28 deletions server/src/public/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,6 @@ paths:
/api/core/userInfo:
get:
summary: 유저 정보 획득
parameters:
- name: uid
in: query
required: true
description: 유저 아이디
schema:
type: string
example:
"my_id"
responses:
'200':
description: 유저 정보
Expand Down Expand Up @@ -427,15 +418,6 @@ paths:
/api/chat/info:
get:
summary: 채팅방 정보 가져오기
parameters:
- name: uid
in: query
description: 아이디
required: true
schema:
type: string
example:
"my_id"
responses:
'200':
description: 채팅방 정보
Expand Down Expand Up @@ -638,16 +620,7 @@ paths:
type: number
/api/core/request:
get:
summary: 요청 목록 가져오기
parameters:
- name: uid
in: query
description: 아이디
required: true
schema:
type: string
example:
"my_id"
summary: 요청 목록 가져오기
responses:
'200':
description: 요청 목록
Expand Down

0 comments on commit af4aee9

Please sign in to comment.