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