@@ -22,7 +22,9 @@ module.exports = {
22
22
notification . content = `${ event . eventName } is added!`
23
23
notification . tag = 'New!'
24
24
notificationHelper . addToNotificationForAll ( req , res , notification , next )
25
+ res . locals . data = event
25
26
res . status ( HttpStatus . CREATED ) . json ( { event : event } )
27
+ next ( )
26
28
} catch ( error ) {
27
29
res . status ( HttpStatus . BAD_REQUEST ) . json ( { error : error } )
28
30
}
@@ -53,7 +55,9 @@ module.exports = {
53
55
notification . content = `${ event . eventName } is updated!`
54
56
notification . tag = 'Update'
55
57
notificationHelper . addToNotificationForAll ( req , res , notification , next )
58
+ res . locals . data = event
56
59
res . status ( HttpStatus . OK ) . json ( { event : event } )
60
+ next ( )
57
61
} catch ( error ) {
58
62
HANDLER . handleError ( res , error )
59
63
}
@@ -84,10 +88,12 @@ module.exports = {
84
88
try {
85
89
event . rsvpYes . push ( req . user . id )
86
90
await event . save ( )
91
+ res . locals . data = event
87
92
req . io . emit ( 'rsvp done' , { data : 'RSVP successfully done!' } )
88
93
notification . heading = 'RSVP done!'
89
94
notification . content = 'RSVP successfully done!'
90
95
notificationHelper . addToNotificationForUser ( req . user . _id , res , notification , next )
96
+ next ( )
91
97
res . status ( HttpStatus . OK ) . json ( { rsvpData : data } )
92
98
} catch ( error ) {
93
99
return res . status ( HttpStatus . BAD_REQUEST ) . json ( { error : error } )
@@ -97,10 +103,12 @@ module.exports = {
97
103
try {
98
104
event . rsvpNo . push ( req . user . id )
99
105
await event . save ( )
106
+ res . locals . data = event
100
107
req . io . emit ( 'rsvp done' , { data : 'RSVP successfully done!' } )
101
108
notification . heading = 'RSVP done!'
102
109
notification . content = 'RSVP successfully done!'
103
110
notificationHelper . addToNotificationForUser ( req . user . _id , res , notification , next )
111
+ next ( )
104
112
res . status ( HttpStatus . OK ) . json ( { rsvpData : data } )
105
113
} catch ( error ) {
106
114
return res . status ( HttpStatus . BAD_REQUEST ) . json ( { error : error } )
@@ -110,11 +118,13 @@ module.exports = {
110
118
try {
111
119
event . rsvpMaybe . push ( req . user . id )
112
120
await event . save ( )
121
+ res . locals . data = event
113
122
req . io . emit ( 'rsvp done' , { data : 'RSVP successfully done!' } )
114
123
notification . heading = 'RSVP done!'
115
124
notification . content = 'RSVP successfully done!'
116
125
notificationHelper . addToNotificationForUser ( req . user . _id , res , notification , next )
117
126
res . status ( HttpStatus . OK ) . json ( { rsvpData : data } )
127
+ next ( )
118
128
} catch ( error ) {
119
129
return res . status ( HttpStatus . BAD_REQUEST ) . json ( { error : error } )
120
130
}
@@ -158,12 +168,14 @@ module.exports = {
158
168
}
159
169
if ( permission . check ( req , res , deleteEvent . createdBy ) ) {
160
170
await Event . findByIdAndRemove ( id )
171
+ res . locals . data = event
161
172
req . io . emit ( 'event deleted' , { data : deleteEvent . eventName } )
162
173
notification . heading = 'Event deleted!'
163
174
notification . content = `Event ${ deleteEvent . eventName } is deleted!`
164
175
notification . tag = 'Deleted'
165
176
notificationHelper . addToNotificationForAll ( req , res , notification , next )
166
- return res . status ( HttpStatus . OK ) . json ( { deleteEvent : deleteEvent , message : 'Deleted the event' } )
177
+ res . status ( HttpStatus . OK ) . json ( { deleteEvent : deleteEvent , message : 'Deleted the event' } )
178
+ next ( )
167
179
}
168
180
return res . status ( HttpStatus . BAD_REQUEST ) . json ( { msg : 'Not permitted!' } )
169
181
} catch ( error ) {
0 commit comments