박권수

feat. get user's hub List

...@@ -39,6 +39,25 @@ exports.hubConnect = async (ctx) => { ...@@ -39,6 +39,25 @@ exports.hubConnect = async (ctx) => {
39 ctx.body = hub; 39 ctx.body = hub;
40 }; 40 };
41 41
42 +exports.getHubList = async(ctx) => {
43 + const token = ctx.cookies.get('access_token');
44 + if(!token) {
45 + ctx.status = 401;
46 + return;
47 + }
48 +
49 + const { userId } = jwt.verify(token, process.env.JWT_SECRET);
50 + const hubList = await Hub.find({ userId });
51 + console.log(hubList)
52 + if(!hubList || !hubList.length) {
53 + ctx.status = 404;
54 + return;
55 + }
56 +
57 + ctx.status = 200;
58 + ctx.body = hubList;
59 +};
60 +
42 exports.hubDisconnect = async(ctx) => { 61 exports.hubDisconnect = async(ctx) => {
43 const token = ctx.cookies.get('access_token'); 62 const token = ctx.cookies.get('access_token');
44 if(!token) { 63 if(!token) {
......
...@@ -12,6 +12,14 @@ const hub = new Router(); ...@@ -12,6 +12,14 @@ const hub = new Router();
12 hub.post('/', hubCtrl.hubConnect); 12 hub.post('/', hubCtrl.hubConnect);
13 13
14 /** 14 /**
15 + * 로그인한 유저의 허브 목록 가져오기
16 + * request parameter : X
17 + * url : http://localhost:4000/api/hub
18 + * return : hub List(json type)
19 + */
20 +hub.get('/', hubCtrl.getHubList);
21 +
22 +/**
15 * 허브 등록 해제 23 * 허브 등록 해제
16 * request parameter : x 24 * request parameter : x
17 * url : http://localhost:4000/api/hub/:hubId 25 * url : http://localhost:4000/api/hub/:hubId
......