Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server Side File Reorganization #397

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
9494153
refactor file structure
michelleli01 Sep 12, 2023
c0f54ac
lint
michelleli01 Sep 12, 2023
06ddf2b
remove db from gitignore
michelleli01 Sep 12, 2023
354e5b3
lint
michelleli01 Sep 12, 2023
a6bed60
replacing === instead of ==
michelleli01 Sep 12, 2023
eb0f25b
extracted types and functions
michelleli01 Sep 12, 2023
75811a0
rename to routes.ts files
michelleli01 Sep 12, 2023
c925a84
lint
michelleli01 Sep 12, 2023
846c707
lint
michelleli01 Sep 12, 2023
59b56ad
move test files
michelleli01 Sep 12, 2023
16e6a84
Merge branch 'michelle/restructure-server' of https://github.com/corn…
michelleli01 Sep 26, 2023
4776403
Merge branch 'master' of https://github.com/cornell-dti/course-review…
michelleli01 Sep 26, 2023
0ffe723
add new dao layer
michelleli01 Sep 26, 2023
0f56376
more restructuring
michelleli01 Sep 26, 2023
4172e14
temporarily remove tests
michelleli01 Sep 26, 2023
bb15b3f
more restructuring
michelleli01 Sep 26, 2023
25dddb4
rename
michelleli01 Sep 26, 2023
c9f1dae
abstract data from reviews
michelleli01 Sep 26, 2023
d5e29ca
move stuff
michelleli01 Nov 26, 2023
f135a4b
change name
michelleli01 Nov 26, 2023
7923b7a
small changes
michelleli01 Nov 26, 2023
45578fb
auth function
michelleli01 Nov 26, 2023
c0f4bf8
admin endpoints
michelleli01 Nov 26, 2023
d4b1b1f
deprecate endpoints.ts for profile
michelleli01 Nov 26, 2023
9e6ceec
remove unnecessary lines
michelleli01 Nov 26, 2023
34c9c5f
remove unnecessary
michelleli01 Nov 26, 2023
00b7cad
refactor search
michelleli01 Nov 26, 2023
09abd18
remove unnecessary
michelleli01 Nov 26, 2023
c25a14b
add search and profile endpoints
michelleli01 Nov 26, 2023
8fd6cdf
review router refactor
michelleli01 Nov 26, 2023
1deccaa
try and fix search
michelleli01 Nov 26, 2023
1601fe9
fix returns
michelleli01 Nov 26, 2023
b6ede16
fix returns
michelleli01 Nov 26, 2023
513143e
reorg
michelleli01 Nov 26, 2023
c6fedec
adjustments
michelleli01 Nov 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ mongodb-binaries/
.git
.vscode
.env
db
.meteor
mongo/
*error.log
Expand Down
21 changes: 16 additions & 5 deletions server/dbDefs.ts → server/db/dbDefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const ClassSchema = new Schema<ClassDocument>({
classRating: { type: Number }, // the average class rating from reviews
classWorkload: { type: Number }, // the average workload rating from reviews
classDifficulty: { type: Number }, // the average difficulty rating from reviews

});

export const Classes = mongoose.model<ClassDocument>("classes", ClassSchema);
Expand All @@ -54,7 +53,10 @@ const StudentSchema = new Schema<StudentDocument>({
reviews: { type: [String] }, // the reviews that this user has posted.
likedReviews: { type: [String] },
});
export const Students = mongoose.model<StudentDocument>("students", StudentSchema);
export const Students = mongoose.model<StudentDocument>(
"students",
StudentSchema,
);

/* # Subjects Collection
# List of all course subject groups and their full text names
Expand All @@ -70,7 +72,10 @@ const SubjectSchema = new Schema<SubjectDocument>({
subShort: { type: String }, // subject, like "PHIL" or "CS"
subFull: { type: String }, // subject full name, like 'Computer Science'
});
export const Subjects = mongoose.model<SubjectDocument>("subjects", SubjectSchema);
export const Subjects = mongoose.model<SubjectDocument>(
"subjects",
SubjectSchema,
);

/* # Reviews Collection.
# Stores each review inputted by a user. Linked with the course that was
Expand Down Expand Up @@ -119,7 +124,10 @@ const ProfessorSchema = new Schema<ProfessorDocument>({
courses: { type: [String] }, // a list of the ids all the courses
major: { type: String }, // professor affliation by probable major
});
export const Professors = mongoose.model<ProfessorDocument>("professors", ProfessorSchema);
export const Professors = mongoose.model<ProfessorDocument>(
"professors",
ProfessorSchema,
);

/* # Validation Collection.
# Stores passwords and other sensitive application keys.
Expand All @@ -135,4 +143,7 @@ interface ValidationDocument extends mongoose.Document {
adminPass?: string;
}

export const Validation = mongoose.model<ValidationDocument>("validation", ValidationSchema);
export const Validation = mongoose.model<ValidationDocument>(
"validation",
ValidationSchema,
);
105 changes: 84 additions & 21 deletions server/dbInit.test.ts → server/db/dbInit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import axios from "axios";
import { MongoMemoryServer } from "mongodb-memory-server";
import mongoose from "mongoose";
import { Subjects, Classes, Professors } from "./dbDefs";
import { fetchSubjects, fetchClassesForSubject, fetchAddCourses } from "./dbInit";
import {
fetchSubjects,
fetchClassesForSubject,
fetchAddCourses,
} from "./dbInit";

let testServer: MongoMemoryServer;
let serverCloseHandle;
Expand All @@ -17,8 +21,11 @@ beforeAll(async () => {
// get mongoose all set up
testServer = new MongoMemoryServer();
const mongoUri = await testServer.getUri();
await mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true });
mongoose.set('useFindAndModify', false);
await mongoose.connect(mongoUri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
mongoose.set("useFindAndModify", false);

await new Subjects({
_id: "some id",
Expand Down Expand Up @@ -62,8 +69,16 @@ beforeAll(async () => {
status: "success",
data: {
subjects: [
{ descr: "Study of Fungi", descrformal: "The Study of Fungi", value: "gork" },
{ descr: "Study of Space", descrformal: "The Study of Where No One has Gone Before", value: "fedn" },
{
descr: "Study of Fungi",
descrformal: "The Study of Fungi",
value: "gork",
},
{
descr: "Study of Space",
descrformal: "The Study of Where No One has Gone Before",
value: "fedn",
},
],
},
});
Expand All @@ -88,18 +103,45 @@ beforeAll(async () => {
catalogNbr: "1110",
titleLong: "Introduction to Angry Fungi",
randoJunk: "Making sure this scauses no issues",
enrollGroups: [{ classSections: [{ ssrComponent: "LEC", meetings: [{ instructors: [{ firstName: "Prof.", lastName: "Thraka" }] }] }] }],
enrollGroups: [
{
classSections: [
{
ssrComponent: "LEC",
meetings: [
{
instructors: [
{ firstName: "Prof.", lastName: "Thraka" },
],
},
],
},
],
},
],
},
{
junk: "nada",
subject: "gork",
catalogNbr: "2110",
titleLong: "Advanced Study of Angry Fungi",
enrollGroups: [{
classSections: [
{ ssrComponent: "LEC", meetings: [{ instructors: [{ firstName: "Prof.", lastName: "Thraka" }, { firstName: "Prof.", lastName: "Urgok" }] }] },
],
}],
enrollGroups: [
{
classSections: [
{
ssrComponent: "LEC",
meetings: [
{
instructors: [
{ firstName: "Prof.", lastName: "Thraka" },
{ firstName: "Prof.", lastName: "Urgok" },
],
},
],
},
],
},
],
},
],
},
Expand All @@ -113,10 +155,14 @@ afterAll(async () => {
serverCloseHandle.close();
});

describe('tests', () => {
describe("tests", () => {
it("dbInit-db-works", async () => {
expect((await Subjects.findOne({ subShort: "gork" })).subShort).toBe("gork");
expect((await Classes.findOne({ classSub: "gork", classNum: "1110" })).classSub).toBe("gork");
expect((await Subjects.findOne({ subShort: "gork" })).subShort).toBe(
"gork",
);
expect(
(await Classes.findOne({ classSub: "gork", classNum: "1110" })).classSub,
).toBe("gork");
});

// Does the internal testing endpoint exist?
Expand All @@ -141,15 +187,21 @@ describe('tests', () => {

// Does fetching the classes collection work as expected?
it("fetching-classes-by-subject-works", async () => {
const response = await fetchClassesForSubject(testingEndpoint, "FA20", { descrformal: "The Study of AngryFungi", value: "gork" });
const response = await fetchClassesForSubject(testingEndpoint, "FA20", {
descrformal: "The Study of AngryFungi",
value: "gork",
});
expect(response.length).toBe(2);
expect(response[0].subject).toBe("gork");
expect(response[0].catalogNbr).toBe("1110");
expect(response[0].titleLong).toBe("Introduction to Angry Fungi");
expect(response[1].titleLong).toBe("Advanced Study of Angry Fungi");

// No fedn classes, only gork classes!
const nil = await fetchClassesForSubject(testingEndpoint, "FA20", { descrformal: "The Study of Where No One has Gone Before", value: "fedn" });
const nil = await fetchClassesForSubject(testingEndpoint, "FA20", {
descrformal: "The Study of Where No One has Gone Before",
value: "fedn",
});
expect(nil).toBeNull();
});

Expand All @@ -158,24 +210,35 @@ describe('tests', () => {
expect(worked).toBe(true);

// did it add the fedn subject?
expect((await Subjects.findOne({ subShort: "fedn" }).exec()).subFull).toBe("The Study of Where No One has Gone Before");
expect((await Subjects.findOne({ subShort: "fedn" }).exec()).subFull).toBe(
"The Study of Where No One has Gone Before",
);

// did it update the semesters on gork 1110?
// notice the .lean(), which changes some of the internals of what mongo returns
const class1 = await Classes.findOne({ classSub: "gork", classNum: "1110" }).lean().exec();
const class1 = await Classes.findOne({ classSub: "gork", classNum: "1110" })
.lean()
.exec();
expect(class1.classSems).toStrictEqual(["FA19", "FA20"]);

// did it add the gork 2110 Class?
const class2 = await Classes.findOne({ classSub: "gork", classNum: "2110" }).exec();
const class2 = await Classes.findOne({
classSub: "gork",
classNum: "2110",
}).exec();
expect(class2.classTitle).toBe("Advanced Study of Angry Fungi");

// Did it update the classes for the first professor
const prof1 = await Professors.findOne({ fullName: "Prof. Thraka" }).lean().exec();
const prof1 = await Professors.findOne({ fullName: "Prof. Thraka" })
.lean()
.exec();
expect(prof1.courses).toContain(class1._id);
expect(prof1.courses).toContain(class2._id);

// Did it add the second professor with the right class id?
const prof2 = await Professors.findOne({ fullName: "Prof. Urgok" }).lean().exec();
const prof2 = await Professors.findOne({ fullName: "Prof. Urgok" })
.lean()
.exec();
expect(prof2.courses).toStrictEqual([class2._id]);
});
});
Loading