From 788c300c8fa836b9ab8383067f63dd07c0fd2002 Mon Sep 17 00:00:00 2001 From: daeseong9388 Date: Tue, 29 Nov 2022 23:49:52 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20IndexedDB=20edit,=20editMany=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EA=B5=AC=ED=98=84=20resolve=20#1?= =?UTF-8?q?21?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/core/repository/repository.indexedDB.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/client/src/core/repository/repository.indexedDB.ts b/client/src/core/repository/repository.indexedDB.ts index a93305c..f74e8ed 100644 --- a/client/src/core/repository/repository.indexedDB.ts +++ b/client/src/core/repository/repository.indexedDB.ts @@ -45,11 +45,21 @@ export class IndexedDB implements ITodoListDataBase { return await this.getAll(); } + async edit(id: string, todo: InputTodo): Promise { + const tx = this.db.transaction(TABLE_NAME, 'readwrite'); + const store = tx.objectStore(TABLE_NAME); + const oldTodo = (await this.get(id)) as PlainTodo; + const newTodo = new Todo({ ...oldTodo, ...todo, id: oldTodo.id }).toPlain(); + await store.put(newTodo, newTodo.id); + return await this.getAll(); } - async edit(id: string, todo: InputTodo): Promise {} - - async editMany(inputArr: Array<{ id: string; todo: InputTodo }>): Promise {} + async editMany(inputArr: Array<{ id: string; todo: InputTodo }>): Promise { + for (const el of inputArr) { + await this.edit(el.id, el.todo); + } + return await this.getAll(); + } async remove(id: string): Promise {} }