@@ -14,15 +14,24 @@ router.post("/delayNotification", async (req, res) => {
1414 ! tripID ||
1515 typeof tripID !== "string"
1616 ) {
17- return res . status ( 400 ) . json ( { error : "Invalid input parameters" } ) ;
17+ return res . status ( 400 ) . json ( {
18+ success : false ,
19+ data : "Invalid input parameters"
20+ } ) ;
1821 }
1922
2023 try {
2124 NotificationUtils . addDelayNotification ( tripID , stopID , deviceToken ) ;
22- res . status ( 200 ) . json ( { success : "successfully sent delay notification" } ) ;
25+ res . status ( 200 ) . json ( {
26+ success : true ,
27+ data : "successfully registered delay notification"
28+ } ) ;
2329 } catch ( error ) {
2430 console . error ( "Error setting up delay notification:" , error . message ) ;
25- res . status ( 500 ) . json ( { error : "Failed to set up delay notification" } ) ;
31+ res . status ( 500 ) . json ( {
32+ success : false ,
33+ data : "Failed to set up delay notification"
34+ } ) ;
2635 }
2736} ) ;
2837
@@ -37,17 +46,24 @@ router.post("/cancelDelayNotification", async (req, res) => {
3746 ! stopID ||
3847 typeof stopID !== "string"
3948 ) {
40- return res . status ( 400 ) . json ( { error : "Invalid input parameters" } ) ;
49+ return res . status ( 400 ) . json ( {
50+ success : false ,
51+ data : "Invalid input parameters"
52+ } ) ;
4153 }
4254
4355 try {
4456 NotificationUtils . deleteDelayNotification ( tripID , stopID , deviceToken ) ;
45- res
46- . status ( 200 )
47- . json ( { success : "successfully cancelled delay notification" } ) ;
57+ res . status ( 200 ) . json ( {
58+ success : true ,
59+ data : "successfully cancelled delay notification"
60+ } ) ;
4861 } catch ( error ) {
4962 console . error ( "Error canceling delay notification:" , error . message ) ;
50- res . status ( 500 ) . json ( { error : "Failed to cancel delay notification" } ) ;
63+ res . status ( 500 ) . json ( {
64+ success : false ,
65+ data : "Failed to cancel delay notification"
66+ } ) ;
5167 }
5268} ) ;
5369
@@ -63,7 +79,10 @@ router.post("/departureNotification", async (req, res) => {
6379 ! startTime ||
6480 typeof startTime !== "string"
6581 ) {
66- return res . status ( 400 ) . json ( { error : "Invalid input parameters" } ) ;
82+ return res . status ( 400 ) . json ( {
83+ success : false ,
84+ data : "Invalid input parameters"
85+ } ) ;
6786 }
6887
6988 // Call the utility function to set up the departure notification
@@ -73,12 +92,16 @@ router.post("/departureNotification", async (req, res) => {
7392 ) ;
7493
7594 // Respond with the result
76- res
77- . status ( 200 )
78- . json ( { sucess : "successfully sent departure notification" } ) ;
95+ res . status ( 200 ) . json ( {
96+ success : true ,
97+ data : "successfully scheduled departure notification"
98+ } ) ;
7999 } catch ( error ) {
80100 console . error ( "Error setting up departure notification:" , error . message ) ;
81- res . status ( 500 ) . json ( { error : "Failed to set up departure notification" } ) ;
101+ res . status ( 500 ) . json ( {
102+ success : false ,
103+ data : "Failed to set up departure notification"
104+ } ) ;
82105 }
83106} ) ;
84107
@@ -94,7 +117,10 @@ router.post("/cancelDepartureNotification", async (req, res) => {
94117 ! startTime ||
95118 typeof startTime !== "string"
96119 ) {
97- return res . status ( 400 ) . json ( { error : "Invalid input parameters" } ) ;
120+ return res . status ( 400 ) . json ( {
121+ success : false ,
122+ data : "Invalid input parameters"
123+ } ) ;
98124 }
99125
100126 // Call the utility function to cancel the departure notification
@@ -104,12 +130,16 @@ router.post("/cancelDepartureNotification", async (req, res) => {
104130 ) ;
105131
106132 // Respond with the result
107- res
108- . status ( 200 )
109- . json ( { sucess : "successfully canceled departure notification" } ) ;
133+ res . status ( 200 ) . json ( {
134+ success : true ,
135+ data : "successfully canceled departure notification"
136+ } ) ;
110137 } catch ( error ) {
111138 console . error ( "Error canceling departure notification:" , error . message ) ;
112- res . status ( 500 ) . json ( { error : "Failed to cancel departure notification" } ) ;
139+ res . status ( 500 ) . json ( {
140+ success : false ,
141+ data : "Failed to cancel departure notification"
142+ } ) ;
113143 }
114144} ) ;
115145
@@ -124,7 +154,10 @@ router.post("/microserviceNotif", async (req, res) => {
124154 ! routeID ||
125155 typeof routeID !== "string"
126156 ) {
127- return res . status ( 400 ) . json ( { error : "Invalid input parameters" } ) ;
157+ return res . status ( 400 ) . json ( {
158+ success : false ,
159+ data : "Invalid input parameters"
160+ } ) ;
128161 }
129162
130163 // Send the notification
@@ -133,12 +166,16 @@ router.post("/microserviceNotif", async (req, res) => {
133166 `The bus on ${ routeID } is delayed` ,
134167 "testBody"
135168 ) ;
136- return res
137- . status ( 200 )
138- . json ( { success : "successfully sent microservice notification" } ) ;
169+ return res . status ( 200 ) . json ( {
170+ success : true ,
171+ data : "successfully sent microservice notification"
172+ } ) ;
139173 } catch ( error ) {
140174 console . error ( "Error sending notification:" , error . message ) ;
141- res . status ( 500 ) . json ( { error : "Failed to send notification" } ) ;
175+ res . status ( 500 ) . json ( {
176+ success : false ,
177+ data : "Failed to send notification"
178+ } ) ;
142179 }
143180} ) ;
144181
0 commit comments