Skip to content

Commit f88a7b9

Browse files
committed
[Added]changes to 115- Refactor Group model
1 parent d23d09f commit f88a7b9

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

models/group.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
import connector from "#models/databaseUtil";
22

33
const groupSchema = {
4-
groupName: { type: String, required: true },
5-
studentIds: { type: [Number], required: true },
4+
title: { type: String, required: true },
5+
student: { type: connector.Schema.Types.ObjectId, ref: "Student", required: true }
66
};
77

8+
89
const groupModel = connector.model("group", groupSchema);
910

10-
async function createGroup(groupData) {
11+
async function create(title,student) {
1112
try {
12-
const newGroup = await groupModel.create(groupData);
13+
const newGroup = await groupModel.create(title , student);
1314
return newGroup;
1415
} catch (error) {
1516
console.error("Error creating group:", error);
1617
return null;
1718
}
1819
}
1920

20-
async function getGroupById(groupId) {
21+
async function read(groupId) {
2122
try {
2223
const group = await groupModel.findById(groupId);
2324
return group;
@@ -27,7 +28,7 @@ async function getGroupById(groupId) {
2728
}
2829
}
2930

30-
async function updateGroup(groupId, updateData) {
31+
async function update(groupId, updateData) {
3132
try {
3233
const updatedGroup = await groupModel.findByIdAndUpdate(groupId, updateData, { new: true });
3334
return updatedGroup;
@@ -36,8 +37,7 @@ async function updateGroup(groupId, updateData) {
3637
return null;
3738
}
3839
}
39-
40-
async function deleteGroup(groupId) {
40+
async function remove(groupId) {
4141
try {
4242
const deletedGroup = await groupModel.findByIdAndDelete(groupId);
4343
return deletedGroup;
@@ -47,9 +47,10 @@ async function deleteGroup(groupId) {
4747
}
4848
}
4949

50+
5051
export default {
51-
createGroup,
52-
getGroupById,
53-
updateGroup,
54-
deleteGroup,
52+
create,
53+
read,
54+
update,
55+
remove,
5556
};

0 commit comments

Comments
 (0)