1
1
var model = require ( './../Models/model.js' )
2
+ const fs = require ( 'fs' ) ;
3
+
2
4
3
5
var methods = { }
4
6
@@ -53,7 +55,8 @@ methods.addCourse = function (courseID, courseName, imageUrl) {
53
55
}
54
56
55
57
methods . addCourseData = function ( courseID , courseName , topicName , courseData , videolink ) {
56
- return model . fun . checkCourse ( courseID ) . then ( flag => {
58
+ return model . fun . checkCourse ( courseName ) . then ( flag => {
59
+ console . log ( flag ) ;
57
60
if ( courseID == flag . courseid ) {
58
61
return model . fun . addCourseData ( courseID , topicName , courseData , videolink ) . then ( result => {
59
62
return Promise . resolve ( {
@@ -85,35 +88,72 @@ methods.getCourse = function () {
85
88
} )
86
89
} )
87
90
}
88
- methods . getCourseData = function ( courseName ) {
89
- return model . fun . checkCourse ( courseName ) . then ( flag => {
90
- return model . fun . getCourseData ( flag . courseid ) . then ( result => {
91
+ methods . getCourseData = function ( courseName ) {
92
+ return model . fun . checkCourse ( courseName ) . then ( flag => {
93
+ return model . fun . getCourseData ( flag . courseid ) . then ( result => {
91
94
var data = { } ;
92
95
var count = 0 ;
93
- for ( let val of result ) {
96
+ for ( let val of result ) {
94
97
data [ count ] = val . section ;
95
98
count = count + 1 ;
96
99
}
97
100
return Promise . resolve ( data ) ;
98
101
} )
99
102
} )
100
- . catch ( error => {
101
- return Promise . reject ( { "message" : "course not found" } )
102
- } )
103
+ . catch ( error => {
104
+ return Promise . reject ( { "message" : "course not found" } )
105
+ } )
103
106
}
104
- methods . getSectionData = function ( courseName , section ) {
105
- return model . fun . checkCourse ( courseName ) . then ( flag => {
106
- return model . fun . getSectionData ( flag . courseid , section ) . then ( result => {
107
- console . log ( "SECTION RESULT" , result ) ;
108
-
109
- return Promise . resolve ( { "data" :result . data , "link" :result . videoLink } ) ;
107
+ methods . getSectionData = function ( courseName , section ) {
108
+ return model . fun . checkCourse ( courseName ) . then ( flag => {
109
+ return model . fun . getSectionData ( flag . courseid , section ) . then ( result => {
110
+ console . log ( "SECTION RESULT" , result ) ;
111
+
112
+ return Promise . resolve ( { "data" : result . data , "link" : result . videoLink } ) ;
110
113
} )
111
- . catch ( error => {
112
- return Promise . reject ( { "message" :"error in section data" } )
114
+ . catch ( error => {
115
+ return Promise . reject ( { "message" : "error in section data" } )
116
+ } )
117
+ } )
118
+ . catch ( error => {
119
+ return Promise . reject ( { "message" : "cannot find the course" } )
120
+ } )
121
+ }
122
+ methods . deleteCourse = function ( courseName ) {
123
+ return model . fun . checkCourse ( courseName ) . then ( flag => {
124
+ return model . fun . deleteCourse ( flag . courseid ) . then ( result => {
125
+ fs . unlink ( flag . imageurl , ( err ) => {
126
+ if ( err ) return Promise . resolve ( { "message" : "error in file deleting" } ) ;
127
+ console . log ( "Successfully file deleted" ) ;
128
+ } )
129
+ return Promise . resolve ( { "message" : "successfully deleted" } )
113
130
} )
131
+ . catch ( error => {
132
+ return Promise . reject ( { "message" : "error in delete course" } )
133
+ } )
114
134
} )
115
- . catch ( error => {
116
- return Promise . reject ( { "message" :"error in check the course" } )
135
+ . catch ( error => {
136
+ return Promise . reject ( { "message" : "cannot find the course" } )
137
+ } )
138
+ }
139
+ methods . updateSection = function ( courseName , topicName , courseData , videolink ) {
140
+ return model . fun . checkCourse ( courseName ) . then ( flag => {
141
+ console . log ( flag ) ;
142
+ return model . fun . updateCourseData ( flag . courseid , topicName , courseData , videolink ) . then ( result => {
143
+ return Promise . resolve ( {
144
+ "message" : "course data successfully updated"
145
+ } ) ;
146
+ } )
147
+ . catch ( error => {
148
+ console . log ( error ) ;
149
+ return Promise . reject ( {
150
+ "message" : "failure"
151
+ } ) ;
152
+ } )
153
+
117
154
} )
155
+ . catch ( error => {
156
+ return Promise . reject ( { "message" : "course not found" } )
157
+ } )
118
158
}
119
- exports . cont = methods ;
159
+ exports . cont = methods ;
0 commit comments