Skip to content

Commit

Permalink
fix ticket and call customer
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo Cuccu s330260 committed Oct 16, 2024
1 parent b517fec commit 410fcb9
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 24 deletions.
22 changes: 21 additions & 1 deletion office-queue-client/src/API/API.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,28 @@ const getQueues = async (ticketId) => {
throw "Something went wrong";
}
};

const addCounterCustomer = async (counterId, code) =>{
const response = await fetch(`${SERVER_URL}/api/ticket/${counterId}`,{
method: "PUT",
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({code: code})
})
if(response.ok) {
const ticketid = await response.json();
return ticketid;
}
else {
const errDetail = await response.json();
if (errDetail.error)
throw errDetail.error
if (errDetail.message)
throw errDetail.message
throw "Something went wrong"
}
}


const API ={newTicket,getTicket, getServices,getServicesCounter, getCounters, nextCustomer, newHistory, getQueues}
const API ={newTicket,getTicket, getServices,getServicesCounter, getCounters, nextCustomer, newHistory, getQueues, addCounterCustomer}

export default API;
2 changes: 1 addition & 1 deletion office-queue-client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState } from "react";
import {ChooseService,YourTicket} from "./GetTicket"
import { NextCustomer, ChooseCounter } from "./NextCustomer"
import { Routes , Route} from "react-router-dom";
import CallCustomer from "./CallCustomer";
import {CallCustomer} from "./CallCustomer";
import "./App.css";

function App() {
Expand Down
4 changes: 2 additions & 2 deletions office-queue-client/src/CallCustomer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function CallCustomer() {
return tickets
.filter((ticket) => ticket.statusId === 1)
.map((ticket) => ({
serviceName: ticket.service.name,
serviceName: ticket.serviceName,
ticketCode: ticket.code,
}));
};
Expand Down Expand Up @@ -138,4 +138,4 @@ function CallCustomer() {
);
}

export default CallCustomer;
export {CallCustomer};
10 changes: 5 additions & 5 deletions office-queue-client/src/GetTicket.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function ServiceCard(props) {
<Col className='btn-font-1'>{props.s.name}</Col>
</Row>
<Row>
<Col className='btn-font-2'>Questo è un servizio</Col>
<Col className='btn-font-2'>This is a service</Col>
</Row>
</Button>
</div>
Expand All @@ -103,7 +103,7 @@ function ServiceCard(props) {

function YourTicket() {

const [code, setCode] = useState({code:"ciao"})
const [code, setCode] = useState({code:"--"})
const params = useParams()

//get ticket value
Expand Down Expand Up @@ -137,17 +137,17 @@ function YourTicket() {
<Card.Body className='custom-ticket my-3'>
<Row>
<Col className='p-2 m-3 bg-white rounded'>
<QRcode value={`Il tuo Numero: ${code.code} \nEstimated Waiting Time: ${code.estimatedWaitingTime} `} className='m-3'></QRcode>
<QRcode value={`Your ticket code: ${code.code} \nEstimated Waiting Time: ${code.estimatedWaitingTime} m`} className='m-3'></QRcode>
</Col>
</Row>
<Row>
<Col>
<p className='btn-font-4'>{`Il tuo Ticket: ${code.code}`}</p>
<p className='btn-font-4'>{`Your ticket code: ${code.code}`}</p>
</Col>
</Row>
<Row>
<Col>
<p className='btn-font-4'>{`Estimated Waiting Time: ${code.estimatedWaitingTime} `}</p>
<p className='btn-font-4'>{`Estimated Waiting Time: ${code.estimatedWaitingTime} m`}</p>
</Col>
</Row>
<Row className='w-100 my-2'>
Expand Down
7 changes: 6 additions & 1 deletion office-queue-client/src/NextCustomer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ function NextCustomer() {
await API.newHistory(params.counter, currentTicket.code)
}
const ct = await API.nextCustomer(params.counter, currentTicket.code)

console.log(ct);
setCurrentTicket(ct)
setCurrentTicket(ct);

await API.addCounterCustomer(params.counter,currentTicket.code)

setTimer(0)

} catch (err) {
console.log("Errore QUI: " + err);
}
Expand Down
2 changes: 0 additions & 2 deletions office-queue-server/dao/CounterDao.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import db from "../db.mjs";

export default class Counterdao {
constructor() {


/* retrieve all the services offered by a counter*/
this.getCounterServices = (counterId) => {

Expand Down
2 changes: 1 addition & 1 deletion office-queue-server/dao/dao-nextCustomer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import db from "../db.mjs";
export async function insertHistory(history) {
return new Promise( (resolve, reject) => {
const query = `INSERT INTO History (counterId, serviceId, date) VALUES (?,?,?)`;
const params = [history.counterId, history.serviceType, history.date, history.spentTime]
const params = [history.counterId, history.serviceType, history.date]

db.run(query, params, function (err) {
if (err) {
Expand Down
22 changes: 19 additions & 3 deletions office-queue-server/dao/ticketDao.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ import db from '../db.mjs';
async function createTicket(serviceId, estimatedWaitingTime) {
return new Promise(async (resolve, reject) => {
const generatedTicketCode = await generateTicketCode(serviceId);
const query = `INSERT INTO ticket (code, serviceId, estimatedWaitingTime, statusId) VALUES (?, ?, ?, ?)`;
const params = [generatedTicketCode, serviceId, estimatedWaitingTime, 1]; // Assuming statusId is set to 1 by default
const query = `INSERT INTO ticket (code, serviceId, estimatedWaitingTime, statusId, counterId) VALUES (?, ?, ?, ?, ?)`;
const params = [generatedTicketCode, serviceId, estimatedWaitingTime, 1, null]; // Assuming statusId is set to 1 by default

db.run(query, params, function(err) {
if (err) {
Expand Down Expand Up @@ -104,12 +104,28 @@ async function generateTicketCode(serviceId) {

}

function setCounterTicket(code, counterId) {
return new Promise((resolve, reject) => {
//statusId = 1 means that the ticket's status is "waiting" and should be added to the queue lenght
const query = `UPDATE ticket SET counterId = ? WHERE code = ?`;
const params = [counterId, code];

db.run(query, params, function(err) {
if (err) {
return reject(err);
}
resolve(this.changes)
});
})
}

const TicketDao = {
createTicket,
getQueueLength,
getTicketByCode,
getTicketById,
generateTicketCode
generateTicketCode,
setCounterTicket

};

Expand Down
Binary file modified office-queue-server/database.db
Binary file not shown.
3 changes: 1 addition & 2 deletions office-queue-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions office-queue-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
"passport": "^0.7.0",
"passport-local": "^1.0.0",
"sqlite3": "^5.1.7"
},
"devDependencies": {
}
}
18 changes: 18 additions & 0 deletions office-queue-server/routes/ticketRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,22 @@ router.get('/:ticketId', async (req, res) => {
}
});

router.get('/:counterId', async (req, res) => {
const { counterId } = req.params;
const { code } = req.body;

try {
const ticket = await TicketDao.setCounterTicket(code, counterId);

if (!ticket) {
return res.status(404).json({ error: 'Ticket not found' });
}

return res.status(200).json(ticket);
} catch (error) {
console.error('Error fetching ticket:', error.message);
return res.status(500).json({ error: 'Internal server error' });
}
});

export default router;
4 changes: 0 additions & 4 deletions office-queue-server/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ app.use('/api/history', nextCustomerRoutes);
app.use('/api/counters', counterRoutes);
app.use("/api/callCustomer", callCustomerRoutes);

//--- DAOs
import TicketDao from "./dao/dao-ticket.mjs";
const ticketDao = new TicketDao();

//--- Activate the server
const PORT = 3000;
app.listen(PORT, () =>
Expand Down

0 comments on commit 410fcb9

Please sign in to comment.