diff --git a/task_yell/src/lib/events.ts b/task_yell/src/lib/events.ts index 2de88aa..16b7a4b 100644 --- a/task_yell/src/lib/events.ts +++ b/task_yell/src/lib/events.ts @@ -14,35 +14,36 @@ const COLLECTION_NAME = "events"; * @param event 作成されるイベント * @returns 競合がない場合はnull, そうでない場合はマージエディターで必要なので該当日時のイベントのリスト */ -export async function createEvent(event: Event): Promise { +export async function createEvent(userId: string, event: Event): Promise { // event.start ~ event.end とコンフリクトする予定があるかどうかを確認する - const events = await readEvents(); + const events = await readEvents(userId); const isConflict = events.some( (e) => event.start <= e.end && event.end >= e.start, ); if (isConflict) { return events; } else { - await createData(COLLECTION_NAME, event); + await createData(`users/${userId}/${COLLECTION_NAME}`, event); return null; } } -export async function readEvents(): Promise { - return readData(COLLECTION_NAME); +export async function readEvents(userId: string): Promise { + return readData(`users/${userId}/${COLLECTION_NAME}`); } -export async function readSingleEvent(id: string): Promise { - return readSingleData(COLLECTION_NAME, id); +export async function readSingleEvent(userId: string, id: string): Promise { + return readSingleData(`users/${userId}/${COLLECTION_NAME}`, id); } export async function updateEvent( + userId: string, id: string, eventData: Partial, ): Promise { - return updateData(COLLECTION_NAME, id, eventData); + return updateData(`users/${userId}/${COLLECTION_NAME}`, id, eventData); } -export async function deleteEvent(id: string): Promise { - return deleteData(COLLECTION_NAME, id); +export async function deleteEvent(userId: string, id: string): Promise { + return deleteData(`users/${userId}/${COLLECTION_NAME}`, id); } diff --git a/task_yell/src/lib/tasks.ts b/task_yell/src/lib/tasks.ts index c9065f9..430a016 100644 --- a/task_yell/src/lib/tasks.ts +++ b/task_yell/src/lib/tasks.ts @@ -14,8 +14,8 @@ const COLLECTION_NAME = "tasks"; * * @param task 作成されるタスク */ -export async function createTask(task: Task): Promise { - await createData(COLLECTION_NAME, task); +export async function createTask(userId: string, task: Task): Promise { + await createData(`users/${userId}/${COLLECTION_NAME}`, task); } /** @@ -23,8 +23,8 @@ export async function createTask(task: Task): Promise { * * @returns 全タスク */ -export async function readTasks(): Promise { - return readData(COLLECTION_NAME); +export async function readTasks(userId: string): Promise { + return readData(`users/${userId}/${COLLECTION_NAME}`); } /** @@ -33,8 +33,8 @@ export async function readTasks(): Promise { * @param id - 取得するタスクのID。 * @returns 指定されたIDのタスク。 */ -export async function readSingleTask(id: string): Promise { - return readSingleData(COLLECTION_NAME, id); +export async function readSingleTask(userId: string, id: string): Promise { + return readSingleData(`users/${userId}/${COLLECTION_NAME}`, id); } /** @@ -44,10 +44,11 @@ export async function readSingleTask(id: string): Promise { * @param taskData 新規タスクデータ */ export async function updateTask( + userId: string, id: string, taskData: Partial, ): Promise { - await updateData(COLLECTION_NAME, id, taskData); + await updateData(`users/${userId}/${COLLECTION_NAME}`, id, taskData); } /** @@ -55,6 +56,6 @@ export async function updateTask( * * @param id 削除するタスクのID。 */ -export async function deleteTask(id: string): Promise { - await deleteData(COLLECTION_NAME, id); +export async function deleteTask(userId: string, id: string): Promise { + await deleteData(`users/${userId}/${COLLECTION_NAME}`, id); } diff --git a/task_yell/src/lib/want-todo.ts b/task_yell/src/lib/want-todo.ts index 74a96c0..1bc27c7 100644 --- a/task_yell/src/lib/want-todo.ts +++ b/task_yell/src/lib/want-todo.ts @@ -13,8 +13,8 @@ const COLLECTION_NAME = "want-todos"; * * @param wantTodo - 作成する `WantTodo` オブジェクト。 */ -export async function createWantTodo(wantTodo: WantTodo): Promise { - await createData(COLLECTION_NAME, wantTodo); +export async function createWantTodo(userId: string, wantTodo: WantTodo): Promise { + await createData(`users/${userId}/${COLLECTION_NAME}`, wantTodo); } /** @@ -22,8 +22,8 @@ export async function createWantTodo(wantTodo: WantTodo): Promise { * * @returns 全WantTodo */ -export async function readWantTodos(): Promise { - return readData(COLLECTION_NAME); +export async function readWantTodos(userId: string): Promise { + return readData(`users/${userId}/${COLLECTION_NAME}`); } /** @@ -32,8 +32,8 @@ export async function readWantTodos(): Promise { * @param id - 取得するイベントのID。 * @returns 指定されたIDのWantTodo。 */ -export async function readSingleWantTodo(id: string): Promise { - return readSingleData(COLLECTION_NAME, id); +export async function readSingleWantTodo(userId: string, id: string): Promise { + return readSingleData(`users/${userId}/${COLLECTION_NAME}`, id); } /** @@ -43,10 +43,11 @@ export async function readSingleWantTodo(id: string): Promise { * @param wantTodoData 新規WantTodoデータ。 */ export async function updateWantTodo( + userId: string, id: string, wantTodoData: Partial, ): Promise { - return updateData(COLLECTION_NAME, id, wantTodoData); + return updateData(`users/${userId}/${COLLECTION_NAME}`, id, wantTodoData); } /** @@ -54,6 +55,6 @@ export async function updateWantTodo( * * @param id - 削除するWantTodoのID。 */ -export async function deleteWantTodo(id: string): Promise { - return deleteData(COLLECTION_NAME, id); +export async function deleteWantTodo(userId: string, id: string): Promise { + return deleteData(`users/${userId}/${COLLECTION_NAME}`, id); }