Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions controllers/client/utsavBooking.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
} from '../../config/constants.js';
import {
UtsavBooking,
UtsavDb,
UtsavPackagesDb
UtsavDb
} from '../../models/associations.js';
import { userCancelBooking } from '../../helpers/transactions.helper.js';
import { openUtsavSeat, sendUtsavBookingUpdateEmail } from '../../helpers/utsavBooking.helper.js';
Expand All @@ -23,7 +22,7 @@ export const FetchUpcoming = async (req, res) => {

const page = parseInt(req.query.page) || 1;
const pageSize = parseInt(req.query.page_size) || 10;
Comment on lines 23 to 24
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pagination offset math changed here, and FetchUpcoming now has new behavior for utsavs with no packages. There are integration tests for other booking controllers under tests/controllers/client/, but none for this controller; adding coverage for non-overlapping page results and packages: [] when no packages exist would help prevent regressions.

Suggested change
const page = parseInt(req.query.page) || 1;
const pageSize = parseInt(req.query.page_size) || 10;
const rawPage = parseInt(req.query.page, 10);
const rawPageSize = parseInt(req.query.page_size, 10);
const page = Number.isNaN(rawPage) || rawPage < 1 ? 1 : rawPage;
const DEFAULT_PAGE_SIZE = 10;
const MAX_PAGE_SIZE = 100;
const pageSizeUnclamped = Number.isNaN(rawPageSize) || rawPageSize < 1 ? DEFAULT_PAGE_SIZE : rawPageSize;
const pageSize = Math.min(pageSizeUnclamped, MAX_PAGE_SIZE);

Copilot uses AI. Check for mistakes.
const offset = (page - 1) * (pageSize - 1);
const offset = (page - 1) * pageSize;

const utsavs = await database.query(
`
Expand All @@ -35,17 +34,17 @@ export const FetchUpcoming = async (req, res) => {
t1.location AS utsav_location,
t1.status AS utsav_status,
t1.registration_deadline AS registration_deadline,
JSON_ARRAYAGG(
IF(COUNT(t2.id) = 0, JSON_ARRAY(), JSON_ARRAYAGG(
JSON_OBJECT(
'package_id', t2.id,
'package_name', t2.name,
'package_start', t2.start_date,
'package_end', t2.end_date,
'package_amount', t2.amount
)
) AS packages
)) AS packages
FROM utsav_db t1
JOIN utsav_packages_db t2 ON t1.id = t2.utsavid
LEFT JOIN utsav_packages_db t2 ON t1.id = t2.utsavid
Comment on lines +37 to +47
Copy link

Copilot AI Mar 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FetchUpcoming now includes utsavs with no packages via LEFT JOIN and returns packages as []. However FetchUtsavById in the same controller still uses an inner JOIN utsav_packages_db, so selecting an utsav from the upcoming list that has no packages will likely 404 on the details endpoint. Consider updating FetchUtsavById to also use LEFT JOIN and the same empty-array handling for packages to keep the API consistent.

Copilot uses AI. Check for mistakes.
WHERE t1.registration_deadline IS NULL OR t1.registration_deadline >= :today
GROUP BY t1.id
ORDER BY t1.start_date ASC
Expand Down
Loading