공정훈

Update mbti list

Showing 1 changed file with 65 additions and 219 deletions
...@@ -5,7 +5,6 @@ const bodyParser = require('body-parser'); ...@@ -5,7 +5,6 @@ const bodyParser = require('body-parser');
5 5
6 const apiRouter = express.Router(); 6 const apiRouter = express.Router();
7 7
8 -
9 app.use(bodyParser.json()); 8 app.use(bodyParser.json());
10 app.use(bodyParser.urlencoded({ 9 app.use(bodyParser.urlencoded({
11 extended: true 10 extended: true
...@@ -13,24 +12,7 @@ app.use(bodyParser.urlencoded({ ...@@ -13,24 +12,7 @@ app.use(bodyParser.urlencoded({
13 12
14 app.use('/api', apiRouter); 13 app.use('/api', apiRouter);
15 14
16 -apiRouter.post("/blockId", function(req, res) { 15 +let userDB = new Array();
17 - const userRequest = req.body.userRequest;
18 - const blockId = userRequest.block.id;
19 -
20 - return res.send({
21 - version: "2.0",
22 - template: {
23 - outputs: [
24 - {
25 - "basicCard": {
26 - "title": "블록ID 입니다",
27 - "description": blockId
28 - }
29 - }
30 - ]
31 - }
32 - });
33 -});
34 16
35 apiRouter.post('/sayHello', function(req, res) { 17 apiRouter.post('/sayHello', function(req, res) {
36 const responseBody = { 18 const responseBody = {
...@@ -59,159 +41,12 @@ apiRouter.post('/sayHello', function(req, res) { ...@@ -59,159 +41,12 @@ apiRouter.post('/sayHello', function(req, res) {
59 res.status(200).send(responseBody); 41 res.status(200).send(responseBody);
60 }); 42 });
61 43
62 -var mbtilist = {
63 - I: false,
64 - E: false,
65 - S: false,
66 - N: false,
67 - T: false,
68 - F: false,
69 - P: false,
70 - J: false
71 -};
72 -
73 -var userDB = {};
74 -
75 -apiRouter.post("/add", function(req, res) {
76 - const userRequest = req.body.userRequest;
77 - const userId = userRequest.user.id;
78 - const usermbti = userRequest.utterance;
79 -
80 - if (!userDB[userId]) {
81 - userDB[userId] = { ...mbtilist };
82 - }
83 -
84 - if (usermbti in mbtilist) {
85 - userDB[userId][usermbti] = true;
86 - }
87 -
88 - return res.send({
89 - version: "2.0",
90 - template: {
91 - outputs: [
92 - {
93 - basicCard: {
94 - description: "추가 되었습니다",
95 - buttons: [
96 - {
97 - action: "message",
98 - label: "내 mbti 목록",
99 - messageText: "내 mbti 목록"
100 - },
101 - {
102 - action: "message",
103 - label: "mbti 추가",
104 - messageText: "mbti 추가"
105 - }
106 - ]
107 - }
108 - }
109 - ]
110 - }
111 - });
112 -});
113 -
114 -apiRouter.post("/form", function(req,res) {
115 - const userRequest = req.body.userRequest;
116 - const userId = userRequest.user.id;
117 - let mbti = [];
118 -
119 - if (!userDB[userId]) {
120 - mbti = Object.keys(mbtilist).map(f => {
121 - return {
122 - action: "block",
123 - label: f,
124 - blockId: "62903faf7befc3101c3be587"
125 - };
126 - });
127 - } else {
128 - mbti = Object.keys(userDB[userId])
129 - .filter(f => {
130 - return userDB[userId][f] === false;
131 - })
132 - .map(f => {
133 - return {
134 - action: "block",
135 - label: f,
136 - blockId: "62903faf7befc3101c3be587"
137 - };
138 - });
139 - }
140 -
141 - return res.send({
142 - version: "2.0",
143 - template: {
144 - outputs: [
145 - {
146 - simpleText: {
147 - text: "추가할 mbti를 선택해 주세요"
148 - }
149 - }
150 - ],
151 - quickReplies: mbti
152 - }
153 - });
154 -});
155 -
156 -apiRouter.post("/list", function(req, res) {
157 - const userRequest = req.body.userRequest;
158 - const userId = userRequest.user.id;
159 - let mymbti = [];
160 -
161 - if (userDB[userId]) {
162 - mymbti = Object.keys(userDB[userId]).filter(f => {
163 - return userDB[userId][f] === true;
164 - });
165 - }
166 -
167 - if (mymbti.length <= 0) {
168 - return res.send({
169 - version: "2.0",
170 - template: {
171 - outputs: [
172 - {
173 - basicCard: {
174 - description: "등록된 mbti가 없습니다",
175 - buttons: [
176 - {
177 - action: "message",
178 - label: "mbti 추가",
179 - messageText: "mbti 추가"
180 - }
181 - ]
182 - }
183 - }
184 - ]
185 - }
186 - });
187 - } else {
188 - return res.send({
189 - version: "2.0",
190 - template: {
191 - outputs: [
192 - {
193 - basicCard: {
194 - description: `현재 나의 mbti는 ${mymbti
195 - .map(f => `[${f}]`)
196 - .join(", ")} 입니다`,
197 - buttons: [
198 - {
199 - action: "message",
200 - label: "mbti 추가",
201 - messageText: "mtbi 추가"
202 - }
203 - ]
204 - }
205 - }
206 - ]
207 - }
208 - });
209 - }
210 -});
211 -
212 apiRouter.post('/question1', (req, res) => { 44 apiRouter.post('/question1', (req, res) => {
45 + var userId = req.body.userRequest.user.id;
213 var mesg = req.body.userRequest; 46 var mesg = req.body.userRequest;
214 console.log('[q1:user message] ', mesg); 47 console.log('[q1:user message] ', mesg);
48 + userDB[userId] = '';
49 + console.log(userDB[userId]);
215 const responseBody = { 50 const responseBody = {
216 version: "2.0", 51 version: "2.0",
217 template: { 52 template: {
...@@ -242,21 +77,24 @@ apiRouter.post('/question1', (req, res) => { ...@@ -242,21 +77,24 @@ apiRouter.post('/question1', (req, res) => {
242 }); 77 });
243 78
244 apiRouter.post('/question2', (req, res) => { 79 apiRouter.post('/question2', (req, res) => {
245 - var mesg = req.body.userRequest.utterance; 80 + var userId = req.body.userRequest.user.id;
246 - console.log('[q2:user message] ', mesg); 81 + var mesg = req.body.userRequest.utterance;
247 - var mbti = ''; 82 + console.log('[q2:user message] ', mesg);
248 - if (mesg == "네") { 83 + var mbti = '';
249 - mbti = 'E'; 84 + if (mesg == "네") {
250 - } else if (mesg == "아니오") { 85 + mbti = 'E';
251 - mbti = 'I'; 86 + } else if (mesg == "아니오") {
252 - } 87 + mbti = 'I';
253 - const responseBody = { 88 + }
89 + userDB[userId] += mbti;
90 + console.log(userDB[userId]);
91 + const responseBody = {
254 version: "2.0", 92 version: "2.0",
255 template: { 93 template: {
256 outputs: [ 94 outputs: [
257 { 95 {
258 simpleText: { 96 simpleText: {
259 - text: 'mbti:'+mbti+'***\n\n평소 깻잎논쟁에 1시간 이상을 생각해봤다.\n맞다면 N 아니면 S을 입력해주세요.' 97 + text: '평소 깻잎논쟁에 1시간 이상을 생각해봤다.'
260 } 98 }
261 } 99 }
262 ], 100 ],
...@@ -280,45 +118,48 @@ apiRouter.post('/question2', (req, res) => { ...@@ -280,45 +118,48 @@ apiRouter.post('/question2', (req, res) => {
280 }); 118 });
281 119
282 apiRouter.post('/question3', function(req, res) { 120 apiRouter.post('/question3', function(req, res) {
283 - var mesg = req.body.userRequest.utterance; 121 + var userId = req.body.userRequest.user.id;
284 - console.log('[q3:user message] ', mesg); 122 + var mesg = req.body.userRequest.utterance;
285 - var mbti = ''; 123 + console.log('[q3:user message] ', mesg);
286 - if (mesg == '네') { 124 + var mbti = '';
287 - mbti = 'N'; 125 + if (mesg == '네') {
288 - } else if (mesg == '아니오') { 126 + mbti = 'N';
289 - mbti = 'S'; 127 + } else if (mesg == '아니오') {
290 - } 128 + mbti = 'S';
291 - const responseBody = {
292 - version: "2.0",
293 - template: {
294 - outputs: [
295 - {
296 - "simpleText": {
297 - "text": "mbti:*"+mbti+"**\n\n다음과 같은 상황에서 어떻게 대답하겠습니까?\n 친구: 나 기분 안 좋아서 옷 샀어"
298 - }
299 - }
300 - ],
301 - quickReplies: [
302 - {
303 - action: "block",
304 - label: "왜 기분 안 좋아?",
305 - message: "왜 기분 안 좋아?",
306 - blockId: "6290630451c40d32c6d8e71f"
307 - },
308 - {
309 - action: "block",
310 - label: "무슨 옷 샀어?",
311 - message: "무슨 옷 샀어?",
312 - blockId: "6290630451c40d32c6d8e71f"
313 - }
314 - ]
315 } 129 }
316 - }; 130 + userDB[userId] += mbti;
317 - 131 + console.log(userDB[userId]);
318 - res.status(200).send(responseBody); 132 + const responseBody = {
133 + version: "2.0",
134 + template: {
135 + outputs: [
136 + {
137 + "simpleText": {
138 + "text": "다음과 같은 상황에서 어떻게 대답하겠습니까?\n 친구: 나 기분 안 좋아서 옷 샀어"
139 + }
140 + }
141 + ],
142 + quickReplies: [
143 + {
144 + action: "block",
145 + label: "왜 기분 안 좋아?",
146 + message: "왜 기분 안 좋아?",
147 + blockId: "6290630451c40d32c6d8e71f"
148 + },
149 + {
150 + action: "block",
151 + label: "무슨 옷 샀어?",
152 + message: "무슨 옷 샀어?",
153 + blockId: "6290630451c40d32c6d8e71f"
154 + }
155 + ]
156 + }
157 + };
158 + res.status(200).send(responseBody);
319 }); 159 });
320 160
321 apiRouter.post('/question4', (req, res) => { 161 apiRouter.post('/question4', (req, res) => {
162 + var userId = req.body.userRequest.user.id;
322 var mesg = req.body.userRequest.utterance; 163 var mesg = req.body.userRequest.utterance;
323 console.log('[q4:user message] ', mesg); 164 console.log('[q4:user message] ', mesg);
324 var mbti = ''; 165 var mbti = '';
...@@ -327,13 +168,15 @@ apiRouter.post('/question4', (req, res) => { ...@@ -327,13 +168,15 @@ apiRouter.post('/question4', (req, res) => {
327 } else if (mesg == "무슨 옷 샀어?") { 168 } else if (mesg == "무슨 옷 샀어?") {
328 mbti = 'T'; 169 mbti = 'T';
329 } 170 }
171 + userDB[userId] += mbti;
172 + console.log(userDB[userId]);
330 const responseBody = { 173 const responseBody = {
331 version: "2.0", 174 version: "2.0",
332 template: { 175 template: {
333 outputs: [ 176 outputs: [
334 { 177 {
335 simpleText: { 178 simpleText: {
336 - text: "mbti:**"+mbti+"*\n\n그날 할 일에 대해 계획을 미리 세우시나요?" 179 + text: "그날 할 일에 대해 계획을 미리 세우시나요?"
337 } 180 }
338 } 181 }
339 ], 182 ],
...@@ -357,6 +200,7 @@ apiRouter.post('/question4', (req, res) => { ...@@ -357,6 +200,7 @@ apiRouter.post('/question4', (req, res) => {
357 }); 200 });
358 201
359 apiRouter.post('/result', (req, res) => { 202 apiRouter.post('/result', (req, res) => {
203 + var userId = req.body.userRequest.user.id;
360 var mesg = req.body.userRequest.utterance; 204 var mesg = req.body.userRequest.utterance;
361 console.log('[result:user message] ', mesg); 205 console.log('[result:user message] ', mesg);
362 var mbti = ''; 206 var mbti = '';
...@@ -365,21 +209,23 @@ apiRouter.post('/result', (req, res) => { ...@@ -365,21 +209,23 @@ apiRouter.post('/result', (req, res) => {
365 } else if (mesg == "아니오") { 209 } else if (mesg == "아니오") {
366 mbti = 'P'; 210 mbti = 'P';
367 } 211 }
212 + userDB[userId] += mbti;
213 + console.log(userDB[userId]);
368 const responseBody = { 214 const responseBody = {
369 version: "2.0", 215 version: "2.0",
370 template: { 216 template: {
371 outputs: [ 217 outputs: [
372 { 218 {
373 simpleText: { 219 simpleText: {
374 - text: "mbti: ***"+mbti 220 + text: "당신의 MBTI는 : "+userDB[userId]
375 } 221 }
376 } 222 }
377 ], 223 ],
378 quickReplies: [{ 224 quickReplies: [{
379 action: "block", 225 action: "block",
380 - label: "mbti 결과 보기", 226 + label: "MBTI 테스트 다시하기",
381 - message: "mbti 결과 보기", 227 + message: "MBTI 테스트 다시하기",
382 - blockId : "629045977befc3101c3be778" //mbti list로 연결 228 + blockId : "628b8005055a574d7df54466"
383 }] 229 }]
384 } 230 }
385 } 231 }
......