From 535432384679d814c5bb7f2e2c3e67e824636a5c Mon Sep 17 00:00:00 2001 From: Danilo Vieira Date: Tue, 29 Sep 2020 16:58:29 -0300 Subject: [PATCH] Trabalhando com dados --- .../src/models/Appointment.ts | 2 +- .../src/repositories/AppointmentsRepository.ts | 9 +++++++-- .../src/routes/appointments.routes.ts | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/nivel-02/01-primeiro-projeto-com-nodejs/src/models/Appointment.ts b/nivel-02/01-primeiro-projeto-com-nodejs/src/models/Appointment.ts index 637167a..205f6a4 100644 --- a/nivel-02/01-primeiro-projeto-com-nodejs/src/models/Appointment.ts +++ b/nivel-02/01-primeiro-projeto-com-nodejs/src/models/Appointment.ts @@ -7,7 +7,7 @@ class Appointment { date: Date; - constructor(provider: string, date: Date) { + constructor({ provider, date }: Omit) { this.id = uuid(); this.provider = provider; this.date = date; diff --git a/nivel-02/01-primeiro-projeto-com-nodejs/src/repositories/AppointmentsRepository.ts b/nivel-02/01-primeiro-projeto-com-nodejs/src/repositories/AppointmentsRepository.ts index 9773091..8cf91a0 100644 --- a/nivel-02/01-primeiro-projeto-com-nodejs/src/repositories/AppointmentsRepository.ts +++ b/nivel-02/01-primeiro-projeto-com-nodejs/src/repositories/AppointmentsRepository.ts @@ -1,6 +1,11 @@ import { isEqual } from 'date-fns'; import Appoitment from '../models/Appointment'; +interface CreateAppointmentDTO { + provider: string; + date: Date; +} + class AppointmentsRepository { private appointments: Appoitment[]; @@ -20,8 +25,8 @@ class AppointmentsRepository { return findAppointment || null; } - public create(provider: string, date: Date): Appoitment { - const appointment = new Appoitment(provider, date); + public create({ provider, date }: CreateAppointmentDTO): Appoitment { + const appointment = new Appoitment({ provider, date }); this.appointments.push(appointment); diff --git a/nivel-02/01-primeiro-projeto-com-nodejs/src/routes/appointments.routes.ts b/nivel-02/01-primeiro-projeto-com-nodejs/src/routes/appointments.routes.ts index 51f337c..3c9ba04 100644 --- a/nivel-02/01-primeiro-projeto-com-nodejs/src/routes/appointments.routes.ts +++ b/nivel-02/01-primeiro-projeto-com-nodejs/src/routes/appointments.routes.ts @@ -27,7 +27,10 @@ appointmentsRouter.post('/', (request, response) => { .json({ message: 'This appointment is already booked' }); } - const appointment = appointmentsRepository.create(provider, parsedDate); + const appointment = appointmentsRepository.create({ + provider, + date: parsedDate, + }); return response.json(appointment); });