Fixed bug for displaying sign ups for shifts
This commit is contained in:
@@ -16,18 +16,40 @@ class ShiftsController {
|
||||
|
||||
logger.info('Loading public shifts from:', config.nocodb.shiftsSheetId);
|
||||
|
||||
// Load all shifts without filter - we'll filter in JavaScript
|
||||
const response = await nocodbService.getAll(config.nocodb.shiftsSheetId, {
|
||||
sort: 'Date,Start Time'
|
||||
});
|
||||
|
||||
logger.info('Loaded shifts:', response);
|
||||
|
||||
// Filter out cancelled shifts manually
|
||||
const shifts = (response.list || []).filter(shift =>
|
||||
let shifts = (response.list || []).filter(shift =>
|
||||
shift.Status !== 'Cancelled'
|
||||
);
|
||||
|
||||
// If signups sheet is configured, calculate current volunteer counts
|
||||
if (config.nocodb.shiftSignupsSheetId) {
|
||||
try {
|
||||
const signupsResponse = await nocodbService.getAll(config.nocodb.shiftSignupsSheetId);
|
||||
const allSignups = signupsResponse.list || [];
|
||||
|
||||
// Update each shift with calculated volunteer count
|
||||
shifts = shifts.map(shift => {
|
||||
const confirmedSignups = allSignups.filter(signup =>
|
||||
signup['Shift ID'] === shift.ID && signup.Status === 'Confirmed'
|
||||
);
|
||||
|
||||
const currentVolunteers = confirmedSignups.length;
|
||||
const maxVolunteers = shift['Max Volunteers'] || 0;
|
||||
|
||||
return {
|
||||
...shift,
|
||||
'Current Volunteers': currentVolunteers,
|
||||
'Status': currentVolunteers >= maxVolunteers ? 'Full' : 'Open'
|
||||
};
|
||||
});
|
||||
} catch (signupError) {
|
||||
logger.warn('Could not load signups for volunteer count calculation:', signupError);
|
||||
}
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
shifts: shifts
|
||||
|
||||
Reference in New Issue
Block a user