-
Notifications
You must be signed in to change notification settings - Fork 0
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
976c199
commit 54e884c
Showing
10 changed files
with
203 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { Appointment, User } = require('../models') | ||
const { Op } = require('sequelize') | ||
const moment = require('moment') | ||
|
||
class ScheduleController { | ||
async index (req, res) { | ||
const { date } = req.query | ||
|
||
const defaultDate = moment(parseInt(date || new Date().getTime())) | ||
|
||
const appointments = await Appointment.findAll({ | ||
include: [{ model: User, as: 'user' }], | ||
where: { | ||
provider_id: req.session.user.id, | ||
date: { | ||
[Op.between]: [ | ||
defaultDate.startOf('day').format(), | ||
defaultDate.endOf('day').format() | ||
] | ||
} | ||
}, | ||
order: [['date', 'ASC']] | ||
}) | ||
|
||
return res.render('schedule/index', { appointments, defaultDate }) | ||
} | ||
} | ||
|
||
module.exports = new ScheduleController() |
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
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{% extends "_layouts/default.njk" %} | ||
|
||
{% block body %} | ||
<div class="content"> | ||
<strong>Meus agendamentos</strong> | ||
|
||
<div> | ||
<a href="/app/schedule" class="btn btn-primary">Hoje</a> | ||
<form action="/app/appointments/new/{{ provider.id}}" method="POST"> | ||
<input type="text" class="flatpickr" placeholder="Escolha uma data"> | ||
</form> | ||
</div> | ||
|
||
{% if appointments.length %} | ||
<ul class="schedules"> | ||
{% for appointment in appointments %} | ||
<li class="schedule {% if appointment.date | isAfter === false %}disabled{% endif %}"> | ||
<strong>{{ appointment.date | date("HH:mm") }}</strong> | ||
<div> | ||
<img src="/files/{{appointment.user.avatar}}" alt="Avatar"> | ||
<strong>{{ appointment.user.name }}</strong> | ||
</div> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
{% else %} | ||
<span align="center">Nenhum agendamento marcado!</span> | ||
{% endif %} | ||
|
||
<a href="/app/dashboard" class="btn btn-secondary">Voltar ao início</a> | ||
|
||
</div> | ||
|
||
<script type="text/javascript"> | ||
flatpickr('.flatpickr', { | ||
minDate: new Date(), | ||
defaultDate: new Date('{{defaultDate}}'), | ||
dateFormat: 'd/m/Y', | ||
locale: 'pt', | ||
onChange: function (date) { | ||
window | ||
.location | ||
.assign(`/app/schedule?date=${date[0].getTime()}`); | ||
} | ||
}) | ||
</script> | ||
|
||
{% endblock %} |
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