-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(subject): get all subjects endpoint
- Loading branch information
Showing
4 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { firestore } from "../config"; | ||
import { logger } from "../middleware/logging.middleware"; | ||
import { Controller, Subject } from "../types"; | ||
|
||
export const getAllSubjects: Controller = async (_req, res) => { | ||
try { | ||
const subjects = await firestore.collection("subjects").get(); | ||
const data = subjects.docs.map((doc) => doc.data() as Subject); | ||
|
||
res.json({ status: "success", data }); | ||
} catch (error) { | ||
logger.error(`Error when getting all subjects: ${error}`); | ||
res.status(400).json({ | ||
status: "fail", | ||
data: { message: "Failed to get all subjects." }, | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { Router } from "express"; | ||
import authRouter from "./auth.route"; | ||
import subjectRouter from "./subject.route"; | ||
|
||
const v1Router = Router(); | ||
|
||
v1Router.use("/auth", authRouter); | ||
v1Router.use("/subjects", subjectRouter); | ||
|
||
export default v1Router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Router } from "express"; | ||
import * as subjectController from "@controllers/subject.controller"; | ||
|
||
// /api/v1/subjects | ||
const subjectRouter = Router(); | ||
|
||
subjectRouter.get("/", subjectController.getAllSubjects); | ||
|
||
export default subjectRouter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters