From 5ca8149bd3c8da9fb1bc7cfd0a0a68185b8c7563 Mon Sep 17 00:00:00 2001 From: Heikki Hellgren Date: Wed, 17 Jan 2024 09:46:34 +0200 Subject: [PATCH] fix: use correct json response from routes --- .../src/service/routes/answers.ts | 12 +++++----- .../src/service/routes/questions.ts | 24 +++++++++---------- .../qeta-backend/src/service/routes/tags.ts | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/plugins/qeta-backend/src/service/routes/answers.ts b/plugins/qeta-backend/src/service/routes/answers.ts index 69960efa..be8fad96 100644 --- a/plugins/qeta-backend/src/service/routes/answers.ts +++ b/plugins/qeta-backend/src/service/routes/answers.ts @@ -65,7 +65,7 @@ export const answersRoutes = (router: Router, options: RouterOptions) => { // Response response.status(201); - response.send(answer); + response.json(answer); }); // POST /questions/:id/answers/:answerId @@ -103,7 +103,7 @@ export const answersRoutes = (router: Router, options: RouterOptions) => { // Response response.status(201); - response.send(answer); + response.json(answer); }); // POST /questions/:id/answers/:answerId/comments @@ -159,7 +159,7 @@ export const answersRoutes = (router: Router, options: RouterOptions) => { // Response response.status(201); - response.send(answer); + response.json(answer); }, ); @@ -188,7 +188,7 @@ export const answersRoutes = (router: Router, options: RouterOptions) => { // Response response.status(201); - response.send(answer); + response.json(answer); }, ); @@ -212,7 +212,7 @@ export const answersRoutes = (router: Router, options: RouterOptions) => { mapAdditionalFields(username, answer, options, moderator); // Response - response.send(answer); + response.json(answer); }); // DELETE /questions/:id/answers/:answerId @@ -295,7 +295,7 @@ export const answersRoutes = (router: Router, options: RouterOptions) => { }); } // Response - response.send(answer); + response.json(answer); }; // GET /questions/:id/answers/:answerId/upvote diff --git a/plugins/qeta-backend/src/service/routes/questions.ts b/plugins/qeta-backend/src/service/routes/questions.ts index 5ed4ba86..1d7bc8ba 100644 --- a/plugins/qeta-backend/src/service/routes/questions.ts +++ b/plugins/qeta-backend/src/service/routes/questions.ts @@ -43,7 +43,7 @@ export const questionsRoutes = (router: Router, options: RouterOptions) => { const questions = await database.getQuestions(username, request.query); // Response - response.send(questions); + response.json(questions); }); // GET /questions @@ -79,7 +79,7 @@ export const questionsRoutes = (router: Router, options: RouterOptions) => { }); // Response - response.send(questions); + response.json(questions); }); // GET /questions/:id @@ -105,7 +105,7 @@ export const questionsRoutes = (router: Router, options: RouterOptions) => { ); // Response - response.send(question); + response.json(question); }); // POST /questions/:id/comments @@ -153,7 +153,7 @@ export const questionsRoutes = (router: Router, options: RouterOptions) => { } // Response - response.send(question); + response.json(question); }); // DELETE /questions/:id/comments/:commentId @@ -183,7 +183,7 @@ export const questionsRoutes = (router: Router, options: RouterOptions) => { ); // Response - response.send(question); + response.json(question); }, ); @@ -221,7 +221,7 @@ export const questionsRoutes = (router: Router, options: RouterOptions) => { if (!validateRequestBody(request.body)) { response .status(400) - .send({ errors: validateRequestBody.errors, type: 'body' }); + .json({ errors: validateRequestBody.errors, type: 'body' }); return; } @@ -255,7 +255,7 @@ export const questionsRoutes = (router: Router, options: RouterOptions) => { // Response response.status(201); - response.send(question); + response.json(question); }); // POST /questions/:id @@ -265,7 +265,7 @@ export const questionsRoutes = (router: Router, options: RouterOptions) => { if (!validateRequestBody(request.body)) { response .status(400) - .send({ errors: validateRequestBody.errors, type: 'body' }); + .json({ errors: validateRequestBody.errors, type: 'body' }); return; } @@ -305,7 +305,7 @@ export const questionsRoutes = (router: Router, options: RouterOptions) => { // Response response.status(200); - response.send(question); + response.json(question); }); // DELETE /questions/:id @@ -383,7 +383,7 @@ export const questionsRoutes = (router: Router, options: RouterOptions) => { } // Response - response.send(question); + response.json(question); }; // GET /questions/:id/upvote @@ -419,7 +419,7 @@ export const questionsRoutes = (router: Router, options: RouterOptions) => { mapAdditionalFields(username, question, options, moderator); // Response - response.send(question); + response.json(question); }); // GET /questions/:id/unfavorite @@ -445,6 +445,6 @@ export const questionsRoutes = (router: Router, options: RouterOptions) => { mapAdditionalFields(username, question, options, moderator); // Response - response.send(question); + response.json(question); }); }; diff --git a/plugins/qeta-backend/src/service/routes/tags.ts b/plugins/qeta-backend/src/service/routes/tags.ts index daaf6357..c83717a2 100644 --- a/plugins/qeta-backend/src/service/routes/tags.ts +++ b/plugins/qeta-backend/src/service/routes/tags.ts @@ -7,6 +7,6 @@ export const tagsRoutes = (router: Router, options: RouterOptions) => { // GET /tags router.get('/tags', async (_request, response) => { const tags = await database.getTags(); - response.send(tags); + response.json(tags); }); };