Skip to content

Commit 519d987

Browse files
Merge pull request #1 from SprintCV-S24/jg-config
Config and project structure
2 parents 0c4c36c + 0fb9c97 commit 519d987

File tree

9 files changed

+346
-5
lines changed

9 files changed

+346
-5
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
dist/
33
*/node_modules/
44
*.env
5-
config/serviceAccountKey.json
5+
config/serviceAccountKey.json
6+
node_modules

package-lock.json

+186-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
"cors": "^2.8.5",
1717
"dotenv": "^16.1.4",
1818
"express": "^4.18.2",
19+
"firebase-admin": "^11.2.0",
1920
"helmet": "^7.0.0",
20-
"morgan": "^1.10.0",
21-
"firebase-admin": "^11.2.0"
21+
"mongoose": "^8.1.1",
22+
"morgan": "^1.10.0"
2223
},
2324
"devDependencies": {
2425
"@types/cors": "^2.8.13",

src/controllers/.gitkeep

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is just here so the folder is tracked by git

src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import dotenv from "dotenv";
33
import cors from "cors";
44
import morgan from "morgan";
55
import helmet from "helmet";
6-
import { exampleRoute } from "./routes/exampleRoute";
6+
import { exampleRoute } from "./routers/exampleRoute";
77
import { verifyToken } from "./middlewares/verifyToken";
88
import { notFound, errorHandler } from "./middlewares/errors";
9+
import { connectDb } from "./utils/mongodb";
910

1011
dotenv.config();
1112

@@ -35,5 +36,6 @@ app.use(notFound);
3536
app.use(errorHandler);
3637

3738
app.listen(PORT, () => {
39+
connectDb();
3840
console.log(`Server is running on port ${PORT}`);
3941
});

src/models/example_event_model.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//this is a model from another project with comments added
2+
3+
//get default import from mongoose library (which is used for interacting w/ mongodb)
4+
import mongoose from "mongoose";
5+
6+
//mongoose object for defining structure of all the documents in a mongodb collection
7+
const Schema = mongoose.Schema;
8+
9+
//typescript type corresponding with the mongoose schema structure
10+
export interface eventType {
11+
name: string;
12+
description: string;
13+
code: string;
14+
date: Date;
15+
programs: string[];
16+
staff: string[];
17+
attended_youth?: string[];
18+
attached_forms?: string[];
19+
}
20+
21+
//mongoose schema for an event document
22+
const Event = new Schema<eventType>({
23+
name: { type: String, required: true },
24+
description: { type: String, required: true },
25+
code: { type: String, required: true },
26+
date: { type: Date, required: true },
27+
programs: { type: [String], required: true },
28+
staff: { type: [String], required: true }, // by Staff.fireID
29+
attended_youth: { type: [String], default: [] }, // by Youth.fireID
30+
attached_forms: { type: [String], default: [] }, // by Note._id
31+
});
32+
33+
//this takes the schema and uses it to form a model object. Model objects allow us
34+
//to interact with mongodb, such as creating new documents or querying documents. The event
35+
//model object is exported so that it can be used in other files
36+
export const EventModel = mongoose.model("Event", Event);
File renamed without changes.

0 commit comments

Comments
 (0)