Skip to content

Commit

Permalink
Merge pull request #15 from polijrorg/feat/appointment
Browse files Browse the repository at this point in the history
Feat/appointment
  • Loading branch information
tassyla authored Oct 19, 2024
2 parents a310714 + 2e59953 commit 6f86c41
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@
"express-async-errors": "^3.1.1",
"handlebars": "^4.7.7",
"jsonwebtoken": "^9.0.2",
"moment": "^2.30.1",
"nodemailer": "^6.4.18",
"openapi-types": "^10.0.0",
"pg": "^8.5.1",
"prisma": "^3.14.0",
"prisma-aurora": "^1.3.6",
"reflect-metadata": "^0.1.13",
"swagger-ui-express": "^4.3.0",
"tsyringe": "^4.4.0",
"tsyringe": "^4.8.0",
"typeorm": "^0.2.31",
"uuid": "^8.3.2"
}
Expand Down
8 changes: 8 additions & 0 deletions src/@types/express.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable @typescript-eslint/naming-convention */
declare namespace Express {
export interface Request {
token: {
id: string,
},
}
}

This file was deleted.

12 changes: 7 additions & 5 deletions src/modules/users/services/CreateAppointmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Users } from '@prisma/client';
import AppError from '@shared/errors/AppError';

import IUsersRepository from '../repositories/IUsersRepository';
import moment from 'moment';

interface IRequest {
id: string;
Expand All @@ -24,17 +25,18 @@ export default class CreateAppointmentService {
const user = await this.usersRepository.findById(id);
if (!user) throw new AppError('This user does not exist');

const date = new Date();
const formattedDate = moment().locale('pt-br').format('DD/MM/YYYY');
const formattedTime = moment().locale('pt-br').format('HH:mm');
const formattedBirthdate = moment(user.birthdate, 'DD/MM/YYYY').locale('pt-br').format('DD/MM/YYYY');

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",
to: "tatitassyla@gmail.com",
from: '[email protected]',
subject: 'Apogeo | Solicitação de consulta médica',
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>" : ""}`,
text: `João, o usuário ${user.name} solicitou uma consulta médica. <br><br>Pedido realizado em <strong>${formattedDate}</strong> às <strong>${formattedTime}</strong>.<br><br><strong>Informações do usuário</strong><br>Nome: ${user.name}<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: " + formattedBirthdate + "<br>" : ""}`,
html: `João, o usuário ${user.name} solicitou uma consulta médica. <br><br>Pedido realizado em <strong>${formattedDate}</strong> às <strong>${formattedTime}</strong>.<br><br><strong>Informações do usuário</strong><br>Nome: ${user.name}<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: " + formattedBirthdate + "<br>" : ""}`,
};

try {
Expand Down
13 changes: 9 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4195,6 +4195,11 @@ mkdirp@^1.0.3, mkdirp@^1.0.4:
resolved "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz"
integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==

moment@^2.30.1:
version "2.30.1"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.30.1.tgz#f8c91c07b7a786e30c59926df530b4eac96974ae"
integrity sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==

[email protected]:
version "2.0.0"
resolved "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz"
Expand Down Expand Up @@ -5955,10 +5960,10 @@ tsutils@^3.17.1:
dependencies:
tslib "^1.8.1"

tsyringe@^4.4.0:
version "4.4.0"
resolved "https://registry.npmjs.org/tsyringe/-/tsyringe-4.4.0.tgz"
integrity sha512-SlMApe1lhIq546CDp7bF+IdF4RB6d+9C5T7B0AS0P/Bm+Qpizj/gEmZzvw9J/KlXPEt4qHTbi1TRvX3rCPSdTg==
tsyringe@^4.8.0:
version "4.8.0"
resolved "https://registry.yarnpkg.com/tsyringe/-/tsyringe-4.8.0.tgz#d599651b36793ba872870fee4f845bd484a5cac1"
integrity sha512-YB1FG+axdxADa3ncEtRnQCFq/M0lALGLxSZeVNbTU8NqhOVc51nnv2CISTcvc1kyv6EGPtXVr0v6lWeDxiijOA==
dependencies:
tslib "^1.9.3"

Expand Down

0 comments on commit 6f86c41

Please sign in to comment.