import { NoteData , NoteRepository } from '@/use-cases/ports' ; export class InMemoryNoteRepository implements NoteRepository { private readonly _data : NoteData [ ] ; private idcounder : number = 0 ; private get data ( ) { return this . _data ; } constructor ( data ) { this . _data = data ; } public async add ( note ) { note . id = this . idcounder . toString ( ) ; this . idcounder ++ ; this . _data . push ( note ) ; return note ; } public async findAllNotesFrom ( userId ) { return this . data . filter ( note => note . ownerId === userId ) ; } public async findById ( noteId ) { const note = this . data . find ( note => note . id === noteId ) ; return note || null ; } public async remove ( noteId ) { this . data . splice ( this . data . findIndex ( note => note . id === noteId ) , 1 ) ; } public async updateTitle ( noteId , newTitle ) { const originalNote = await this . findById ( noteId ) ; if ( originalNote ) { originalNote . title = newTitle ; } } public async updateContent ( noteId , newContent ) { const originalNote = await this . findById ( noteId ) ; if ( originalNote ) { originalNote . content = newContent ; } } }