Skip to content

Commit

Permalink
Merge pull request #14 from polijrorg/feat/appointment
Browse files Browse the repository at this point in the history
Feat/appointment
  • Loading branch information
tassyla authored Oct 10, 2024
2 parents d49e9ac + 0397637 commit a310714
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ export default class AppointmentsController {

public async create(req: Request, res: Response): Promise<Response> {
const { id } = req.token;
const { date } = req.body;

const readUser = container.resolve(CreateAppointmentService);

const user = await readUser.execute({
id,
date
});

return res.status(201).json({
Expand Down
12 changes: 6 additions & 6 deletions src/modules/users/services/CreateAppointmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import IUsersRepository from '../repositories/IUsersRepository';

interface IRequest {
id: string;
date: Date;
}

@injectable()
Expand All @@ -20,20 +19,22 @@ export default class CreateAppointmentService {
) { }

public async execute({
id, date
id
}: IRequest): Promise<Users> {
const user = await this.usersRepository.findById(id);
if (!user) throw new AppError('This user does not exist');

date = new Date(date);
const date = new Date();

sgMail.setApiKey(process.env.SENDGRID_API_KEY as string);
const formatDate = (date: number) => date.toString().padStart(2, '0');

const msg = {
to: "lucas.aguiar@polijunior.com.br",
from: 'tassyla.lima@polijunior.com.br',
subject: 'Apogeo | Solicitação de consulta médica',
text: `João, o usuário ${user.name} solicitou uma consulta médica no dia ${date.getDate()}/${date.getMonth()+1}/${date.getFullYear()} às ${date.getHours()}:${date.getMinutes()}.<br><br><strong>Dados do paciente</strong><br>Nome: ${user.name}<br>Telefone: ${user.phone}<br>Email: ${user.email}<br><br><strong>Data proposta</strong><br>Data: ${date.getDate()}/${date.getMonth()}/${date.getFullYear()}<br>Horário: ${date.getHours()}:${date.getMinutes()}`,
html: `João, o usuário ${user.name} solicitou uma consulta médica no dia ${date.getDate()}/${date.getMonth()+1}/${date.getFullYear()} às ${date.getHours()}:${date.getMinutes()}.<br><br><strong>Dados do paciente</strong><br>Nome: ${user.name}<br>Telefone: ${user.phone}<br>Email: ${user.email}<br><br><strong>Data proposta</strong><br>Data: ${date.getDate()}/${date.getMonth()}/${date.getFullYear()}<br>Horário: ${date.getHours()}:${date.getMinutes()}`,
text: `João, o usuário ${user.name} solicitou uma consulta médica. <br><br>Pedido realizado em <strong>${formatDate(date.getDate())}/${formatDate(date.getMonth()+1)}/${date.getFullYear()}</strong> às <strong>${formatDate(date.getHours())}:${formatDate(date.getMinutes())}</strong>.<br><br><strong>Informações do usuário</strong><br>Email: ${user.email}<br>Telefone: ${user.phone}<br>Idioma: ${user.language}<br>${user.gender != null ? "Gênero: "+ user.gender + "<br>": ""}${user.birthdate ? "Data de Nascimento: " + user.birthdate + "<br>" : ""}`,
html: `João, o usuário ${user.name} solicitou uma consulta médica. <br><br>Pedido realizado em <strong>${formatDate(date.getDate())}/${formatDate(date.getMonth()+1)}/${date.getFullYear()}</strong> às <strong>${formatDate(date.getHours())}:${formatDate(date.getMinutes())}</strong>.<br><br><strong>Informações do usuário</strong><br>Email: ${user.email}<br>Telefone: ${user.phone}<br>Idioma: ${user.language}<br>${user.gender != null ? "Gênero: "+ user.gender + "<br>": ""}${user.birthdate ? "Data de Nascimento: " + user.birthdate + "<br>" : ""}`,
};

try {
Expand All @@ -42,7 +43,6 @@ export default class CreateAppointmentService {
} catch (error: any) {
console.error(error);
}

return user;
}
}

0 comments on commit a310714

Please sign in to comment.