Skip to content

Feat/faq backend#33

Open
willjinjin wants to merge 25 commits intomainfrom
feat/faq-backend
Open

Feat/faq backend#33
willjinjin wants to merge 25 commits intomainfrom
feat/faq-backend

Conversation

@willjinjin
Copy link
Copy Markdown
Contributor

created the connection between faq.tsx and database. created scheme, controller, and route. updated index accordingly.

willjinjin and others added 25 commits April 12, 2026 20:41
Co-authored-by: Copilot <copilot@github.com>
Copy link
Copy Markdown
Collaborator

@RLee64 RLee64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, but going to need to do a bit more to meet functionality requirements. Lmk if you need clarifying on any of the comments or aren't sure how to approach the ticket.

@@ -0,0 +1,26 @@
[
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should remove this

import { RequestHandler } from "express";
import { Faq } from "../model/faq";

export const listFaqs: RequestHandler = async (req, res) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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).

Comment thread server/src/model/faq.ts

const faqSchema = new Schema(
{
question: { type: String, required: true },
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schema we want instead is a single object like

{
    content: { type: String, required: true },
    timestamp: { type: Date, required: true },
}

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

{
    content: { type: String, required: true },
},
{ timestamps: true, versionKey: false }

import { RequestHandler } from "express";
import { Faq } from "../model/faq";

export const listFaqs: RequestHandler = async (req, res) => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: getFaqs would be a better function name (a bit more conventional for web servers)


const router = express.Router();
router.get("/", listFaqs);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

Comment thread client/src/pages/Faq.tsx
return <div>Faq page - not yet implemented</div>;
const [faqs, setFaqs] = useState<Faq[]>([]);

useEffect(() => {
Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants