# Issue #297: Implement actual query processing

## Objective

Route federation queries to actual domain services (tasks, events, projects) instead of returning placeholder data.

## Current State

- Query message type returns placeholder: `{ message: "Query received and processed" }`
- Location: `apps/api/src/federation/query.service.ts:167-169`
- Blocks dashboard from showing real federated data (#92)

## Approach

1. Create query parser to extract intent and parameters from query string
2. Route to appropriate service based on query type
3. Return actual data from services
4. Add authorization checks (workspace-scoped)
5. Add comprehensive tests

## Query Types to Support

1. **Tasks** - "get tasks", "show my tasks", "tasks in progress"
2. **Events** - "upcoming events", "calendar this week", "show events"
3. **Projects** - "active projects", "show projects", "project status"

## Implementation Plan

- [x] Create scratchpad
- [x] Write tests for query processing (TDD)
- [x] Implement query parser
- [x] Route queries to services
- [x] Update handleIncomingQuery to use real data
- [x] Add TasksService, EventsService, ProjectsService to QueryService
- [x] Update FederationModule to import required modules
- [x] All tests passing (20/20)
- [x] Type check passing
- [ ] Test with actual federation connection (deferred to #298)
- [ ] Verify dashboard shows real data (deferred to #298)

## Changes Made

### query.service.ts

Added actual query processing:

- Imported TasksService, EventsService, ProjectsService
- Added `processQuery()` method - routes queries to appropriate services
- Added `parseQueryType()` method - extracts query type from string
- Added `parseQueryParams()` method - extracts parameters from context
- Added `processTasksQuery()`, `processEventsQuery()`, `processProjectsQuery()` methods
- Modified `handleIncomingQuery()` to call `processQuery()` instead of placeholder

### query.service.spec.ts

Added 5 new tests:

- should process 'get tasks' query and return tasks data
- should process 'get events' query and return events data
- should process 'get projects' query and return projects data
- should handle unknown query type gracefully
- should enforce workspace context in queries

All 20 tests passing.

### federation.module.ts

- Added QueryService to providers and exports
- Imported TasksModule, EventsModule, ProjectsModule

## Testing Strategy

1. Unit tests for query parser
2. Integration tests for service routing
3. E2E tests with federation connection
4. Security tests for workspace isolation

## Notes

- Must use workspace context for RLS
- Parser should be extensible for future query types
- Error handling for malformed queries
- Consider caching frequently requested queries
