-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CHE-17 Created alumni model, alumni type file, added routes and getAl…
…lAlumniData controller and basic fetch test on Directory page
- Loading branch information
1 parent
e8fd24b
commit 6c0ff9c
Showing
6 changed files
with
88 additions
and
1 deletion.
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
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 Alumni from "../models/alumniModel"; | ||
import { Request, Response, NextFunction } from "express"; | ||
import { IAlumni } from "../types/alumni"; | ||
|
||
const getAllAlumniData = async ( | ||
req: Request, | ||
res: Response, | ||
next: NextFunction | ||
) => { | ||
try { | ||
const alumni: IAlumni[] = await Alumni.find({}); | ||
return res.status(200).json(alumni); | ||
} catch (error) { | ||
console.log("Awesome error handling"); | ||
} | ||
}; | ||
|
||
export { getAllAlumniData }; |
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
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,31 @@ | ||
import mongoose, { Schema } from "mongoose"; | ||
import { IAlumni } from "../types/alumni"; | ||
|
||
const alumniSchema = new Schema<IAlumni>( | ||
{ | ||
company: { type: String, trim: true }, | ||
name: { type: String, trim: true, required: true }, | ||
email: { type: String, trim: true, required: true }, | ||
linkedIn: { type: String, trim: true }, | ||
campus: { type: String, trim: true }, | ||
cohort: { | ||
type: Schema.Types.Mixed, //TODO Better way to do this? Spreadhsete has strings and numbers... | ||
required: true, | ||
validate: { | ||
validator: function (v: string | number) { | ||
return typeof v === "string" || typeof v === "number"; | ||
}, | ||
message: (props: { value: string | number }) => | ||
`${props.value} is not a valid number or string!`, | ||
}, | ||
}, | ||
jobTitle: { type: String, trim: true }, | ||
industry: { type: String, trim: true, default: "" }, | ||
cities: [{ type: String, trim: true }], | ||
}, | ||
{ timestamps: true } | ||
); | ||
|
||
const Alumni = mongoose.model<IAlumni>("Alumni", alumniSchema); | ||
|
||
export default Alumni; |
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 express from "express"; | ||
|
||
import { getAllAlumniData } from "../controllers/alumniControllers"; | ||
|
||
const router = express.Router(); | ||
|
||
router.get("/", getAllAlumniData); | ||
|
||
export default router; |
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,13 @@ | ||
import { Schema } from "mongoose"; | ||
|
||
export interface IAlumni extends Document { | ||
company: string; | ||
name: string; | ||
email: string; | ||
linkedIn: string; | ||
campus: string; | ||
cohort: Schema.Types.Mixed; | ||
jobTitle: string; | ||
industry: string; | ||
cities: string[]; | ||
} |