Skip to content

Commit

Permalink
Trabalhando com dados
Browse files Browse the repository at this point in the history
  • Loading branch information
danilo-vieira committed Sep 29, 2020
1 parent da3d836 commit 5354323
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Appointment {

date: Date;

constructor(provider: string, date: Date) {
constructor({ provider, date }: Omit<Appointment, 'id'>) {
this.id = uuid();
this.provider = provider;
this.date = date;
Expand Down
Original file line number Diff line number Diff line change
@@ -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[];

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down

0 comments on commit 5354323

Please sign in to comment.