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

[CREATED] Created model for student and added CURD #299

Closed
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
12 changes: 0 additions & 12 deletions models/paper.js

This file was deleted.

53 changes: 53 additions & 0 deletions models/student.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import connector from "#models/databaseUtil";

const studentSchema = {
ERPID: { type: String, required: true },
name: { type: String, required: true },
joiningYear: { type: Number, required: true },
branch: { type: connector.Schema.Types.ObjectId, ref: "Department", required: true },
division: { type: String, enum: ["A", "B", "C"], default: "A" },
rollNo: { type: Number, required: true },
coursesOpted: [{ type: connector.Schema.Types.ObjectId, ref: "Course", required: true }],
};

// eslint-disable-next-line no-unused-vars

const Student = connector.model("Student", studentSchema);

// CRUD OPERATIONS

async function remove(filter) {
const deleteResult = await Student.deleteMany(filter);
return deleteResult.acknowledged;
}

async function create(studentData) {
const {
ERPID, name, joiningYear, branch, division, rollNo, coursesOpted,
} = studentData;
const student = new Student({
ERPID,
name,
joiningYear,
branch,
division,
rollNo,
coursesOpted,
});
const studentDoc = await student.save();
return studentDoc;
}

async function read(filter, limit = 1) {
const studentDoc = await Student.find(filter).limit(limit);
return studentDoc;
}

async function update(filter, updateObject, options = { multi: true }) {
const updateResult = await Student.updateMany(filter, { $set: updateObject }, options);
return updateResult.acknowledged;
}

export default {
create, read, update, remove,
};
Loading