Something went wrong. Try again.
A social knowledge tool for research trails, built on ATProto semble.so
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869import { Controller } from '../../../../../shared/infrastructure/http/Controller';import { Response } from 'express';import { CreateConnectionUseCase } from '../../../application/useCases/commands/CreateConnectionUseCase';import { AuthenticatedRequest } from '../../../../../shared/infrastructure/http/middleware/AuthMiddleware';import { AuthenticationError } from '../../../../../shared/core/AuthenticationError';
export class CreateConnectionController extends Controller { constructor(private createConnectionUseCase: CreateConnectionUseCase) { super(); }
async executeImpl(req: AuthenticatedRequest, res: Response): Promise<any> { try { const { sourceType, sourceValue, targetType, targetValue, connectionType, note, } = req.body; const curatorId = req.did;
if (!curatorId) { return this.unauthorized(res); }
if (!sourceType || !sourceValue) { return this.badRequest(res, 'Source type and value are required'); }
if (!targetType || !targetValue) { return this.badRequest(res, 'Target type and value are required'); }
// Validate source and target types if (!['URL', 'CARD'].includes(sourceType)) { return this.badRequest(res, 'Invalid source type. Must be URL or CARD'); }
if (!['URL', 'CARD'].includes(targetType)) { return this.badRequest(res, 'Invalid target type. Must be URL or CARD'); }
const result = await this.createConnectionUseCase.execute({ sourceType, sourceValue, targetType, targetValue, connectionType, note, curatorId, });
if (result.isErr()) { // Check if the error is an authentication error if (result.error instanceof AuthenticationError) { return this.handleError(res, result.error); } return this.fail(res, result.error); }
return this.created(res, result.value); } catch (error: any) { return this.handleError(res, error); } }}