Skip to content

Commit

Permalink
Merge pull request hngprojects#490 from bammietop03/bamiwo
Browse files Browse the repository at this point in the history
feat: get all faq
  • Loading branch information
Khingz authored Aug 8, 2024
2 parents d2671e2 + 12f99d7 commit 44e3a47
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/controllers/FaqController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,56 @@ class FAQController {
next(error);
}
}

/**
* @swagger
* /faqs:
* get:
* summary: Retrieve all FAQs
* description: Retrieve a list of all FAQs with their respective questions, answers, and categories.
* tags: [FAQ]
* responses:
* 200:
* description: Successfully retrieved all FAQs.
* content:
* application/json:
* schema:
* type: array
* items:
* type: object
* properties:
* id:
* type: string
* description: The unique identifier for the FAQ.
* example: 12345
* question:
* type: string
* description: The question part of the FAQ.
* example: What is the return policy?
* answer:
* type: string
* description: The answer part of the FAQ.
* example: You can return any item within 30 days.
* category:
* type: string
* description: The category of the FAQ.
* example: Returns
* 500:
* description: Internal server error.
*/
public async getFaq(req: Request, res: Response, next: NextFunction) {
try {
const faqs = await faqService.getAllFaqs();
res.status(200).json({
status_code: 200,
success: true,
message: "The FAQ has been retrieved successfully.",
data: faqs,
});
} catch (error) {
next(error);
}
}
}

export { FAQController };
1 change: 1 addition & 0 deletions src/routes/faq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ const faqController = new FAQController();

faqRouter.post("/faqs", authMiddleware, faqController.createFAQ);
faqRouter.patch("/faqs/:id", authMiddleware, faqController.updateFaq);
faqRouter.get("/faqs", faqController.getFaq);

export { faqRouter };
9 changes: 9 additions & 0 deletions src/services/faq.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ class FAQService {
throw error;
}
}

public async getAllFaqs(): Promise<FAQ[]> {
try {
const faqs = await this.faqRepository.find();
return faqs;
} catch (error) {
throw new Error("Failed to fetch FAQs");
}
}
}

export { FAQService };

0 comments on commit 44e3a47

Please sign in to comment.