File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -53,4 +53,12 @@ mutation {
5353 teacher
5454 }
5555}
56+ ```
57+
58+ * Mutation Delete
59+
60+ ```
61+ mutation {
62+ deleteCourse(_id: "5d49a689956e731fb00367f1")
63+ }
5664```
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ module.exports = {
6868 { _id : ObjectID ( _id ) } ,
6969 { $set : input }
7070 )
71-
71+
7272 student = await db . collection ( 'students' ) . findOne (
7373 { _id : ObjectID ( _id ) }
7474 )
@@ -77,5 +77,41 @@ module.exports = {
7777 }
7878
7979 return student
80+ } ,
81+ deleteCourse : async ( root , { _id } ) => {
82+ let db
83+ let info
84+
85+ try {
86+ db = await connectDb ( )
87+
88+ info = await db . collection ( 'courses' ) . deleteOne ( {
89+ _id : ObjectID ( _id )
90+ } )
91+ } catch ( error ) {
92+ console . error ( error )
93+ }
94+
95+ return info . deletedCount
96+ ? `El curso con id ${ _id } fue eliminado exitosamente.`
97+ : 'No existe el curso con el id indicado'
98+ } ,
99+ deleteStudent : async ( root , { _id } ) => {
100+ let db
101+ let info
102+
103+ try {
104+ db = await connectDb ( )
105+
106+ info = await db . collection ( 'students' ) . deleteOne ( {
107+ _id : ObjectID ( _id )
108+ } )
109+ } catch ( error ) {
110+ console . error ( error )
111+ }
112+
113+ return info . deletedCount
114+ ? `El estudiante con id ${ _id } fue eliminado exitosamente.`
115+ : 'No existe el estudiante con el id indicado'
80116 }
81117}
Original file line number Diff line number Diff line change @@ -53,8 +53,12 @@ type Mutation {
5353 createCourse (input : CourseInput ! ): Course
5454 "Edita un curso"
5555 editCourse (_id : ID ! , input : CourseEditInput ): Course
56+ "Elimina un curso"
57+ deleteCourse (_id : ID ! ): String
5658 "Crea un estudiante"
5759 createStudent (input : StudentInput ! ): Student
5860 "Edita un estudiante"
5961 editStudent (_id : ID ! , input : StudentEditInput ): Student
62+ "Elimina un estudiante"
63+ deleteStudent (_id : ID ! ): String
6064}
You can’t perform that action at this time.
0 commit comments