This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

semble / src / modules / cards / infrastructure / http / controllers / GetUserGraphDataController.ts
1.8 kB 58 lines
1import { Controller } from '../../../../../shared/infrastructure/http/Controller'; 2import { Response } from 'express'; 3import { GetGraphDataUseCase } from '../../../application/useCases/queries/GetGraphDataUseCase'; 4import { AuthenticatedRequest } from '../../../../../shared/infrastructure/http/middleware/AuthMiddleware'; 5 6export class GetUserGraphDataController extends Controller { 7 constructor(private getGraphDataUseCase: GetGraphDataUseCase) { 8 super(); 9 } 10 11 async executeImpl(req: AuthenticatedRequest, res: Response): Promise<any> { 12 try { 13 // Extract identifier from route params 14 const identifier = req.params.identifier; 15 if (!identifier) { 16 return this.badRequest(res, 'Identifier is required'); 17 } 18 19 // Parse pagination parameters from query string 20 const page = req.query.page ? parseInt(req.query.page as string, 10) : 1; 21 const limit = req.query.limit 22 ? parseInt(req.query.limit as string, 10) 23 : 300; 24 25 const result = await this.getGraphDataUseCase.execute({ 26 page, 27 limit, 28 identifier, 29 }); 30 31 if (result.isErr()) { 32 return this.fail(res, result.error); 33 } 34 35 // Calculate pagination metadata 36 const totalCount = result.value.totalNodeCount; 37 const totalPages = Math.ceil(totalCount / limit); 38 const hasMore = page < totalPages; 39 40 // Build response with pagination 41 const response = { 42 nodes: result.value.nodes, 43 edges: result.value.edges, 44 pagination: { 45 currentPage: page, 46 totalPages, 47 totalCount, 48 hasMore, 49 limit, 50 }, 51 }; 52 53 return this.ok(res, response); 54 } catch (error: any) { 55 return this.handleError(res, error); 56 } 57 } 58}