Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DATABASE_URL="postgresql://postgres:password@localhost:5433/sa_db?schema=public"
DATABASE_URL="postgresql://postgres:1234@localhost:5432/sa_db?schema=public"
14 changes: 14 additions & 0 deletions .http
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
POST http://localhost:8081/createappointment
content-type: application/json

{
"email": "test@gmail.com",
"firstName":"Willem",
"lastName":"Botha",
"cellphone":"0769693806",
"petName":"Jax",
"petType":"Dog",
"vistReason":"Sore foot",
"appointmentEndDate":"2021-07-29 08:04:03.137",
"appointmentStartDate":"2021-07-30 08:04:03.137"
}
43 changes: 40 additions & 3 deletions routes/appointments.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,56 @@
const express = require("express");
const router = express.Router();
const { PrismaClient } = require('@prisma/client')
const {
PrismaClient
} = require('@prisma/client');
const { json } = require("express");

const prisma = new PrismaClient()

// Health check
router.get('/', async (req,res) => {
router.get('/', async (req, res) => {
res.send('Server is running');
const t = 1;
});

//Get all appointments.
router.get('/appointments', async (req,res) => {
router.get('/appointments', async (req, res) => {
const allUsers = await prisma.appointment.findMany();
res.send(allUsers);
});

router.post('/createappointment', async (req, res) => {

const startDate = new Date(req.query.appointmentStartDate);
const endDate = new Date(req.query.appointmentEndDate);

const existStartDate = await prisma.appointment.findFirst({
where: {
appointmentStartDate: startDate,
},
});

if(existStartDate == null){
const insertAppointment = await prisma.appointment.create({
data: {
email: req.query.email,
firstName: req.query.firstName,
lastName: req.query.lastName,
cellphone: req.query.cellphone,
petName: req.query.petName,
petType: req.query.petType,
vistReason: req.query.vistReason,
appointmentEndDate: startDate,
appointmentStartDate: endDate
}
});
console.log("Inserted Appointment");
res.json(insertAppointment);
}
else{
console.log("Appointment Conflicts!");
}

});

module.exports = router;