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

Data models #4

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions server/schemas/admin.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import mongoose from "mongoose";
import { accesses } from "../utils/constants";

const adminSchema = new mongoose.Schema({
webmail: {
type: String,
unique: true,
},
description: String,
isStudent: {
type: Boolean,
default: false,
},
access: [
{
type: String,
enum: accesses,
},
],
});

export const Admin = mongoose.model("Admin", adminSchema);
export type Admin = typeof Admin;
17 changes: 17 additions & 0 deletions server/schemas/constant.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import mongoose from "mongoose";

const constantSchema = new mongoose.Schema({
constKey: {
type: String,
unique: true,
},
description: String,
type: {
type: String,
enum: ["Number", "String", "Object", "Array"],
},
value: mongoose.Schema.Types.Mixed,
});

export const Constant = mongoose.model("Constant", constantSchema);
export type Constant = typeof Constant;
24 changes: 24 additions & 0 deletions server/schemas/mess.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import mongoose from "mongoose";
import { batches } from "../utils/constants";

const messSchema = new mongoose.Schema({
messName: {
type: String,
unique: true,
},
population: {
type: Number,
default: 0,
},
capacity: Number,
location: [String],
rating: Number,
batch: {
type: String,
enum: batches,
},
hostelNames: [String],
});

export const Mess = mongoose.model("Mess", messSchema);
export type Mess = typeof Mess;
18 changes: 18 additions & 0 deletions server/schemas/messReview.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import mongoose from "mongoose";

const messReviewSchema = new mongoose.Schema({
messID: {
type: mongoose.Schema.Types.ObjectId,
ref: "Mess",
},
userID: {
type: mongoose.Schema.Types.ObjectId,
ref: "User",
},
comment: String,
rating: Number,
time: Date,
});

export const MessReview = mongoose.model("MessReview", messReviewSchema);
export type MessReview = typeof MessReview;
15 changes: 15 additions & 0 deletions server/schemas/userDetail.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import mongoose from "mongoose";

const userDetailSchema = new mongoose.Schema({
rollNumber: {
type: Number,
required: true,
unique: true,
},
name: String,
hostelName: String,
roomNumber: Number,
});

export const UserDetail = mongoose.model("UserDetail", userDetailSchema);
export type UserDetail = typeof UserDetail;
22 changes: 22 additions & 0 deletions server/schemas/userMessDetail.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import mongoose from "mongoose";

const userMessDetailSchema = new mongoose.Schema({
messID: {
type: mongoose.Schema.Types.ObjectId,
ref: "Mess",
},
messPreference: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Mess",
},
],
messRegistrationTime: Date,
isEligibleForRegistering: Boolean,
});

export const UserMessDetail = mongoose.model(
"UserMessDetail",
userMessDetailSchema
);
export type UserMessDetail = typeof UserMessDetail;
9 changes: 8 additions & 1 deletion server/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,11 @@ const batches = [

const genders = ["MALE", "FEMALE"];

export { batches, genders };
const accesses = [
"GetMessList",
"GetMessUnallottedUsers",
"OpenOrCloseMessRegistration",
"MessAllotment",
];

export { batches, genders, accesses };