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.9 kB · 59 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960import { Controller } from '../../../../../shared/infrastructure/http/Controller';import { Response } from 'express';import { RemoveCardFromCollectionUseCase } from '../../../application/useCases/commands/RemoveCardFromCollectionUseCase';import { AuthenticatedRequest } from '../../../../../shared/infrastructure/http/middleware/AuthMiddleware';import { AuthenticationError } from '../../../../../shared/core/AuthenticationError';
export class RemoveCardFromCollectionController extends Controller { constructor( private removeCardFromCollectionUseCase: RemoveCardFromCollectionUseCase, ) { super(); }
async executeImpl(req: AuthenticatedRequest, res: Response): Promise<any> { try { const { cardId, collectionIds: collectionIdsParam } = req.body; const curatorId = req.did;
if (!curatorId) { return this.unauthorized(res); }
if (!cardId) { return this.badRequest(res, 'Card ID is required'); }
if (!collectionIdsParam || !Array.isArray(collectionIdsParam)) { return this.badRequest( res, 'Collection IDs query parameter is required', ); }
const collectionIds = collectionIdsParam.filter((id) => id.trim() !== '');
if (collectionIds.length === 0) { return this.badRequest(res, 'At least one collection ID is required'); }
const result = await this.removeCardFromCollectionUseCase.execute({ cardId: cardId as string, 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); } }}