Something went wrong. Try again.
A social knowledge tool for research trails, built on ATProto semble.so
research-tool social-network tools-for-thought atproto
Something went wrong. Try again.
1.6 kB · 48 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import { Controller } from '../../../../../shared/infrastructure/http/Controller';import { Response } from 'express';import { AddCardToCollectionUseCase } from '../../../application/useCases/commands/AddCardToCollectionUseCase';import { AuthenticatedRequest } from '../../../../../shared/infrastructure/http/middleware/AuthMiddleware';import { AuthenticationError } from '../../../../../shared/core/AuthenticationError';
export class AddCardToCollectionController extends Controller { constructor(private addCardToCollectionUseCase: AddCardToCollectionUseCase) { super(); }
async executeImpl(req: AuthenticatedRequest, res: Response): Promise<any> { try { const { cardId, collectionIds } = req.body; const curatorId = req.did;
if (!curatorId) { return this.unauthorized(res); }
if (!cardId) { return this.badRequest(res, 'Card ID is required'); }
if (!collectionIds || !Array.isArray(collectionIds)) { return this.badRequest(res, 'Collection IDs array is required'); }
const result = await this.addCardToCollectionUseCase.execute({ cardId, collectionIds, 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.ok(res, result.value); } catch (error: any) { return this.handleError(res, error); } }}