Skip to content

Instantly share code, notes, and snippets.

@nmchenry01
Created August 24, 2020 11:25
Show Gist options
  • Select an option

  • Save nmchenry01/a34f8fa0b958b1459d6d255e09dae583 to your computer and use it in GitHub Desktop.

Select an option

Save nmchenry01/a34f8fa0b958b1459d6d255e09dae583 to your computer and use it in GitHub Desktop.
Task service "NestJS with Swagger"
@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