fix(events): Update NocoDB query syntax to match official API documentation
Build And Push Image / docker (push) Waiting to run Details

- Use btw (between) operator for date ranges instead of gte/lte
- Use proper ~or and ~and logical operators for complex conditions
- Use like operator with %wildcards% for search functionality
- Role-based filtering with correct OR conditions for board visibility
- All query syntax now matches official NocoDB v2 API documentation

This should resolve the 422 Unprocessable Entity errors by using the
correct query parameter format that NocoDB expects.
This commit is contained in:
Matt 2025-08-12 13:22:41 +02:00
parent 54a4f05c2a
commit c0c5ae6c44
1 changed files with 41 additions and 5 deletions

View File

@ -62,13 +62,49 @@ export function createNocoDBEventsClient() {
if (filters?.limit) queryParams.set('limit', filters.limit.toString());
if (filters?.offset) queryParams.set('offset', filters.offset.toString());
// Build where clause for filtering using simple NocoDB v2 syntax
// Start with just the status filter to test basic functionality
// Build where clause for filtering using correct NocoDB v2 syntax
const whereConditions: string[] = [];
if (filters?.start_date && filters?.end_date) {
// Date range filtering using btw (between) operator
whereConditions.push(`(start_datetime,btw,${filters.start_date},${filters.end_date})`);
}
if (filters?.event_type) {
whereConditions.push(`(event_type,eq,${filters.event_type})`);
}
if (filters?.visibility) {
whereConditions.push(`(visibility,eq,${filters.visibility})`);
} else if (filters?.user_role) {
// Role-based visibility filtering
if (filters.user_role === 'user') {
whereConditions.push(`(visibility,eq,public)`);
} else if (filters.user_role === 'board') {
// Board members can see public and board-only events
whereConditions.push(`~or((visibility,eq,public),(visibility,eq,board-only))`);
}
// Admin sees all events (no filter)
}
if (filters?.status) {
queryParams.set('where', `(status,eq,${filters.status})`);
whereConditions.push(`(status,eq,${filters.status})`);
} else {
// Default to active events only - test this simple query first
queryParams.set('where', `(status,eq,active)`);
// Default to active events only
whereConditions.push(`(status,eq,active)`);
}
if (filters?.search) {
// Search in title or description using like operator
whereConditions.push(`~or((title,like,%${filters.search}%),(description,like,%${filters.search}%))`);
}
// Combine conditions with ~and if multiple conditions exist
if (whereConditions.length > 0) {
const whereClause = whereConditions.length === 1
? whereConditions[0]
: `~and(${whereConditions.join(',')})`;
queryParams.set('where', whereClause);
}
// Sort by start date