From 6a6946e44deed4b78d01441ea6ec04280dc699f1 Mon Sep 17 00:00:00 2001 From: Yeyusin Date: Mon, 5 Aug 2024 06:32:42 +0200 Subject: [PATCH] add all models; implemente issue api/app logics routes and test ; create component Footer and implement in react router-dom #257 --- .../project/api/data/index.js" | 94 ++++++++- .../sergio-oca\303\261a/project/api/index.js" | 185 +++++++++++++++++- .../project/api/logic/addCinemaToManager.js" | 2 +- .../project/api/logic/closeIssue.js" | 37 ++++ .../project/api/logic/closeIssue.test.js" | 14 ++ .../project/api/logic/createIssue.js" | 62 ++++++ .../project/api/logic/createIssue.test.js" | 14 ++ .../project/api/logic/createRoom.js" | 2 + .../api/logic/deleteCinemaToManager.js" | 5 +- .../project/api/logic/deleteIssue.js" | 28 +++ .../project/api/logic/deleteIssue.test.js" | 15 ++ .../project/api/logic/deleteRoom.js" | 2 + .../project/api/logic/index.js" | 10 + .../api/logic/retrieveCinemaIssues.js" | 51 +++++ .../api/logic/retrieveCinemaIssues.test.js" | 14 ++ .../api/logic/retrieveRoomsFromCinema.js" | 2 +- .../project/api/logic/retrieveUserIssues.js" | 36 ++++ .../api/logic/retrieveUserIssues.test.js" | 14 ++ .../project/api/logic/updateRoom.js" | 4 + .../project/api/test/authenticate-user.sh" | 2 +- .../project/api/test/close-issue.sh" | 1 + .../project/api/test/create-issue.sh" | 1 + .../project/api/test/delete-issue.sh" | 1 + .../api/test/retrieve-cinema-issues.sh" | 1 + .../project/api/test/retrieve-user-issues.sh" | 1 + .../project/app/package.json" | 3 +- .../project/app/src/App.jsx" | 12 +- .../project/app/src/components/Cinema.jsx" | 4 +- .../project/app/src/components/Footer.jsx" | 11 ++ .../project/app/src/components/Header.jsx" | 7 + .../project/app/src/components/index.js" | 2 + .../project/app/src/logic/closeIssue.js" | 29 +++ .../project/app/src/logic/createIssue.js" | 40 ++++ .../project/app/src/logic/deleteIssue.js" | 31 +++ .../app/src/logic/retrieveCinemaIssues.js" | 28 +++ .../app/src/logic/retrieveUserIssues.js" | 28 +++ .../project/app/src/pages/Home.jsx" | 14 +- .../project/app/src/pages/Issue.jsx" | 6 + .../project/app/src/pages/Login.jsx" | 4 +- .../app/src/pages/RegisterCustomer.jsx" | 2 +- .../app/src/pages/RegisterManager.jsx" | 2 +- .../project/app/src/pages/RouteFooter.jsx" | 11 ++ .../project/com/validate.js" | 23 ++- .../project/doc/README.md" | 2 +- .../project/package-lock.json" | 20 +- 45 files changed, 838 insertions(+), 39 deletions(-) create mode 100644 "staff/sergio-oca\303\261a/project/api/logic/closeIssue.js" create mode 100644 "staff/sergio-oca\303\261a/project/api/logic/closeIssue.test.js" create mode 100644 "staff/sergio-oca\303\261a/project/api/logic/createIssue.js" create mode 100644 "staff/sergio-oca\303\261a/project/api/logic/createIssue.test.js" create mode 100644 "staff/sergio-oca\303\261a/project/api/logic/deleteIssue.js" create mode 100644 "staff/sergio-oca\303\261a/project/api/logic/deleteIssue.test.js" create mode 100644 "staff/sergio-oca\303\261a/project/api/logic/retrieveCinemaIssues.js" create mode 100644 "staff/sergio-oca\303\261a/project/api/logic/retrieveCinemaIssues.test.js" create mode 100644 "staff/sergio-oca\303\261a/project/api/logic/retrieveUserIssues.js" create mode 100644 "staff/sergio-oca\303\261a/project/api/logic/retrieveUserIssues.test.js" create mode 100644 "staff/sergio-oca\303\261a/project/api/test/close-issue.sh" create mode 100644 "staff/sergio-oca\303\261a/project/api/test/create-issue.sh" create mode 100644 "staff/sergio-oca\303\261a/project/api/test/delete-issue.sh" create mode 100644 "staff/sergio-oca\303\261a/project/api/test/retrieve-cinema-issues.sh" create mode 100644 "staff/sergio-oca\303\261a/project/api/test/retrieve-user-issues.sh" create mode 100644 "staff/sergio-oca\303\261a/project/app/src/components/Footer.jsx" create mode 100644 "staff/sergio-oca\303\261a/project/app/src/components/Header.jsx" create mode 100644 "staff/sergio-oca\303\261a/project/app/src/logic/closeIssue.js" create mode 100644 "staff/sergio-oca\303\261a/project/app/src/logic/createIssue.js" create mode 100644 "staff/sergio-oca\303\261a/project/app/src/logic/deleteIssue.js" create mode 100644 "staff/sergio-oca\303\261a/project/app/src/logic/retrieveCinemaIssues.js" create mode 100644 "staff/sergio-oca\303\261a/project/app/src/logic/retrieveUserIssues.js" create mode 100644 "staff/sergio-oca\303\261a/project/app/src/pages/Issue.jsx" create mode 100644 "staff/sergio-oca\303\261a/project/app/src/pages/RouteFooter.jsx" diff --git "a/staff/sergio-oca\303\261a/project/api/data/index.js" "b/staff/sergio-oca\303\261a/project/api/data/index.js" index 032abdeb..cec61efe 100644 --- "a/staff/sergio-oca\303\261a/project/api/data/index.js" +++ "b/staff/sergio-oca\303\261a/project/api/data/index.js" @@ -54,20 +54,110 @@ const room = new Schema({ }, cinema: { type: ObjectId, - ref: 'Cinema' + ref: 'Cinema', + required: true }, temperature: { type: String, required: true, } }) +const ticket = new Schema({ + user: { + type: ObjectId, + ref: 'User', + }, + cinema: { + type: ObjectId, + ref: 'Cinema', + required: true + }, + room: { + type: ObjectId, + ref: 'Room', + required: true + }, + seat: { + type: String, + required: true + } +}) +const issue = new Schema({ + author: { + type: ObjectId, + ref: 'User', + required: true + }, + cinema: { + type: ObjectId, + ref: 'Cinema', + required: true + }, + room: { + type: ObjectId, + ref: 'Room', + }, + location: { + type: String, + required: true + }, + type: { + type: String, + requiered: true, + enum: ['temperature', 'sound', 'film', 'cleaning'] + }, + description: { + type: String, + requiered: true + }, + status: { + type: String, + enum: ['open', 'closed'], + default: 'open', + required: true + }, + ticket: { + type: ObjectId, + ref: 'Ticket' + }, + date: { + type: Date, + required: true + } +}) +const comment = new Schema({ + text: { + type: String, + requiered: true + }, + issue: { + type: ObjectId, + ref: 'Issue', + requiered: true + }, + author: { + type: ObjectId, + ref: 'User', + required: true + }, + date: { + type: Date, + required: true + } +}) const Room = model('Room', room) const Cinema = model('Cinema', cinema) const User = model('User', user) +const Ticket = model('Ticket', ticket) +const Issue = model('Issue', issue) +const Comment = model('Comment', comment) export { Cinema, User, - Room + Room, + Ticket, + Issue, + Comment } \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/index.js" "b/staff/sergio-oca\303\261a/project/api/index.js" index b5a58e13..5ee97370 100644 --- "a/staff/sergio-oca\303\261a/project/api/index.js" +++ "b/staff/sergio-oca\303\261a/project/api/index.js" @@ -21,7 +21,9 @@ mongoose.connect(MONGO_URL) const jsonBodyParser = express.json() server.use(cors()) - /* User Routes */ + + /* UserRoutes */ + server.post('/users/customer', jsonBodyParser, (req, res) => { try { const { name, birthdate, email, password } = req.body @@ -168,11 +170,11 @@ mongoose.connect(MONGO_URL) status = 401 error = new MatchError(error.message) - } res.status(status).json({ error: error.constructor.name, message: error.message }) } }) + server.get('/cinemas', (req, res) => { try { const { authorization } = req.headers @@ -202,7 +204,6 @@ mongoose.connect(MONGO_URL) status = 401 error = new MatchError(error.message) - } res.status(status).json({ error: error.constructor.name, message: error.message }) } @@ -239,7 +240,6 @@ mongoose.connect(MONGO_URL) status = 401 error = new MatchError(error.message) - } res.status(status).json({ error: error.constructor.name, message: error.message }) } @@ -275,7 +275,6 @@ mongoose.connect(MONGO_URL) status = 401 error = new MatchError(error.message) - } res.status(status).json({ error: error.constructor.name, message: error.message }) } @@ -390,7 +389,6 @@ mongoose.connect(MONGO_URL) } }) - server.get('/rooms/:cinemaId', (req, res) => { try { const { authorization } = req.headers @@ -458,10 +456,8 @@ mongoose.connect(MONGO_URL) error = new MatchError(error.message) } - res.status(status).json({ error: error.constructor.name, message: error.message }) } - }) server.delete('/rooms/:cinemaId/:roomId', (req, res) => { @@ -494,12 +490,185 @@ mongoose.connect(MONGO_URL) status = 401 error = new MatchError(error.message) + } + res.status(status).json({ error: error.constructor.name, message: error.message }) + } + }) + + /* IssueRoutes */ + + server.post('/issues/:cinemaId/:roomId?', jsonBodyParser, (req, res) => { + try { + const { authorization } = req.headers + + const token = authorization.slice(7) + + const { sub: userId } = jwt.verify(token, JWT_SECRET) + + const { cinemaId, roomId } = req.params + + const { location, type, description } = req.body + + logic.createIssue(userId, cinemaId, location, type, description, roomId) + .then(() => res.status(201).send()) + .catch(error => { + let status = 500 + + if (error instanceof MatchError) + status = 401 + + res.status(status).json({ error: error.constructor.name, message: error.message }) + }) + + } catch (error) { + let status = 500 + + if (error instanceof TypeError || error instanceof RangeError || error instanceof ContentError) + status = 400 + + else if (error instanceof JsonWebTokenError || error instanceof TokenExpiredError) { + status = 401 + + error = new MatchError(error.message) + } + res.status(status).json({ error: error.constructor.name, message: error.message }) + } + }) + + server.get('/issues/cinema', (req, res) => { + try { + const { authorization } = req.headers + + const token = authorization.slice(7) + + const { sub: userId } = jwt.verify(token, JWT_SECRET) + + logic.retrieveCinemaIssues(userId) + .then(issues => res.json(issues)) + .catch(error => { + + let status = 500 + + if (error instanceof MatchError) + status = 404 + + res.status(status).json({ error: error.constructor.name, message: error.message }) + }) + } catch (error) { + let status = 500 + + if (error instanceof TypeError || error instanceof RangeError || error instanceof ContentError) + status = 400 + else if (error instanceof JsonWebTokenError || error instanceof TokenExpiredError) { + status = 401 + error = new MatchError(error.message) } res.status(status).json({ error: error.constructor.name, message: error.message }) } }) + server.get('/issues/user', (req, res) => { + try { + const { authorization } = req.headers + + const token = authorization.slice(7) + + const { sub: userId } = jwt.verify(token, JWT_SECRET) + + logic.retrieveUserIssues(userId) + .then(issues => res.json(issues)) + .catch(error => { + + let status = 500 + + if (error instanceof MatchError) + status = 404 + + res.status(status).json({ error: error.constructor.name, message: error.message }) + }) + } catch (error) { + let status = 500 + + if (error instanceof TypeError || error instanceof RangeError || error instanceof ContentError) + status = 400 + else if (error instanceof JsonWebTokenError || error instanceof TokenExpiredError) { + status = 401 + + error = new MatchError(error.message) + } + res.status(status).json({ error: error.constructor.name, message: error.message }) + } + }) + + server.patch('/issues/:issueId', (req, res) => { + try { + const { authorization } = req.headers + + const token = authorization.slice(7) + + const { sub: userId } = jwt.verify(token, JWT_SECRET) + + const { issueId } = req.params + + logic.closeIssue(userId, issueId) + .then(() => { res.status(200).send() }) + .catch(error => { + let status = 500 + + if (error instanceof MatchError) + status = 401 + + res.status(status).json({ error: error.constructor.name, message: error.message }) + }) + } catch (error) { + let status = 500 + + if (error instanceof TypeError || error instanceof RangeError || error instanceof ContentError) + status = 400 + else if (error instanceof JsonWebTokenError || error instanceof TokenExpiredError) { + status = 401 + + error = new MatchError(error.message) + } + res.status(status).json({ error: error.constructor.name, message: error.message }) + } + }) + + server.delete('/issues/:issueId', (req, res) => { + try { + const { authorization } = req.headers + + const token = authorization.slice(7) + + const { sub: userId } = jwt.verify(token, JWT_SECRET) + + const { issueId } = req.params + + logic.deleteIssue(userId, issueId) + .then(() => res.status(204).send()) + .catch(error => { + let status = 500 + + if (error instanceof MatchError) + status = 401 + res.status(status).json({ error: error.constructor.name, message: error.message }) + }) + + } catch (error) { + let status = 500 + + if (error instanceof TypeError || error instanceof RangeError || error instanceof ContentError) + status = 400 + + else if (error instanceof JsonWebTokenError || error instanceof TokenExpiredError) { + status = 401 + + error = new MatchError(error.message) + } + res.status(status).json({ error: error.constructor.name, message: error.message }) + } + }) server.listen(PORT, () => console.log(`API started on port ${PORT}`)) }) diff --git "a/staff/sergio-oca\303\261a/project/api/logic/addCinemaToManager.js" "b/staff/sergio-oca\303\261a/project/api/logic/addCinemaToManager.js" index baab33c2..2d3e760f 100644 --- "a/staff/sergio-oca\303\261a/project/api/logic/addCinemaToManager.js" +++ "b/staff/sergio-oca\303\261a/project/api/logic/addCinemaToManager.js" @@ -13,7 +13,7 @@ function addCinemaToManager(userId, cinemaId) { .then(user => { if (!user) throw new MatchError('user not found') - if (user.role !== 'manager') throw new MatchError('Only Managers are allowed could be assigned to a cinema') + if (user.role !== 'manager') throw new MatchError('Only Managers are allowed to be assigned to a cinema') if (user.cinema) throw new MatchError('You already have a Cinema. If you want to change it, delete it first') diff --git "a/staff/sergio-oca\303\261a/project/api/logic/closeIssue.js" "b/staff/sergio-oca\303\261a/project/api/logic/closeIssue.js" new file mode 100644 index 00000000..fef81f4d --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/logic/closeIssue.js" @@ -0,0 +1,37 @@ +import { User, Issue } from '../data/index.js' + +import { validate, errors } from 'com' + +const { SystemError, MatchError } = errors + +function closeIssue(userId, issueId) { + validate.id(userId) + validate.id(issueId, 'issueId') + + return User.findById(userId) + .catch(error => { throw new SystemError(error.message) }) + .then(user => { + if (!user) throw new MatchError('User not found') + + if (user.role !== 'manager') throw new MatchError('You don t have privileges to close Issues') + + if (!user.cinema) throw new MatchError('You need asign a cinema first, after it you can handle issues') + + return Issue.findById(issueId) + .catch(error => { throw new SystemError(error.message) }) + .then(issue => { + if (!issue) throw new MatchError('Issue not found') + + if (issue.status === 'closed') throw new MatchError('Issue already closed') + + if (issue.cinema.toString() !== user.cinema.toString()) throw new MatchError('You could only close your cinema tickets') + + issue.status = 'closed' + + return issue.save() + .catch(error => { throw new SystemError(error.message) }) + .then(() => { }) + }) + }) +} +export default closeIssue \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/logic/closeIssue.test.js" "b/staff/sergio-oca\303\261a/project/api/logic/closeIssue.test.js" new file mode 100644 index 00000000..24f7c52b --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/logic/closeIssue.test.js" @@ -0,0 +1,14 @@ +import mongoose from 'mongoose' +import closeIssue from './closeIssue.js' + +mongoose.connect('mongodb://localhost:27017/project') + .then(() => { + try { + closeIssue('669e3f9f595f14db65b23a19', '66b020691ead207d8496d539') + .then(() => console.log('issue closed')) + .catch(error => console.error(error)) + + } catch (error) { + console.error(error) + } + }) \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/logic/createIssue.js" "b/staff/sergio-oca\303\261a/project/api/logic/createIssue.js" new file mode 100644 index 00000000..10449188 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/logic/createIssue.js" @@ -0,0 +1,62 @@ +import { User, Cinema, Room, Issue } from '../data/index.js' + +import { validate, errors } from 'com' + +const { SystemError, MatchError } = errors + +function callbackFunction(author, cinema, location, type, description, room) { + const issue = { + author, + cinema, + location, + type, + description, + date: new Date + } + if (room) issue.room = room + + return Issue.create(issue) + .catch(error => { throw new SystemError(error.message) }) + .then(issue => { }) +} + +function createIssue(userId, cinemaId, location, type, description, roomId) { + validate.id(userId) + validate.id(cinemaId, 'cinemaId') + validate.text(location) + validate.type(type) + validate.text(description) + + if (roomId) + validate.id(roomId, 'roomId') + + return User.findById(userId) + .catch(error => { throw new SystemError(error.message) }) + .then(user => { + if (!user) throw new MatchError('User not found') + + if (user.role == ! 'customer') throw new MatchError('You need asign a cinema first, so you can edit it') + + return Cinema.findById(cinemaId) + .catch(error => { throw new SystemError(error.message) }) + .then(cinema => { + if (!cinema) throw new MatchError('Cinema not found') + + if (roomId) { + return Room.findById(roomId) + .catch(error => { throw new SystemError(error.message) }) + .then(room => { + if (!room) throw new MatchError('Room not found') + + if (room.cinema.toString() !== cinemaId) throw new MatchError('The Room doesn´t belong to the Cinema') + + callbackFunction(userId, cinemaId, location, type, description, roomId) + }) + } + else { + callbackFunction(userId, cinemaId, location, type, description, roomId) + } + }) + }) + +} export default createIssue \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/logic/createIssue.test.js" "b/staff/sergio-oca\303\261a/project/api/logic/createIssue.test.js" new file mode 100644 index 00000000..f88cff6f --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/logic/createIssue.test.js" @@ -0,0 +1,14 @@ +import createIssue from './createIssue.js' + +import mongoose from 'mongoose' + +mongoose.connect('mongodb://localhost:27017/project') + .then(() => { + try { + createIssue('669a7e6492f2e1bb5b9cbcf2', '66a8b2fca7a3e4552fedf3f4', 'Sala 1', 'cleaning', 'hay papel tirado por todos lados', '66aba81ec09ef7f3a8197b0d') + .then(() => console.log('issue created')) + .catch(error => console.error(error)) + } catch (error) { + console.error(error) + } + }) diff --git "a/staff/sergio-oca\303\261a/project/api/logic/createRoom.js" "b/staff/sergio-oca\303\261a/project/api/logic/createRoom.js" index 0f1af545..ba99ffc6 100644 --- "a/staff/sergio-oca\303\261a/project/api/logic/createRoom.js" +++ "b/staff/sergio-oca\303\261a/project/api/logic/createRoom.js" @@ -17,6 +17,8 @@ function createRoom(userId, cinemaId, name, temperature) { if (!user.cinema) throw new MatchError('You need asign a cinema first, so you can edit it') + if (user.role !== 'manager') throw new MatchError('You don t have privileges to create a Room') + return Cinema.findById(cinemaId) .catch(error => { throw new SystemError(error.message) }) .then(cinema => { diff --git "a/staff/sergio-oca\303\261a/project/api/logic/deleteCinemaToManager.js" "b/staff/sergio-oca\303\261a/project/api/logic/deleteCinemaToManager.js" index 75c674b3..488d96bf 100644 --- "a/staff/sergio-oca\303\261a/project/api/logic/deleteCinemaToManager.js" +++ "b/staff/sergio-oca\303\261a/project/api/logic/deleteCinemaToManager.js" @@ -4,10 +4,9 @@ import { validate, errors } from 'com' const { SystemError, MatchError } = errors -function deleteCinemaToManager(userId, cinemaId, role) { +function deleteCinemaToManager(userId, cinemaId) { validate.id(userId) validate.id(cinemaId, 'cinemaId') - validate.role(role) return User.findById(userId) .catch(error => { throw new SystemError(error.message) }) @@ -16,6 +15,8 @@ function deleteCinemaToManager(userId, cinemaId, role) { if (!user.cinema) throw new MatchError('You don´t have any cinema to delete') + if (user.role !== 'manager') throw new MatchError('You don t have privileges') + return Cinema.findById(cinemaId) .catch(error => { throw new SystemError(error.message) }) .then(cinema => { diff --git "a/staff/sergio-oca\303\261a/project/api/logic/deleteIssue.js" "b/staff/sergio-oca\303\261a/project/api/logic/deleteIssue.js" new file mode 100644 index 00000000..ae7df540 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/logic/deleteIssue.js" @@ -0,0 +1,28 @@ +import { User, Issue } from '../data/index.js' +import { validate, errors } from 'com' + +const { MatchError, SystemError } = errors + +function deleteIssue(userId, issueId) { + validate.id(userId) + validate.id(issueId, 'issueId') + + return User.findById(userId) + .catch(error => { throw new SystemError(error.message) }) + .then(user => { + if (!user) throw new MatchError('user not found') + + return Issue.findById(issueId).lean() + .catch(error => { throw new SystemError(error.message) }) + .then(issue => { + if (!issue) throw new MatchError('issue not found') + + if (user.role !== 'manager' && issue.author.toString() !== userId) throw new MatchError('You couldn´t have permission to delete this issue') + + return Issue.findByIdAndDelete(issueId) + .catch(error => { throw new SystemError(error.message) }) + .then(() => { }) + }) + }) +} +export default deleteIssue \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/logic/deleteIssue.test.js" "b/staff/sergio-oca\303\261a/project/api/logic/deleteIssue.test.js" new file mode 100644 index 00000000..20f96c77 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/logic/deleteIssue.test.js" @@ -0,0 +1,15 @@ +import deleteIssue from './deleteIssue.js' + +import mongoose from 'mongoose' + +mongoose.connect('mongodb://localhost:27017/project') + .then(() => { + try { + deleteIssue('66ad34549584ffcded1d4939', '66aec3f2ef03e964949a66f1') + .then(() => console.log('Issue deleted')) + .catch((error) => console.error(error)) + } catch (error) { + console.error(error) + } + }) + .catch(error => console.error(error)) \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/logic/deleteRoom.js" "b/staff/sergio-oca\303\261a/project/api/logic/deleteRoom.js" index 07e5022f..38abfa5b 100644 --- "a/staff/sergio-oca\303\261a/project/api/logic/deleteRoom.js" +++ "b/staff/sergio-oca\303\261a/project/api/logic/deleteRoom.js" @@ -16,6 +16,8 @@ function deleteRoom(userId, cinemaId, roomId) { if (!user.cinema) throw new MatchError('You need asign a cinema first, after that you could edit it') + if (user.role !== 'manager') throw new MatchError('You don t have privileges') + return Cinema.findById(cinemaId) .catch(error => { throw new SystemError(error.message) }) .then(cinema => { diff --git "a/staff/sergio-oca\303\261a/project/api/logic/index.js" "b/staff/sergio-oca\303\261a/project/api/logic/index.js" index 1c47b1f3..f7530e03 100644 --- "a/staff/sergio-oca\303\261a/project/api/logic/index.js" +++ "b/staff/sergio-oca\303\261a/project/api/logic/index.js" @@ -12,6 +12,11 @@ import createRoom from './createRoom.js' import updateRoom from './updateRoom.js' import deleteRoom from './deleteRoom.js' import retrieveRoomsFromCinema from './retrieveRoomsFromCinema.js' +import createIssue from './createIssue.js' +import retrieveCinemaIssues from './retrieveCinemaIssues.js' +import retrieveUserIssues from './retrieveUserIssues.js' +import deleteIssue from './deleteIssue.js' +import closeIssue from './closeIssue.js' const logic = { authenticateUser, @@ -28,6 +33,11 @@ const logic = { updateRoom, deleteRoom, retrieveRoomsFromCinema, + createIssue, + retrieveCinemaIssues, + retrieveUserIssues, + closeIssue, + deleteIssue, } export default logic diff --git "a/staff/sergio-oca\303\261a/project/api/logic/retrieveCinemaIssues.js" "b/staff/sergio-oca\303\261a/project/api/logic/retrieveCinemaIssues.js" new file mode 100644 index 00000000..ab15ae82 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/logic/retrieveCinemaIssues.js" @@ -0,0 +1,51 @@ +import { User, Issue, Cinema } from '../data/index.js' +import { validate, errors } from 'com' + +const { MatchError, SystemError } = errors + + +function retrieveCinemaIssues(userId) { + validate.id(userId) + + return User.findById(userId) + .catch(error => { throw new SystemError(error.message) }) + .then(user => { + if (!user) throw new MatchError('user not found') + + if (user.role !== 'manager') throw new MatchError('only manager could search by cinema') + + const cinemaId = user.cinema.toString() + + return Cinema.findById(cinemaId) + .catch(error => { throw new SystemError(error.message) }) + .then(cinema => { + if (!cinema) throw new MatchError('Cinema not found') + + return Issue.find({ $and: [{ status: 'open' }, { cinema: cinemaId }] }).populate('author', 'name').sort({ date: -1 }).select('-__v ').lean() + .catch(error => { throw new SystemError(error.message) }) + .then(issues => { + issues.forEach(issue => { + if (issue._id) { + issue.id = issue._id.toString() + + delete issue._id + } + + if (issue.author._id) { + issue.author.id = issue.author._id.toString() + + delete issue.author._id + } + + if (typeof issue.cinema === 'object') issue.cinema = issue.cinema.toString() + + if ('room' in issue) if (typeof issue.room === 'object') issue.room = issue.room.toString() + }) + + return issues + }) + + }) + }) +} +export default retrieveCinemaIssues \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/logic/retrieveCinemaIssues.test.js" "b/staff/sergio-oca\303\261a/project/api/logic/retrieveCinemaIssues.test.js" new file mode 100644 index 00000000..394d68cc --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/logic/retrieveCinemaIssues.test.js" @@ -0,0 +1,14 @@ +import mongoose from 'mongoose' +import retrieveCinemaIssues from './retrieveCinemaIssues.js' + +mongoose.connect('mongodb://localhost:27017/project') + .then(() => { + try { + retrieveCinemaIssues('669e3f9f595f14db65b23a19') + .then(issues => console.log('issues retrieved', issues)) + .catch(error => console.error(error)) + + } catch (error) { + console.error(error) + } + }) \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/logic/retrieveRoomsFromCinema.js" "b/staff/sergio-oca\303\261a/project/api/logic/retrieveRoomsFromCinema.js" index dbdaad8f..f08a23fc 100644 --- "a/staff/sergio-oca\303\261a/project/api/logic/retrieveRoomsFromCinema.js" +++ "b/staff/sergio-oca\303\261a/project/api/logic/retrieveRoomsFromCinema.js" @@ -31,7 +31,7 @@ function retrieveRoomsFromCinema(userId, cinemaId) { delete room._id } - if (typeof room.cinema !== 'string') + if (typeof room.cinema === 'object') room.cinema = room.cinema.toString() }) diff --git "a/staff/sergio-oca\303\261a/project/api/logic/retrieveUserIssues.js" "b/staff/sergio-oca\303\261a/project/api/logic/retrieveUserIssues.js" new file mode 100644 index 00000000..f144a409 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/logic/retrieveUserIssues.js" @@ -0,0 +1,36 @@ +import { User, Issue } from '../data/index.js' +import { validate, errors } from 'com' + +const { MatchError, SystemError } = errors + + +function retrieveUserIssues(userId) { + validate.id(userId) + + return User.findById(userId) + .catch(error => { throw new SystemError(error.message) }) + .then(user => { + if (!user) throw new MatchError('user not found') + + if (user.role !== 'customer') throw new MatchError('only customers could search his issues') + + return Issue.find({ author: userId }).sort({ date: -1 }).select('-__v -author').lean() + .catch(error => { throw new SystemError(error.message) }) + .then(issues => { + issues.forEach(issue => { + if (issue._id) { + issue.id = issue._id.toString() + + delete issue._id + } + + if (typeof issue.cinema === 'object') issue.cinema = issue.cinema.toString() + + if ('room' in issue) if (typeof issue.room === 'object') issue.room = issue.room.toString() + }) + + return issues + }) + }) +} +export default retrieveUserIssues \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/logic/retrieveUserIssues.test.js" "b/staff/sergio-oca\303\261a/project/api/logic/retrieveUserIssues.test.js" new file mode 100644 index 00000000..d0cc589b --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/logic/retrieveUserIssues.test.js" @@ -0,0 +1,14 @@ +import mongoose from 'mongoose' +import retrieveUserIssues from './retrieveUserIssues.js' + +mongoose.connect('mongodb://localhost:27017/project') + .then(() => { + try { + retrieveUserIssues('669a7e6492f2e1bb5b9cbcf2') + .then(issues => console.log('issues retrieved', issues)) + .catch(error => console.error(error)) + + } catch (error) { + console.error(error) + } + }) \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/logic/updateRoom.js" "b/staff/sergio-oca\303\261a/project/api/logic/updateRoom.js" index 208397bd..3f43f797 100644 --- "a/staff/sergio-oca\303\261a/project/api/logic/updateRoom.js" +++ "b/staff/sergio-oca\303\261a/project/api/logic/updateRoom.js" @@ -18,6 +18,8 @@ function updateRoom(userId, cinemaId, roomId, name, temperature) { if (!user.cinema) throw new MatchError('You need asign a cinema first, so you can edit it') + if (user.role !== 'manager') throw new MatchError('You don t have privileges to edit the room') + return Cinema.findById(cinemaId) .catch(error => { throw new SystemError(error.message) }) .then(cinema => { @@ -25,6 +27,8 @@ function updateRoom(userId, cinemaId, roomId, name, temperature) { if (cinemaId !== user.cinema.toString()) throw new MatchError('You can only modify your own cinema') + if (user.role !== 'manager') throw new MatchError('You don t have privileges') + return Room.findById(roomId) .catch(error => { throw new SystemError(error.message) }) .then(room => { diff --git "a/staff/sergio-oca\303\261a/project/api/test/authenticate-user.sh" "b/staff/sergio-oca\303\261a/project/api/test/authenticate-user.sh" index 2727ee69..162f86ca 100644 --- "a/staff/sergio-oca\303\261a/project/api/test/authenticate-user.sh" +++ "b/staff/sergio-oca\303\261a/project/api/test/authenticate-user.sh" @@ -1 +1 @@ -curl -X POST -H 'Content-type: application/json' -d '{"email":"the@boss.com","password":"12341234"}' http://127.0.0.1:8080/users/auth -v \ No newline at end of file +curl -X POST -H 'Content-type: application/json' -d '{"email":"sergio@gmail.com","password":"12341234"}' http://127.0.0.1:8080/users/auth -v \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/test/close-issue.sh" "b/staff/sergio-oca\303\261a/project/api/test/close-issue.sh" new file mode 100644 index 00000000..e1f00b09 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/test/close-issue.sh" @@ -0,0 +1 @@ +curl -X PATCH -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NjllM2Y5ZjU5NWYxNGRiNjViMjNhMTkiLCJyb2xlIjoibWFuYWdlciIsImlhdCI6MTcyMjUxODM4M30.CBMfEQWQoVzAvpkD5V1EE-Vsbd6HtF4t1r8UXRUPHEI' http://localhost:8080/issues/66b022f4679ff34daf8d55fb -v \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/test/create-issue.sh" "b/staff/sergio-oca\303\261a/project/api/test/create-issue.sh" new file mode 100644 index 00000000..b3cd5922 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/test/create-issue.sh" @@ -0,0 +1 @@ +curl -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NjllM2Y5ZjU5NWYxNGRiNjViMjNhMTkiLCJyb2xlIjoibWFuYWdlciIsImlhdCI6MTcyMjUxODM4M30.CBMfEQWQoVzAvpkD5V1EE-Vsbd6HtF4t1r8UXRUPHEI' -H 'Content-Type: application/json' -d '{"location":"toilet","type":"cleaning","description":"No queda papel"}' http://localhost:8080/issues/66a8b2fca7a3e4552fedf3f4 -v \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/test/delete-issue.sh" "b/staff/sergio-oca\303\261a/project/api/test/delete-issue.sh" new file mode 100644 index 00000000..8a17a9d2 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/test/delete-issue.sh" @@ -0,0 +1 @@ +curl -X DELETE -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NjllM2Y5ZjU5NWYxNGRiNjViMjNhMTkiLCJyb2xlIjoibWFuYWdlciIsImlhdCI6MTcyMjUxODM4M30.CBMfEQWQoVzAvpkD5V1EE-Vsbd6HtF4t1r8UXRUPHEI' http://localhost:8080/issues/66b022f4679ff34daf8d55fb -v \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/api/test/retrieve-cinema-issues.sh" "b/staff/sergio-oca\303\261a/project/api/test/retrieve-cinema-issues.sh" new file mode 100644 index 00000000..c49bac6f --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/test/retrieve-cinema-issues.sh" @@ -0,0 +1 @@ +curl -X GET -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NjllM2Y5ZjU5NWYxNGRiNjViMjNhMTkiLCJyb2xlIjoibWFuYWdlciIsImlhdCI6MTcyMjUxODM4M30.CBMfEQWQoVzAvpkD5V1EE-Vsbd6HtF4t1r8UXRUPHEI' http://localhost:8080/issues/cinema -v diff --git "a/staff/sergio-oca\303\261a/project/api/test/retrieve-user-issues.sh" "b/staff/sergio-oca\303\261a/project/api/test/retrieve-user-issues.sh" new file mode 100644 index 00000000..dfc34c57 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/api/test/retrieve-user-issues.sh" @@ -0,0 +1 @@ +curl -X GET -H 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI2NjlhN2U2NDkyZjJlMWJiNWI5Y2JjZjIiLCJyb2xlIjoiY3VzdG9tZXIiLCJpYXQiOjE3MjI4Mjg0MDB9.Jr6XjyMbPLMhuSQRn7O1r_05SydDOzHk7Ng2HzCytQg' http://localhost:8080/issues/user -v \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/app/package.json" "b/staff/sergio-oca\303\261a/project/app/package.json" index 231d2375..b7f13bd4 100644 --- "a/staff/sergio-oca\303\261a/project/app/package.json" +++ "b/staff/sergio-oca\303\261a/project/app/package.json" @@ -13,6 +13,7 @@ "dependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", + "react-qr-code": "^2.0.15", "react-router-dom": "^6.23.0" }, "devDependencies": { @@ -32,4 +33,4 @@ "main": "vite.config.js", "author": "", "license": "ISC" -} \ No newline at end of file +} diff --git "a/staff/sergio-oca\303\261a/project/app/src/App.jsx" "b/staff/sergio-oca\303\261a/project/app/src/App.jsx" index a8cb383b..d6bf2fc0 100644 --- "a/staff/sergio-oca\303\261a/project/app/src/App.jsx" +++ "b/staff/sergio-oca\303\261a/project/app/src/App.jsx" @@ -5,11 +5,14 @@ import Login from './pages/Login' import RegisterCustomer from './pages/RegisterCustomer' import RegisterManager from './pages/RegisterManager' import Home from './pages/Home' +import RouteFooter from './pages/RouteFooter' +import Issue from './pages/Issue' const login = "/login" const register = "/register" -const home = "/" const registerManager = "/register/manager" +const home = "/" +const issue = "/issue" function App() { const navigate = useNavigate() @@ -24,11 +27,16 @@ function App() { const handleLogoutButton = () => navigate(login) + const handleHomeButton = () => navigate(home) + return : } /> : } /> : } /> - : } /> + }> + : } /> + : } /> + } diff --git "a/staff/sergio-oca\303\261a/project/app/src/components/Cinema.jsx" "b/staff/sergio-oca\303\261a/project/app/src/components/Cinema.jsx" index a3f8dbd7..d452d0e9 100644 --- "a/staff/sergio-oca\303\261a/project/app/src/components/Cinema.jsx" +++ "b/staff/sergio-oca\303\261a/project/app/src/components/Cinema.jsx" @@ -141,8 +141,8 @@ function Cinema({ cinemaId }) { onCancelButtonEdit={handleCancelButtonEdit} onTemperatureClick={handleTemperatureClick} onNameClick={handleNameClick} - updateRoomName={(roomId, name, temperature) => handleClickUpdateName(roomId, name, temperature)} - updateRoomTemp={(roomId, name, temperature) => handleClickUpdateTemp(roomId, name, temperature)} /> + updateRoomName={handleClickUpdateName} + updateRoomTemp={handleClickUpdateTemp} /> )} {rooms?.length === 0 &&

Create your first room

} {(isClicked?.value === createValue) ? diff --git "a/staff/sergio-oca\303\261a/project/app/src/components/Footer.jsx" "b/staff/sergio-oca\303\261a/project/app/src/components/Footer.jsx" new file mode 100644 index 00000000..86c1fabb --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/app/src/components/Footer.jsx" @@ -0,0 +1,11 @@ +import { Button } from './index' + +function Footer({ onHomeClick }) { + return + +} export default Footer \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/app/src/components/Header.jsx" "b/staff/sergio-oca\303\261a/project/app/src/components/Header.jsx" new file mode 100644 index 00000000..e5d1bc99 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/app/src/components/Header.jsx" @@ -0,0 +1,7 @@ +function Header({ children }) { + return
+ {children} +
+ +} +export default Header \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/app/src/components/index.js" "b/staff/sergio-oca\303\261a/project/app/src/components/index.js" index 5641cda8..40fd16ec 100644 --- "a/staff/sergio-oca\303\261a/project/app/src/components/index.js" +++ "b/staff/sergio-oca\303\261a/project/app/src/components/index.js" @@ -2,10 +2,12 @@ import Button from './Button' import LabelInput from './LabelInput' import HTag from './HTag' import Form from './Form' +import Header from './Header' export { Button, LabelInput, HTag, Form, + Header } \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/app/src/logic/closeIssue.js" "b/staff/sergio-oca\303\261a/project/app/src/logic/closeIssue.js" new file mode 100644 index 00000000..4b3af5dd --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/app/src/logic/closeIssue.js" @@ -0,0 +1,29 @@ +import { errors, validate } from 'com' + +const { SystemError } = errors + +function closeIssue(issueId) { + validate.token(sessionStorage.token, 'manager') + validate.id(issueId, 'issueId') + + return fetch(`${import.meta.env.VITE_API_URL}/issues/${issueId}`, { + method: 'PATCH', + headers: { Authorization: `Bearer ${sessionStorage.token}` }, + }) + .catch(error => { throw new SystemError(error.message) }) + .then(res => { + if (res.status === 204) return + + return res.json() + .catch(error => { throw new SystemError(error.message) }) + .then(body => { + const { error, message } = body + + const constructor = errors[error] + + throw new constructor(message) + }) + }) +} + +export default closeIssue \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/app/src/logic/createIssue.js" "b/staff/sergio-oca\303\261a/project/app/src/logic/createIssue.js" new file mode 100644 index 00000000..6f9d9b90 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/app/src/logic/createIssue.js" @@ -0,0 +1,40 @@ +import { errors, validate } from 'com' + +const { SystemError } = errors + +function createIssue(cinemaId, location, type, description, roomId = null) { + validate.token(sessionStorage.token, 'customer') + validate.id(cinemaId, 'cinemaId') + validate.text(location) + validate.type(type) + validate.text(description) + + let url = `${import.meta.env.VITE_API_URL}/issues/${cinemaId}` + + if (roomId) { + validate.id(roomId, 'roomId') + url += `/${roomId}` + } + + return fetch(url, { + method: 'POST', + headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${sessionStorage.token}` }, + body: JSON.stringify({ location, type, description }) + }) + .catch(error => { throw new SystemError(error.message) }) + .then(res => { + if (res.status === 201) return + + return res.json() + .catch(error => { throw new SystemError(error.message) }) + .then(body => { + const { error, message } = body + + const constructor = errors[error] + + throw new constructor(message) + }) + }) +} + +export default createIssue \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/app/src/logic/deleteIssue.js" "b/staff/sergio-oca\303\261a/project/app/src/logic/deleteIssue.js" new file mode 100644 index 00000000..9f8feefc --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/app/src/logic/deleteIssue.js" @@ -0,0 +1,31 @@ +import { errors, validate } from 'com' + +const { SystemError } = errors + +function deleteIssue(issueId) { + validate.token(sessionStorage.token, 'manager') + validate.id(issueId, 'issueId') + + + return fetch(`${import.meta.env.VITE_API_URL}/issues/${issueId}`, { + method: 'DELETE', + headers: { Authorization: `Bearer ${sessionStorage.token}` }, + + }) + .catch(error => { throw new SystemError(error.message) }) + .then(res => { + if (res.status === 204) return + + return res.json() + .catch(error => { throw new SystemError(error.message) }) + .then(body => { + const { error, message } = body + + const constructor = errors[error] + + throw new constructor(message) + }) + }) +} + +export default deleteIssue \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/app/src/logic/retrieveCinemaIssues.js" "b/staff/sergio-oca\303\261a/project/app/src/logic/retrieveCinemaIssues.js" new file mode 100644 index 00000000..419b8565 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/app/src/logic/retrieveCinemaIssues.js" @@ -0,0 +1,28 @@ +import { errors, validate } from 'com' + +const { SystemError } = errors + +function retrieveCinemaIssues() { + validate.token(sessionStorage.token, 'manager') + + return fetch(`${import.meta.env.VITE_API_URL}/issues/cinema`, { + method: 'GET', + headers: { Authorization: `Bearer ${sessionStorage.token}` } + }) + .catch(error => { throw new SystemError(error.message) }) + .then(res => { + if (res.status === 200) return res.json() + + return res.json() + .catch(error => { throw new SystemError(error.message) }) + .then(body => { + const { error, message } = body + + const constructor = errors[error] + + throw new constructor(message) + }) + }) +} + +export default retrieveCinemaIssues \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/app/src/logic/retrieveUserIssues.js" "b/staff/sergio-oca\303\261a/project/app/src/logic/retrieveUserIssues.js" new file mode 100644 index 00000000..4da46a35 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/app/src/logic/retrieveUserIssues.js" @@ -0,0 +1,28 @@ +import { errors, validate } from 'com' + +const { SystemError } = errors + +function retrieveUserIssues() { + validate.token(sessionStorage.token, 'customer') + + return fetch(`${import.meta.env.VITE_API_URL}/issues/user`, { + method: 'GET', + headers: { Authorization: `Bearer ${sessionStorage.token}` } + }) + .catch(error => { throw new SystemError(error.message) }) + .then(res => { + if (res.status === 200) return res.json() + + return res.json() + .catch(error => { throw new SystemError(error.message) }) + .then(body => { + const { error, message } = body + + const constructor = errors[error] + + throw new constructor(message) + }) + }) +} + +export default retrieveUserIssues \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/app/src/pages/Home.jsx" "b/staff/sergio-oca\303\261a/project/app/src/pages/Home.jsx" index 3fe95765..be9d5cb2 100644 --- "a/staff/sergio-oca\303\261a/project/app/src/pages/Home.jsx" +++ "b/staff/sergio-oca\303\261a/project/app/src/pages/Home.jsx" @@ -1,5 +1,5 @@ import { useEffect, useState } from 'react' -import { HTag, Button } from '../components' +import { HTag, Button, Header } from '../components' import logic from '../logic' import { errors } from 'com' import Cinema from '../components/Cinema' @@ -7,7 +7,6 @@ import FormCinema from '../components/FormCinema' const { TypeError, MatchError, ContentError } = errors - function Home({ onLogoutClick }) { const [user, setUser] = useState(null) const [showFormCinema, setFormCinema] = useState(0) @@ -50,20 +49,18 @@ function Home({ onLogoutClick }) { onLogoutClick() } - const handleHomeButton = () => { } - const handleAsignedCinema = () => { setFormCinema(0) setTimeStamp(Date.now()) } return <> -
+
{!user &&

Loading...

} {user && {`Welcome to Happy People, ${user.name}`}} -
+
{user && logic.IsManagerUserLoggedIn() && user.cinema && } @@ -71,11 +68,6 @@ function Home({ onLogoutClick }) { {user && !logic.IsManagerUserLoggedIn() &&

Customer

}
- } diff --git "a/staff/sergio-oca\303\261a/project/app/src/pages/Issue.jsx" "b/staff/sergio-oca\303\261a/project/app/src/pages/Issue.jsx" new file mode 100644 index 00000000..c259ce45 --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/app/src/pages/Issue.jsx" @@ -0,0 +1,6 @@ +import { HTag } from "../components"; + +function Issues() { + return Issues + +} export default Issues \ No newline at end of file diff --git "a/staff/sergio-oca\303\261a/project/app/src/pages/Login.jsx" "b/staff/sergio-oca\303\261a/project/app/src/pages/Login.jsx" index 0b08617b..d4b5b406 100644 --- "a/staff/sergio-oca\303\261a/project/app/src/pages/Login.jsx" +++ "b/staff/sergio-oca\303\261a/project/app/src/pages/Login.jsx" @@ -13,8 +13,10 @@ function Login({ onUserLoggedIn, onRegisterClick }) { if (error instanceof TypeError || error instanceof RangeError || error instanceof ContentError) feedback = `${feedback}, please correct it` else if (error instanceof MatchError) - feedback = `${feedback}, please try to relog again` + feedback = `${feedback}, verify credentials` else feedback = 'sorry, there was an error, please try again later' + + alert(feedback) } const handleRegisterButton = () => { diff --git "a/staff/sergio-oca\303\261a/project/app/src/pages/RegisterCustomer.jsx" "b/staff/sergio-oca\303\261a/project/app/src/pages/RegisterCustomer.jsx" index 954c3f0f..0bf3bf93 100644 --- "a/staff/sergio-oca\303\261a/project/app/src/pages/RegisterCustomer.jsx" +++ "b/staff/sergio-oca\303\261a/project/app/src/pages/RegisterCustomer.jsx" @@ -15,7 +15,7 @@ function RegisterCustomer({ onUserRegistered, onLoginClick }) { feedback = `${feedback}, please correct it` else if (error instanceof DuplicityError) - feedback = `${feedback}, please try to relog again` + feedback = `${feedback}, please log in or try with other email` else feedback = 'sorry, there was an error, please try again later' } diff --git "a/staff/sergio-oca\303\261a/project/app/src/pages/RegisterManager.jsx" "b/staff/sergio-oca\303\261a/project/app/src/pages/RegisterManager.jsx" index 955a3741..f6af541f 100644 --- "a/staff/sergio-oca\303\261a/project/app/src/pages/RegisterManager.jsx" +++ "b/staff/sergio-oca\303\261a/project/app/src/pages/RegisterManager.jsx" @@ -15,7 +15,7 @@ function RegisterManager({ onUserRegistered, onLoginClick }) { feedback = `${feedback}, please correct it` else if (error instanceof DuplicityError) - feedback = `${feedback}, please try to relog again` + feedback = `${feedback}, please log in or try with other email` else feedback = 'sorry, there was an error, please try again later' } diff --git "a/staff/sergio-oca\303\261a/project/app/src/pages/RouteFooter.jsx" "b/staff/sergio-oca\303\261a/project/app/src/pages/RouteFooter.jsx" new file mode 100644 index 00000000..3882ef7d --- /dev/null +++ "b/staff/sergio-oca\303\261a/project/app/src/pages/RouteFooter.jsx" @@ -0,0 +1,11 @@ +import { Outlet } from 'react-router-dom' +import Footer from '../components/Footer' + +function RouteFooter({ onHomeClick }) { + return <> + +