-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
11ed5c8
commit 66833fb
Showing
6 changed files
with
29 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
37 changes: 8 additions & 29 deletions
37
nivel-02/02-iniciando-back-end-do-app/src/repositories/AppointmentsRepository.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,16 @@ | ||
import { isEqual } from 'date-fns'; | ||
import Appoitment from '../models/Appointment'; | ||
|
||
interface CreateAppointmentDTO { | ||
provider: string; | ||
date: Date; | ||
} | ||
|
||
class AppointmentsRepository { | ||
private appointments: Appoitment[]; | ||
|
||
constructor() { | ||
this.appointments = []; | ||
} | ||
import { EntityRepository, Repository } from 'typeorm'; | ||
|
||
public all(): Appoitment[] { | ||
return this.appointments; | ||
} | ||
import Appoitment from '../models/Appointment'; | ||
|
||
public findByDate(date: Date): Appoitment | null { | ||
const findAppointment = this.appointments.find(appointment => | ||
isEqual(date, appointment.date), | ||
); | ||
@EntityRepository(Appoitment) | ||
class AppointmentsRepository extends Repository<Appoitment> { | ||
public async findByDate(date: Date): Promise<Appoitment | null> { | ||
const findAppointment = await this.findOne({ | ||
where: { date }, | ||
}); | ||
|
||
return findAppointment || null; | ||
} | ||
|
||
public create({ provider, date }: CreateAppointmentDTO): Appoitment { | ||
const appointment = new Appoitment({ provider, date }); | ||
|
||
this.appointments.push(appointment); | ||
|
||
return appointment; | ||
} | ||
} | ||
|
||
export default AppointmentsRepository; |
17 changes: 9 additions & 8 deletions
17
nivel-02/02-iniciando-back-end-do-app/src/routes/appointments.routes.ts
This file contains 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
This file contains 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