Created
August 24, 2020 11:25
-
-
Save nmchenry01/a34f8fa0b958b1459d6d255e09dae583 to your computer and use it in GitHub Desktop.
Task service "NestJS with Swagger"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Injectable() | |
| export class TaskService { | |
| private tasks: Task[] = []; | |
| createTask(createTask: CreateTask): Task { | |
| const { title, description } = createTask; | |
| const newTask: Task = { | |
| id: uuidv4(), | |
| title, | |
| description, | |
| dateTimeCreated: moment().format(), | |
| } | |
| this.tasks.push(newTask) | |
| return newTask; | |
| } | |
| getTasks(): Task[] { | |
| return this.tasks; | |
| } | |
| getTask(taskId: string): Task { | |
| const task = this.tasks.find(task => task.id === taskId); | |
| if (!task) { | |
| throw new NotFoundException(`Task with ID ${taskId} not found`) | |
| } | |
| return task | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment