Skip to content

Commit e0f7563

Browse files
committed
Fix activation banners dates
1 parent 2ece094 commit e0f7563

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

src/app.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ app.use(express.json());
2323

2424
app.use(checkJwt);
2525

26-
// TODO: We will remove this route after testing
27-
app.get("/debug-sentry", function mainHandler(req) {
28-
const { message = 'Test error message' } = req.query;
29-
throw new Error(`Sentry Test Error: ${message}`);
30-
});
31-
3226
app.use('/api/cities', cityRoutes);
3327
app.use('/api/faqs', faqRoutes);
3428
app.use('/api/services', serviceRoutes);

src/controllers/bannerController.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,20 @@ export const toggleBannerStatus = asyncHandler(async (req: Request, res: Respons
290290
if (StartDate !== undefined && StartDate !== null) {
291291
updateData.StartDate = new Date(StartDate);
292292
updateData.ShowDates = true;
293-
} else if (updateData.IsActive && !existingBanner.StartDate) {
293+
} else if (updateData.IsActive && !StartDate) {
294294
// If activating immediately without dates, set StartDate to now
295295
updateData.StartDate = new Date();
296-
updateData.ShowDates = true;
296+
updateData.EndDate = null;
297+
updateData.ShowDates = false;
297298
}
298299

299300
if (EndDate !== undefined && EndDate !== null) {
300301
updateData.EndDate = new Date(EndDate);
301-
updateData.ShowDates = true;
302302
} else if (!updateData.IsActive && !EndDate) {
303303
// If deactivating without explicit date, set EndDate to now
304+
updateData.StartDate = null;
304305
updateData.EndDate = new Date();
305-
updateData.ShowDates = true;
306+
updateData.ShowDates = false;
306307
}
307308

308309
// Update banner
@@ -315,6 +316,7 @@ export const toggleBannerStatus = asyncHandler(async (req: Request, res: Respons
315316
return sendSuccess(res, updatedBanner, `Banner ${updatedBanner?.IsActive ? 'activated' : 'deactivated'} successfully`);
316317
});
317318

319+
// TODO: Remove it if we are going to get "Downloads" from GA4
318320
// Increment download count for resource banners
319321
export const incrementDownloadCount = asyncHandler(async (req: Request, res: Response) => {
320322
const { id } = req.params;

src/controllers/swepBannerController.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,17 @@ export const toggleSwepBannerActive = asyncHandler(async (req: Request, res: Res
185185
// Handle date range for scheduled activation
186186
if (SwepActiveFrom !== undefined && SwepActiveFrom !== null) {
187187
updateData.SwepActiveFrom = new Date(SwepActiveFrom);
188-
} else if (updateData.IsActive && !existingSwep.SwepActiveFrom) {
188+
} else if (updateData.IsActive && !SwepActiveFrom) {
189189
// If activating immediately without dates, set SwepActiveFrom to now
190190
updateData.SwepActiveFrom = new Date();
191+
updateData.SwepActiveUntil = null;
191192
}
192193

193194
if (SwepActiveUntil !== undefined && SwepActiveUntil !== null) {
194195
updateData.SwepActiveUntil = new Date(SwepActiveUntil);
195196
} else if (!updateData.IsActive && !SwepActiveUntil) {
196197
// If deactivating without explicit date, set SwepActiveUntil to now
198+
updateData.SwepActiveFrom = null;
197199
updateData.SwepActiveUntil = new Date();
198200
}
199201

0 commit comments

Comments
 (0)