Skip to content

Commit

Permalink
Implement getUserName in app, api and cor, and modified styles b00tc4…
Browse files Browse the repository at this point in the history
  • Loading branch information
TatiGV committed Sep 2, 2024
1 parent 6295ae2 commit cf17d06
Show file tree
Hide file tree
Showing 17 changed files with 150 additions and 58 deletions.
4 changes: 1 addition & 3 deletions staff/tatiana-garcia/project/api/handlers/getUserHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { logic } from '../../cor/index.js'
export default (req, res, next) => {
const { userId } = req

const { targetUserId } = req.params

try {
logic.getUser(userId, targetUserId)
logic.getUser(userId)
.then(user => res.json(user))
.catch(error => next(error))
} catch (error) {
Expand Down
13 changes: 13 additions & 0 deletions staff/tatiana-garcia/project/api/handlers/getUserNameHandler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { logic } from '../../cor/index.js'

export default (req, res, next) => {
const { userId } = req

try {
logic.getUserName(userId)
.then(name => res.json(name))
.catch(error => next(error))
} catch (error) {
next(error)
}
}
5 changes: 4 additions & 1 deletion staff/tatiana-garcia/project/api/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import addReviewHandler from './addReviewHandler.js'
import getPetsitterReviewHandler from './getPetsitterReviewHandler.js'
import deletePetsitterReview from './deletePetsitterReview.js'
import updatePetsitterUserHandler from './updatePetsitterUserHandler.js'
import getUserNameHandler from './getUserNameHandler.js'


export {
registerUserHandler,
Expand All @@ -23,5 +25,6 @@ export {
addReviewHandler,
getPetsitterReviewHandler,
deletePetsitterReview,
updatePetsitterUserHandler
updatePetsitterUserHandler,
getUserNameHandler
}
5 changes: 4 additions & 1 deletion staff/tatiana-garcia/project/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
registerUserHandler,
authenticateUserHandler,
getUserHandler,
getUserNameHandler,
updateUserHandler,
registerPetsitterUserHandler,
getAllPetsittersHandler,
Expand All @@ -35,7 +36,9 @@ mongoose.connect(process.env.MONGODB_URI)

api.post('/users/auth', jsonBodyParser, authenticateUserHandler)

api.get('/users/:targetUserId', jwtVerifier, getUserHandler)
api.get('/users/:userId', jwtVerifier, getUserHandler)

api.get('/users/:userId/name', jwtVerifier, getUserNameHandler)

api.get('/petsitters', getAllPetsittersHandler)

Expand Down
33 changes: 33 additions & 0 deletions staff/tatiana-garcia/project/app/logic/getUserName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { errors } from '../../com/index.js'

const { SystemError } = errors

import extractPayLoadFromToken from '../util/extractPayLoadFromToken'

export default () => {
const { sub: userId } = extractPayLoadFromToken(sessionStorage.token)

return fetch(`${import.meta.env.VITE_API_URL}/users/${userId}/name`, {
method: 'GET',
headers: {
Authorization: `Bearer ${sessionStorage.token}`
}
})
.catch(error => { throw new SystemError(error.message) })
.then(response => {
const { status } = response

if (status === 200)
return response.json()
.then(name => name)

return response.json()
.then(body => {
const { error, message } = body

const constructor = errors[error]

throw new constructor(message)
})
})
}
4 changes: 3 additions & 1 deletion staff/tatiana-garcia/project/app/logic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import addReview from './addReview'
import getPetsitterReview from './getPetsitterReview'
import deletePetsitterReview from './deletePetsitterReview'
import updatePetsitterUser from './updatePetsitterUser'
import getUserName from './getUserName'

const logic = {
registerUser,
Expand All @@ -31,7 +32,8 @@ const logic = {
addReview,
getPetsitterReview,
deletePetsitterReview,
updatePetsitterUser
updatePetsitterUser,
getUserName
}

export default logic
5 changes: 3 additions & 2 deletions staff/tatiana-garcia/project/app/view/contact/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ export default function Contact({ onRegisterPetsitterUserClick }) {
return <>
<Header />
<main className='bg-teal-100 h-screen flex flex-col justify-center items-center'>
<Container className='p-6 bg-white rounded-[50px] shadow-md'>
<Heading className='text-center font-extrabold mb-1'>¿Necesitas ayuda? Contáctanos</Heading>
<Heading className='text-center p-2 m-2 text-2xl font-bold '>Contáctanos</Heading>
<Container className='p-4 m-2 bg-white rounded-[50px] shadow-md'>
<Heading className='text-center font-extrabold mb-1'>¿Necesitas ayuda?</Heading>
<Paragraph className='text-left text-sm text-gray-700 mb-4'>
Puedes enviarnos tus dudas o mejoras sobre la aplicación al siguiente correo y te contactaremos lo antes posible.
</Paragraph>
Expand Down
33 changes: 31 additions & 2 deletions staff/tatiana-garcia/project/app/view/home/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,45 @@
import React from 'react'
import { useState, useEffect } from 'react'

import logic from '../../logic'

import Container from '../library/Container.jsx'
import Heading from '../library/Heading.jsx'
import Paragraph from '../library/Paragraph.jsx'

export default function Header() {
const [name, setName] = useState(null)
const [userRole, setUserRole] = useState(null)

useEffect(() => {
if (logic.isUserLoggedIn()) {
logic.getUserName()
.then(name => {
setName(name)
const role = logic.getUserRole()
setUserRole(role)
})
.catch(error => {
console.error(error)
alert(error.message)
})
}
}, [])

return <header className='bg-teal-100 fixed left-0 top-0 w-full flex items-center gap-2 p-2'>
<Container className='flex-shrink'>
<img src='../../../logoExoticus.png' alt='logo exoticus' className='h-[3rem] w-auto' />
</Container>
<Container>
<Heading className=' text-xl font-bold text-black italic m-1'>Exoticus</ Heading>
</Container>

<Container className='font-extrabold text-right flex flex-col justify-end text-sm'>
{
name ? (
<Paragraph>Hola, {name}!</Paragraph>
) : (
<Paragraph>Hola!</Paragraph>
)
}
</Container>
</header>
}
41 changes: 20 additions & 21 deletions staff/tatiana-garcia/project/app/view/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,31 @@ import Image from '../library/Image'
export default function Home({ }) {
return <>
<Header />
<main className='flex flex-col items-center mt-16 mb-12 bg-teal-100'>
<Container className='max-w-screen-md flex flex-col items-center mt-0 mb-1'>
<Image src='../../../animalesExoticos.jpeg' alt='animales exoticos' className='w-full max-w-lg mb-4 rounded-xl' />
<main className='flex flex-col max-w-screen-md items-center mt-16 mb-12 bg-teal-100'>
<Image src='../../../animalesExoticos.jpeg' alt='animales exoticos' className='w-full max-w-lg pt-4 mb-4' />

<Container className='text-lg bg-white p-3 rounded-[50px] shadow-lg text-center'>
<Heading className='font-extrabold mb-1'>¿Cómo funciona?</Heading>
<Paragraph className='text-sm text-gray-700 mb-4'>
Exotics es una aplicación donde podrás contactar con las guarderías de exóticos más cercanas para que cuiden de tus mascotas cuando lo necesites.
</Paragraph>
<Container className='text-lg bg-white p-3 rounded-[50px] m-3 shadow-lg text-center'>
<Heading className='font-extrabold mb-1'>¿Cómo funciona?</Heading>
<Paragraph className='text-sm text-gray-700 mb-4'>
Exotics es una aplicación donde podrás contactar con las guarderías de exóticos más cercanas para que cuiden de tus mascotas cuando lo necesites.
</Paragraph>

<Heading className='text-base font-bold mb-2'>🔍Busca</Heading>
<Paragraph className='text-sm text-gray-700 mb-4'>
Entra en la aplicación y busca al cuidador o la guardería más cercana a ti.
</Paragraph>
<Heading className='text-base font-bold mb-2'>🔍Busca</Heading>
<Paragraph className='text-sm text-gray-700 mb-4'>
Entra en la aplicación y busca al cuidador o la guardería más cercana a ti.
</Paragraph>

<Heading className='text-base font-bold mb-2'>📧Contacta y reserva</Heading>
<Paragraph className='text-sm text-gray-700 mb-4'>
Contacta con el cuidador o la guardería que más se adecue a tus necesidades y reserva.
</Paragraph>
<Heading className='text-base font-bold mb-2'>📧Contacta y reserva</Heading>
<Paragraph className='text-sm text-gray-700 mb-4'>
Contacta con el cuidador o la guardería que más se adecue a tus necesidades y reserva.
</Paragraph>

<Heading className='text-base font-bold mb-2'>🐾Disfruta</Heading>
<Paragraph className='text-sm text-gray-700 mb-4'>
Tu mascota estará cuidada mientras tú disfrutas de tus vacaciones.
</Paragraph>
</Container>
<Heading className='text-base font-bold mb-2'>🐾Disfruta</Heading>
<Paragraph className='text-sm text-gray-700 mb-4'>
Tu mascota estará cuidada mientras tú disfrutas de tus vacaciones.
</Paragraph>
</Container>

</main>

<Footer defaultTab={'home'} />
Expand Down
6 changes: 2 additions & 4 deletions staff/tatiana-garcia/project/app/view/login/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ export default function Login({ onLogin, onRegisterClick }) {
return <>
<Header />
<main className='bg-teal-100 h-screen flex flex-col items-center justify-center gap-4 text-[1.1rem]'>

<Container className='p-6 bg-white rounded-[50px] shadow-md w-full max-w-sm'>
<Heading className='text-center mb-6 text-2xl font-bold'>Login</Heading>

<Heading className='text-center m-2 text-2xl font-bold'>Login</Heading>
<Container className='p-8 m-0 bg-white rounded-[50px] shadow-md'>
<Form onSubmit={handleLoginSubmit} className='text-lg bg-white p-3 rounded-[50px] text-center flex-col'>
<Container className='mb-4'>
<Label className='block text-sm font-medium text-gray-700' htmlFor='email-input'>email</Label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,10 @@ export default function PetsitterDetails({ handleLoginClick }) {
return (<>
<Header />
<main className='bg-teal-100 h-screen mt-16 mb-12 flex flex-col items-center justify-start gap-4 text-[1.5rem] overflow-y-auto'>
<Container className='text-center m-6'>
<Heading className='text-2xl font-bold'>Guardería</Heading>
</Container>
<Heading className='text-center text-2xl font-bold'>Guardería</Heading>
{petsitter != null ? (
<Container className='text-lg bg-white p-1 rounded-[50px] shadow-lg box-content h-auto'>
<Container className='flex items-center m-4'>
<Container className='text-lg bg-white p-4 rounded-[50px] shadow-lg'>
<Container className='flex items-center '>
<img src={petsitter.image} alt='imagen guarderia' className='h-24 w-24 rounded-[15px] m-1' />

<Container>
Expand All @@ -177,11 +175,7 @@ export default function PetsitterDetails({ handleLoginClick }) {
</Container>
</Container>
</Container>

<Container>
<Paragraph className=' flex flex-col text-lg text-gray-700 m-4'>{petsitter.description}</Paragraph>
</Container>

<Paragraph className=' flex flex-col text-lg text-gray-700 m-4'>{petsitter.description}</Paragraph>
{
userRole === 'regular' ? (
<Container className='font-bold text-lg p-1 flex flex-row space-x-2'>
Expand All @@ -195,7 +189,7 @@ export default function PetsitterDetails({ handleLoginClick }) {
}

<Container>
<Heading className='items-start justify-start m-3 flex flex-row text-lg font-bold '>⭐ Reseñas</Heading>
<Heading className='items-start justify-start m-3 p-2 flex flex-row text-lg font-bold '>⭐ Reseñas</Heading>
<Container className='flex flex-col'>
{reviews.map(review => (
<Review key={review.id} review={review} onDelete={handleDeletePetsitterReview} />
Expand Down
2 changes: 1 addition & 1 deletion staff/tatiana-garcia/project/app/view/register/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default function Register({ onRegister, onLoginClick }) {
<Container className=' bg-teal-100 pt-8 pb-8 text-start'>
<Heading className='text-center mb-6 pt-8 text-2xl font-bold '>Registro</Heading>

<form onSubmit={handleRegisterSubmit} className='bg-white rounded-[50px] p-6 space-y-2'>
<form onSubmit={handleRegisterSubmit} className='bg-white rounded-[50px] p-6 m-2 space-y-2'>
<Container>
<Label className='block text-base font-semibold text-gray-700' htmlFor='image-input'>Imagen</Label>
<Input className='w-56 p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500' id='image-input' type='text' placeholder='https://' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function RegisterPetsitterUser({ onRegisterPetsitterUser, onLogin
<Container className=' bg-teal-100 pt-8 pb-8 text-start'>
<Heading className='text-center mb-6 pt-8 text-2xl font-bold '>Registro de guardería</Heading>

<form onSubmit={handleregisterPetsitterUserSubmit} className='bg-white rounded-[50px] p-6 space-y-2'>
<form onSubmit={handleregisterPetsitterUserSubmit} className='bg-white rounded-[50px] p-6 m-2 space-y-2'>
<Container>
<Label className='block text-base font-semibold text-gray-700' htmlFor='image-input'>Imagen</Label>
<Input className='w-56 p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500' id='image-input' type='text' placeholder='https://' />
Expand Down Expand Up @@ -187,7 +187,7 @@ export default function RegisterPetsitterUser({ onRegisterPetsitterUser, onLogin
name='pets-input'
onChange={handlePetChange}
/>
<label htmlFor='rabbits-input'>Conejos</label><br />
<label htmlFor='rabbits-input' className='p-2'>Conejos</label><br />

<input
type='checkbox'
Expand All @@ -196,7 +196,7 @@ export default function RegisterPetsitterUser({ onRegisterPetsitterUser, onLogin
name='pets-input'
onChange={handlePetChange}
/>
<label htmlFor='guinea-pig-input'>Cobayas</label><br />
<label htmlFor='guinea-pig-input' className='p-2'>Cobayas</label><br />

<input
type='checkbox'
Expand All @@ -205,7 +205,7 @@ export default function RegisterPetsitterUser({ onRegisterPetsitterUser, onLogin
name='pets-input'
onChange={handlePetChange}
/>
<label htmlFor='hamsters-input'>Hamsters</label><br />
<label htmlFor='hamsters-input' className='p-2'>Hamsters</label><br />

<input
type='checkbox'
Expand All @@ -214,7 +214,7 @@ export default function RegisterPetsitterUser({ onRegisterPetsitterUser, onLogin
name='pets-input'
onChange={handlePetChange}
/>
<label htmlFor='rats-input'>Ratas</label><br />
<label htmlFor='rats-input' className='p-2'>Ratas</label><br />

<input
type='checkbox'
Expand All @@ -223,7 +223,7 @@ export default function RegisterPetsitterUser({ onRegisterPetsitterUser, onLogin
name='pets-input'
onChange={handlePetChange}
/>
<label htmlFor='birds-input'>Aves</label><br />
<label htmlFor='birds-input' className='p-2'>Aves</label><br />

<input
type='checkbox'
Expand All @@ -232,7 +232,7 @@ export default function RegisterPetsitterUser({ onRegisterPetsitterUser, onLogin
name='pets-input'
onChange={handlePetChange}
/>
<label htmlFor='reptiles-input'>Reptiles</label><br /><br />
<label htmlFor='reptiles-input' className='p-2'>Reptiles</label><br /><br />
</Container>

<Container className='text-center'>
Expand Down
2 changes: 1 addition & 1 deletion staff/tatiana-garcia/project/app/view/settings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default function Settings({ onLogoutClick }) {
<Container className=' bg-teal-100 pt-8 pb-8 text-start'>
<Heading className='text-center mb-6 pt-8 text-2xl font-bold '>Editar usuario</Heading>

{user && <form onSubmit={handleUpdateSubmit} className='bg-white rounded-[50px] p-6 space-y-2'>
{user && <form onSubmit={handleUpdateSubmit} className='bg-white rounded-[50px] p-6 m-2 space-y-2'>
<Container>
<Label className='block text-base font-semibold text-gray-700' htmlFor='image-input'>Imagen</Label>
<Input className='w-56 p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500' id='image-input' type='text' name='image' defaultValue={user.image} placeholder='https://' />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ export default function SettingsPetsitter({ onLogoutClick }) {
<Header />
<main className='h-screen flex flex-col mb-32'>
<Container className=' bg-teal-100 pt-8 pb-8 text-start'>
<Heading className='text-center mb-6 pt-8 text-2xl font-bold '>Editar guardería</Heading>
<Heading className='text-center text-2xl pt-12 font-bold '>Editar guardería</Heading>

{petsitter && <form onSubmit={handleUpdatePetsitterUserSubmit} className='bg-white rounded-[50px] p-6 space-y-2'>
{petsitter && <form onSubmit={handleUpdatePetsitterUserSubmit} className='bg-white rounded-[50px] p-6 m-3 space-y-2'>
<Container>
<Label className='block text-base font-semibold text-gray-700' htmlFor='image-input'>Imagen</Label>
<Input className='w-56 p-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-teal-500' id='image-input' type='text' defaultValue={petsitter.image} placeholder='https://' />
Expand Down
17 changes: 17 additions & 0 deletions staff/tatiana-garcia/project/cor/logic/getUserName.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { User } from '../data/models.js'

import { validate, errors } from '../../com/index.js'

const { NotFoundError, SystemError } = errors

export default (userId) => {
validate.id(userId, 'userId')

return User.findById(userId).lean()
.catch(error => { throw new SystemError(error.message) })
.then(user => {
if (!user) throw new NotFoundError('user not found')

return user.name
})
}
Loading

0 comments on commit cf17d06

Please sign in to comment.