-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/faq backend #33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat/faq backend #33
Changes from 8 commits
928f81f
67ca058
fb4e8e2
0375cd4
d7094ac
cd5744a
1964756
86766b9
0fb0bcf
27f140a
ba4bf13
07178bd
1d73ab3
780da47
3f2948b
dfb8103
175e18c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { RequestHandler } from "express"; | ||
| import { Faq } from "../model/faq"; | ||
|
|
||
| export const listFaqs: RequestHandler = async (req, res) => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since FAQs are unlikely to be updated often, we should look into some sort of caching if possible (might just be as simple as not hitting the DB until timeout or on outdated version).
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: |
||
| try { | ||
| const faqs = await Faq.find().lean(); | ||
| res.json(faqs); | ||
| } catch (error) { | ||
| console.error("Error fetching FAQs:", error); | ||
| res.status(500).json({ message: "Failed to fetch FAQs" }); | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import mongoose from "mongoose"; | ||
| const { Schema, model } = mongoose; | ||
|
|
||
| const faqSchema = new Schema( | ||
| { | ||
| question: { type: String, required: true }, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The schema we want instead is a single object like Expanding a bit more on why the ticket wants this, allowing admins to directly edit the entire FAQ rather than a bit at a time will probably be a lot easier for them (and for us since we won't have to design a bunch of extra functionality!). Having this also gives us the potential basis to extend the FAQ backend into a larger 'content' backend, which allows for the editing of text fields in other importantn places.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh whoops, turns out there's a nice and easy way for Mongo/mongoose to automatically add timestamps |
||
| answer: { type: String, required: true }, | ||
| }, | ||
| { versionKey: false } | ||
| ); | ||
|
|
||
| export const Faq = model("Faq", faqSchema); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import express from "express"; | ||
| import { listFaqs } from "../controllers/faqController"; | ||
|
|
||
| const router = express.Router(); | ||
| router.get("/", listFaqs); | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per the ticket we should also include the ability for admins to update the FAQ page, make sure to create an endpoint for this and then test it out with Postman |
||
| export default router; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're hooking up backend to frontend, run a function to parse the content into the desired faq item format. Maybe new lines starting with a
#could be used to determine a question, and then the text in the lines below (until the next#) will be that question's answer.