A social knowledge tool for researchers built on ATProto
at development 1.3 kB view raw
1import { Controller } from '../../../../../shared/infrastructure/http/Controller'; 2import { Response } from 'express'; 3import { UpdateCollectionUseCase } from '../../../application/useCases/commands/UpdateCollectionUseCase'; 4import { AuthenticatedRequest } from '../../../../../shared/infrastructure/http/middleware/AuthMiddleware'; 5 6export class UpdateCollectionController extends Controller { 7 constructor(private updateCollectionUseCase: UpdateCollectionUseCase) { 8 super(); 9 } 10 11 async executeImpl(req: AuthenticatedRequest, res: Response): Promise<any> { 12 try { 13 const { collectionId } = req.params; 14 const { name, description } = req.body; 15 const curatorId = req.did; 16 17 if (!curatorId) { 18 return this.unauthorized(res); 19 } 20 21 if (!collectionId) { 22 return this.badRequest(res, 'Collection ID is required'); 23 } 24 25 if (!name) { 26 return this.badRequest(res, 'Collection name is required'); 27 } 28 29 const result = await this.updateCollectionUseCase.execute({ 30 collectionId, 31 name, 32 description, 33 curatorId, 34 }); 35 36 if (result.isErr()) { 37 return this.fail(res, result.error); 38 } 39 40 return this.ok(res, result.value); 41 } catch (error: any) { 42 return this.fail(res, error); 43 } 44 } 45}