1
1
import { Request , Response } from "express" ;
2
- import { addQuestion , db , deleteQuestion , updateQuestion } from "./question.service" ;
3
2
import {
4
- getDocs ,
5
- collection ,
6
- } from "firebase/firestore" ;
3
+ addQuestion ,
4
+ db ,
5
+ deleteQuestion ,
6
+ isValidToken ,
7
+ updateQuestion ,
8
+ } from "./question.service" ;
9
+ import { getDocs , collection } from "firebase/firestore" ;
10
+ import axios from "axios" ;
7
11
8
12
interface Question {
9
13
title : string ;
@@ -22,8 +26,19 @@ interface Example {
22
26
23
27
export async function handleGetQuestions ( req : Request , res : Response ) {
24
28
try {
25
- // console.log(req.query.email);
26
- // const { email } = req.query;
29
+ console . log ( "getting questions" ) ;
30
+ const { token } = req . query ;
31
+ if ( ! token ) {
32
+ res . status ( 500 ) . send ( "unauthorized access" ) ;
33
+ }
34
+ if ( typeof token === "string" ) {
35
+ const response = await isValidToken ( token ) ;
36
+ if ( ! response ) {
37
+ res . status ( 500 ) . send ( "unauthorized access" ) ;
38
+ }
39
+ } else {
40
+ res . status ( 500 ) . send ( "invalid params" ) ;
41
+ }
27
42
const query = await getDocs ( collection ( db , "questions" ) ) ;
28
43
const result = await Promise . all (
29
44
query . docs . map ( async ( d ) => {
@@ -96,7 +111,7 @@ export async function handleUpdateQuestion(req: Request, res: Response) {
96
111
examples,
97
112
} = req . body ;
98
113
console . log ( `updating question ${ questionId } : ${ title } ` ) ;
99
- const question = await updateQuestion ( questionId , {
114
+ const question = await updateQuestion ( questionId , {
100
115
title : title ,
101
116
tags : tags ,
102
117
categories : categories ,
0 commit comments