Aller au contenu principal

API Endpoint Migration Map: Strapi → NestJS

Migration Status Overview​

Purpose: Complete mapping of frontend API calls that need NestJS implementation
Priority: CRITICAL - Dev agent must implement missing endpoints before frontend integration
Context: Frontend currently uses Strapi API contracts, must migrate to NestJS

Frontend API Usage Analysis​

Authentication & User Management (CRITICAL - MISSING)​

Frontend ServiceCurrent Strapi EndpointRequired NestJS EndpointImplementation StatusPriority
User.find()GET /usersGET /api/users❌ MISSINGCRITICAL
User.getRoles()GET /users/meGET /api/users/me❌ MISSINGCRITICAL
Auth.login()POST /auth/localPOST /api/auth/login❌ MISSINGCRITICAL

Impact: Authentication completely broken without these endpoints

Core Business Entities​

Frontend ServiceCurrent Strapi EndpointRequired NestJS EndpointImplementation StatusPriority
Client.find()GET /clientsGET /api/clients✅ EXISTS✅ Complete
Client.findById()GET /clients/{id}GET /api/clients/{id}✅ EXISTS✅ Complete
Client.create()POST /clientsPOST /api/clients✅ EXISTS✅ Complete
Client.update()PUT /clients/{id}PUT /api/clients/{id}✅ EXISTS✅ Complete
Client.delete()DELETE /clients/{id}DELETE /api/clients/{id}✅ EXISTS✅ Complete

Sites Management​

Frontend ServiceCurrent Strapi EndpointRequired NestJS EndpointImplementation StatusPriority
Site.find()GET /sitesGET /api/sites❓ VERIFYHIGH
Site.create()POST /sitesPOST /api/sites❓ VERIFYHIGH
Site.update()PUT /sites/{id}PUT /api/sites/{id}❓ VERIFYHIGH
Site.delete()DELETE /sites/{id}DELETE /api/sites/{id}❓ VERIFYHIGH
Site.findById()GET /sites/{id}GET /api/sites/{id}❓ VERIFYHIGH

Cadastres Management​

Frontend ServiceCurrent Strapi EndpointRequired NestJS EndpointImplementation StatusPriority
Cadastre.find()GET /cadastresGET /api/cadastres✅ EXISTS✅ Complete
Cadastre.findById()GET /cadastres/{id}GET /api/cadastres/{id}✅ EXISTS✅ Complete
Cadastre.delete()DELETE /cadastres/{id}DELETE /api/cadastres/{id}✅ EXISTS✅ Complete

Reclamations (Tax Claims)​

Frontend ServiceCurrent Strapi EndpointRequired NestJS EndpointImplementation StatusPriority
Reclamation.find()GET /reclamationsGET /api/reclamations❓ VERIFYHIGH
Reclamation.findById()GET /reclamations/{id}GET /api/reclamations/{id}❓ VERIFYHIGH
Reclamation.delete()DELETE /reclamations/{id}DELETE /api/reclamations/{id}❓ VERIFYHIGH

Partners (Apporteur Affairs)​

Frontend ServiceCurrent Strapi EndpointRequired NestJS EndpointImplementation StatusPriority
Partner.find()GET /apporteur-affairesGET /api/partners❓ VERIFYMEDIUM
Partner.findById()GET /apporteur-affaires/{id}GET /api/partners/{id}❓ VERIFYMEDIUM
Partner.delete()DELETE /apporteur-affaires/{id}DELETE /api/partners/{id}❓ VERIFYMEDIUM

Invoices (Factures)​

Frontend ServiceCurrent Strapi EndpointRequired NestJS EndpointImplementation StatusPriority
Facture.find()GET /facturesGET /api/invoices❓ VERIFYMEDIUM
Facture.findById()GET /factures/{id}GET /api/invoices/{id}❓ VERIFYMEDIUM
Facture.delete()DELETE /factures/{id}DELETE /api/invoices/{id}❓ VERIFYMEDIUM

Partner Invoices​

Frontend ServiceCurrent Strapi EndpointRequired NestJS EndpointImplementation StatusPriority
PartnerInvoice.find()GET /partner-invoicesGET /api/partner-invoices❓ VERIFYMEDIUM
PartnerInvoice.findById()GET /partner-invoices/{id}GET /api/partner-invoices/{id}❓ VERIFYMEDIUM
PartnerInvoice.update()PUT /partner-invoices/{id}PUT /api/partner-invoices/{id}❓ VERIFYMEDIUM
PartnerInvoice.delete()DELETE /partner-invoices/{id}DELETE /api/partner-invoices/{id}❓ VERIFYMEDIUM

Critical Implementation Gaps​

1. User Management Module (BLOCKING)​

Status: ❌ COMPLETELY MISSING
Impact: Frontend authentication broken
Required Implementation:

// Required: apps/api/src/users/users.controller.ts
@Controller('users')
export class UsersController {
@Get('me')
@UseGuards(JwtAuthGuard)
async getCurrentUser(@Request() req) {
// Return user profile with roles from Auth0
}

@Get()
@UseGuards(JwtAuthGuard)
async findAll(@Query() query) {
// List users with filtering/pagination
}
}

2. Authentication Module (BLOCKING)​

Status: ❌ COMPLETELY MISSING
Impact: No login functionality
Required Implementation:

// Required: apps/api/src/auth/auth.controller.ts
@Controller('auth')
export class AuthController {
@Post('login')
async login(@Body() loginDto) {
// Auth0 token validation
}

@Get('profile')
@UseGuards(JwtAuthGuard)
async getProfile(@Request() req) {
// Extract profile from JWT
}
}

3. JWT Authentication Guard (CRITICAL)​

Status: ❌ MISSING
Impact: No API security
Required Implementation:

// Required: apps/api/src/auth/guards/jwt-auth.guard.ts
@Injectable()
export class JwtAuthGuard implements CanActivate {
async canActivate(context: ExecutionContext): Promise<boolean> {
const request = context.switchToHttp().getRequest();
const token = this.extractTokenFromHeader(request);

if (!token) {
throw new UnauthorizedException();
}

try {
// Validate Auth0 JWT
const payload = await this.validateAuth0Token(token);
request.user = payload;
} catch {
throw new UnauthorizedException();
}

return true;
}
}

Existing NestJS Controllers Found​

✅ Implemented:

  • /apps/api/src/client/client.controller.ts - Client management
  • /apps/api/src/cadastre/cadastre.controller.ts - Cadastre management
  • /apps/api/src/app.controller.ts - Health check

❓ Need Verification:

  • Sites controller
  • Reclamations controller
  • Partners controller
  • Invoices controller

Dev Agent Action Items​

Immediate (CRITICAL - Day 1)​

  1. Verify existing controllers - Check if sites, reclamations, partners, invoices are implemented
  2. Implement User Management Module - Users controller with /me endpoint
  3. Implement Auth Module - JWT validation guard and auth controller
  4. Configure Swagger - Generate OpenAPI spec for frontend type generation

Day 2-3 (HIGH)​

  1. Implement missing controllers based on verification results
  2. Add authentication guards to all existing controllers
  3. Test all endpoints with Postman/automated tests

Day 4-5 (INTEGRATION)​

  1. Generate OpenAPI types for frontend consumption
  2. Update frontend API client to use NestJS endpoints
  3. Integration testing frontend ↔ NestJS API

Response Data Structure Migration​

Strapi Response Format (OLD)​

{
"data": {
"id": 1,
"attributes": {
"nom": "Client Name",
"created_at": "2023-01-01"
}
},
"meta": {
"pagination": {...}
}
}

NestJS Response Format (NEW)​

{
"id": 1,
"nom": "Client Name",
"created_at": "2023-01-01"
}

⚠️ Breaking Change: Frontend services will need response handling updates after API migration.

Verification Commands for Dev Agent​

# Check existing NestJS controllers
find apps/api/src -name "*.controller.ts" -exec basename {} \;

# Verify endpoint availability
curl http://localhost:3001/api/clients
curl http://localhost:3001/api/users/me
curl http://localhost:3001/api-json # Swagger OpenAPI spec

# Test authentication
curl -H "Authorization: Bearer <token>" http://localhost:3001/api/users/me

Next Artifact Needed: auth0-integration-guide.md for JWT validation implementation