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

Implemented CRUD and created service for Student College details #378

Merged
Merged
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
124 changes: 124 additions & 0 deletions models/student/stdCollege.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import connector from "#models/databaseUtil";

const studentCollegeSchema = {
uid: {
type: String,
required: true,
unique: true,
},
admissionYear: {
type: String,
required: true,
},
studentCode: {
type: String,
},
rollNo: {
type: String,
},
admissionStatus: {
type: String,
required: true,
},
admissionPattern: {
type: String,
},
admissionCategory: {
type: String,
required: true,
},
seatDesc: {
type: String,
},
quotaType: {
type: String,
required: true,
},
isBoarderStudent: {
type: Boolean,
},
seatType: {
type: String,
required: true,
},
seatSubType: {
type: String,
required: true,
},
eligibilityNo: {
type: String,
required: true,
},
enrollmentNo: {
type: String,
required: true,
unique: true,
},
};

const StudentCollege = connector.model("Student college", studentCollegeSchema);

async function create(studentCollegeData) {
const {
uid,
admissionYear,
studentCode,
rollNo,
admissionStatus,
admissionPattern,
admissionCategory,
seatDesc,
quotaType,
isBoarderStudent,
seatType,
seatSubType,
eligibilityNo,
enrollmentNo,
} = studentCollegeData;

const stdCollege = new StudentCollege({
uid,
admissionYear,
studentCode,
rollNo,
admissionStatus,
admissionPattern,
admissionCategory,
seatDesc,
quotaType,
isBoarderStudent,
seatType,
seatSubType,
eligibilityNo,
enrollmentNo,
});

const stdCollegeDoc = await stdCollege.save();
return stdCollegeDoc;
}

async function read(filter, limit = 1) {
const stdCollegeDoc = studentCollegeSchema.find(filter).limit(limit);
return stdCollegeDoc;
}

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

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

export default {
create,
read,
update,
remove,
};
60 changes: 0 additions & 60 deletions models/student/std_college.js

This file was deleted.

61 changes: 61 additions & 0 deletions services/student/stdCollege.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import StudentCollege from "#models/student/stdCollege";
import databaseError from "#error/database";

export async function createStudentCollege(
uid,
admissionYear,
studentCode,
rollNo,
admissionStatus,
admissionPattern,
admissionCategory,
seatDesc,
quotaType,
isBoarderStudent,
seatType,
seatSubType,
eligibilityNo,
enrollmentNo,
) {
const newStudentCollege = await StudentCollege.create({
uid,
admissionYear,
studentCode,
rollNo,
admissionStatus,
admissionPattern,
admissionCategory,
seatDesc,
quotaType,
isBoarderStudent,
seatType,
seatSubType,
eligibilityNo,
enrollmentNo,
});
if (newStudentCollege.uid === uid) {
return newStudentCollege;
}
throw new databaseError.DataEntryError("student college");
}

export async function updateStudentCollegeById(id, data) {
const updated = await StudentCollege.update({ _id: id }, data);
if (updated) {
return updated;
}
throw new databaseError.DataEntryError("student college");
}

export async function studentCollegeList(filter) {
const studentColleges = await StudentCollege.read(filter, 0);
return studentColleges;
}

export async function deleteStudentCollegeById(studentCollegeId) {
const deleted = await StudentCollege.remove({ _id: studentCollegeId });
if (deleted) {
return deleted;
}
throw new databaseError.DataDeleteError("student college");
}