Feat/faq backend#33
Conversation
Co-authored-by: Copilot <copilot@github.com>
RLee64
left a comment
There was a problem hiding this comment.
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 @@ | |||
| [ | |||
| import { RequestHandler } from "express"; | ||
| import { Faq } from "../model/faq"; | ||
|
|
||
| export const listFaqs: RequestHandler = async (req, res) => { |
There was a problem hiding this comment.
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).
|
|
||
| const faqSchema = new Schema( | ||
| { | ||
| question: { type: String, required: true }, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
nit: getFaqs would be a better function name (a bit more conventional for web servers)
|
|
||
| const router = express.Router(); | ||
| router.get("/", listFaqs); | ||
|
|
There was a problem hiding this comment.
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
…d schema to be easier for admins to edit
…employing a parse function
RLee64
left a comment
There was a problem hiding this comment.
Nice work! Glad to see these changes. This solution works, but I think it might be better to put things on hold for a bit and restructure this into a more broad 'content' backend (for other editable fields). You've pretty much already got the structure down, and it'll mainly just be smaller semantic changes.
This PR is unfortunately in a bit of a weird state where it's over-engineered for the FAQ page - realistically all we need is an updateFaq endpoint - but not fully sufficient for a broader CMS for text.
For now focus on getting the main page designed for milestone 1, and we'll have someone else continue working off this later.
| } | ||
| }; | ||
|
|
||
| export const deleteAllFaqs: RequestHandler = async(req, res) => { |
There was a problem hiding this comment.
Remove deleteAllFaqs. Also make sure to remove its usage in routes/faq.ts.
| import { RequestHandler } from "express"; | ||
| import { Faq } from "../model/faq"; | ||
|
|
||
| const CACHE_TTL_MS = 10; |
There was a problem hiding this comment.
A ttl of 10ms doesn't do much 😭
|
ahh okay no worries 😹 I forgot to change the delay back from testing but
is 1h okay?
…On Thu, 21 May 2026, 10:14 am Rayen Lee, ***@***.***> wrote:
***@***.**** commented on this pull request.
Nice work! Glad to see these changes. This solution works, but I think it
might be better to put things on hold for a bit and restructure this into a
more broad 'content' backend (for other editable fields). You've pretty
much already got the structure down, and it'll mainly just be smaller
semantic changes.
This PR is unfortunately in a bit of a weird state where it's
over-engineered for the FAQ page - realistically all we need is an
updateFaq endpoint - but not fully sufficient for a broader CMS for text.
For now focus on getting the main page designed for milestone 1, and we'll
have someone else continue working off this later.
------------------------------
In server/src/controllers/faqController.ts
<#33 (comment)>:
> +
+export const deleteFaq: RequestHandler = async (req, res) => {
+ try {
+ const deleted = await Faq.findByIdAndDelete(req.params.id);
+ if (!deleted) {
+ res.status(404).json({ message: "FAQ not found" });
+ return;
+ }
+ res.json({ message: "FAQ deleted successfully" });
+ } catch (error) {
+ console.error("Error deleting FAQ: ", error);
+ res.status(500).json({ message: "Failed to delete FAQ" });
+ }
+};
+
+export const deleteAllFaqs: RequestHandler = async(req, res) => {
Remove deleteAllFaqs. Also make sure to remove its usage in routes/faq.ts.
------------------------------
In server/src/controllers/faqController.ts
<#33 (comment)>:
> @@ -0,0 +1,71 @@
+import { RequestHandler } from "express";
+import { Faq } from "../model/faq";
+
+const CACHE_TTL_MS = 10;
A ttl of 10ms doesn't do much 😭
—
Reply to this email directly, view it on GitHub
<#33 (review)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AUMHM2LREVTAEZ4QKE2RRO343YU5DAVCNFSM6AAAAACYH7VNDGVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHM2DGMZSGU2DSNRZHA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Honestly, making it even longer (e.g. 1 day/week) might be good. To make sure updates are in realtime, we probably want an update flag that gets set whenever a change is made. |
|
Just adding this so I don't forget, technically, there's also a memory leak here, since deleted objects will still remain in memory |
created the connection between faq.tsx and database. created scheme, controller, and route. updated index accordingly.