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