File tree Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Expand file tree Collapse file tree 1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change 1+ const connector = require ( "#models/databaseUtil" ) ;
2+
3+ const groupSchema = {
4+ groupName : { type : String , required : true } ,
5+ studentIds : { type : [ Number ] , required : true } ,
6+ } ;
7+
8+ const groupModel = new connector . model ( "group" , groupSchema ) ;
9+
10+ async function createGroup ( groupData ) {
11+ try {
12+ const newGroup = await groupModel . create ( groupData ) ;
13+ return newGroup ;
14+ } catch ( error ) {
15+ console . error ( "Error creating group:" , error ) ;
16+ return null ;
17+ }
18+ }
19+
20+ async function getGroupById ( groupId ) {
21+ try {
22+ const group = await groupModel . findById ( groupId ) ;
23+ return group ;
24+ } catch ( error ) {
25+ console . error ( "Error retrieving group:" , error ) ;
26+ return null ;
27+ }
28+ }
29+
30+ async function updateGroup ( groupId , updateData ) {
31+ try {
32+ const updatedGroup = await groupModel . findByIdAndUpdate ( groupId , updateData , { new : true } ) ;
33+ return updatedGroup ;
34+ } catch ( error ) {
35+ console . error ( "Error updating group:" , error ) ;
36+ return null ;
37+ }
38+ }
39+
40+ async function deleteGroup ( groupId ) {
41+ try {
42+ const deletedGroup = await groupModel . findByIdAndDelete ( groupId ) ;
43+ return deletedGroup ;
44+ } catch ( error ) {
45+ console . error ( "Error deleting group:" , error ) ;
46+ return null ;
47+ }
48+ }
49+
50+ module . exports = {
51+ createGroup,
52+ getGroupById,
53+ updateGroup,
54+ deleteGroup,
55+ } ;
You can’t perform that action at this time.
0 commit comments