Skip to content

Commit

Permalink
feat: getTodoByIdList API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
NaGyeong-Park committed Dec 8, 2022
1 parent ccb1667 commit 4eb1887
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions client/src/core/todo/todoList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,13 +227,19 @@ export class TodoList {
return this.todoList.find((el) => el.id === id)?.toPlain();
}

async getTodoBySearchKeyword(keyword: string, numberOfReturnTodo: number): Promise<PlainTodo[]> {
async getTodoBySearchKeyword(keyword: string): Promise<PlainTodo[]> {
const regExp = new RegExp(`${keyword}`, 'g');

const searchTodoList = this.todoList
.filter((el) => el.title.match(regExp))
.sort((prev, next) => prev.title.length - next.title.length)
.slice(0, numberOfReturnTodo);
const searchTodoList = this.todoList.filter((el) => el.title.match(regExp));
return searchTodoList.map((el) => el.toPlain());
}

async getTodoByIdList(idList: string[]): Promise<PlainTodo[]> {
const newTodoList = idList.reduce<PlainTodo[]>((acc, id) => {
const todo = this.todoList.find((el) => el.id === id)?.toPlain();
if (todo !== undefined) acc.push(todo);
return acc;
}, []);
return newTodoList;
}
}

0 comments on commit 4eb1887

Please sign in to comment.