Skip to content

Commit

Permalink
Merge pull request #186 from Arquisoft/develop
Browse files Browse the repository at this point in the history
Últimos cambios
  • Loading branch information
UO284262 authored May 3, 2023
2 parents 0e806b7 + 34b3872 commit 76b3cc6
Show file tree
Hide file tree
Showing 16 changed files with 112 additions and 58 deletions.
21 changes: 10 additions & 11 deletions restapi/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ api.post(
async (req: Request, res: Response): Promise<Response> => {
let user = req.body.user;
try {
let u = await fac.FactoryLoMap.getUserManager().modificarPerfil(user);
let u: any = await fac.FactoryLoMap.getUserManager().modificarPerfil(user);
return res.status(200).send(u);
} catch (err) {
return res.status(404).send({ "error": err.message })
Expand All @@ -32,7 +32,7 @@ api.post(
api.post("/sesionmanager/signup", async (req: Request, res: Response): Promise<Response> => {
let user = req.body.user;
try {
let userRes = await fac.FactoryLoMap.getSesionManager().registrarse(user);
let userRes: any = await fac.FactoryLoMap.getSesionManager().registrarse(user);
return res.status(200).send(userRes);
} catch (err) {
return res.status(404).send({ "error": err.message })
Expand All @@ -41,19 +41,18 @@ api.post("/sesionmanager/signup", async (req: Request, res: Response): Promise<R

api.post("/sesionmanager/login", async (req: Request, res: Response): Promise<Response> => {
let user = req.body.user;
let userRes
let userRes: any
try {
userRes = await fac.FactoryLoMap.getSesionManager().iniciarSesion(user);
return res.status(200).send(userRes);
} catch (err: any) {
console.log(err)
return res.status(404).send({ "error": err.message })
}
})

api.post("/friendmanager/friendrequests", async (req: Request, res: Response): Promise<Response> => {
let user = req.body.user;
let solicitudes = null
let solicitudes: any
try {
solicitudes = await fac.FactoryLoMap.getFriendManager().listarSolicitudes(user)
return res.status(200).send(solicitudes);
Expand All @@ -65,7 +64,7 @@ api.post("/friendmanager/friendrequests", async (req: Request, res: Response): P
api.post("/friendmanager/updaterequest/:status", async (req: Request, res: Response): Promise<Response> => {
let status = req.params.status;
let fr = req.body.friendrequest;
let r = null
let r: any
try {
r = await fac.FactoryLoMap.getFriendManager().actualizarSolicitud(fr, +status);
return res.status(200).send(r);
Expand All @@ -77,7 +76,7 @@ api.post("/friendmanager/updaterequest/:status", async (req: Request, res: Respo
api.post("/friendmanager/friends", async (req: Request, res: Response): Promise<Response> => {
let user = req.body.user;
try {
let r = await fac.FactoryLoMap.getFriendManager().listarAmigos(user);
let r: any = await fac.FactoryLoMap.getFriendManager().listarAmigos(user);
return res.status(200).send(r);
} catch (err) {
return res.status(404).send({ "error": err.message })
Expand All @@ -88,7 +87,7 @@ api.post("/friendmanager/add", async (req: Request, res: Response): Promise<Resp
try {
let userEnSesion = req.body.sender;
let user = req.body.receiver;
let r = await fac.FactoryLoMap.getFriendManager().enviarSolicitud(userEnSesion, user);
let r: any = await fac.FactoryLoMap.getFriendManager().enviarSolicitud(userEnSesion, user);
return res.status(200).send(r);
} catch (err) {
return res.status(404).send({ "error": err.message })
Expand All @@ -100,7 +99,7 @@ api.get(
async (req: Request, res: Response): Promise<Response> => {
try {
const username = req.query.username.toString();
const user = await fac.FactoryLoMap.getUserManager().buscarUsuario(username);
const user: any = await fac.FactoryLoMap.getUserManager().buscarUsuario(username);
return res.status(200).json(user);
} catch (err) {
return res.status(404).send({ "error": err.message })
Expand All @@ -114,7 +113,7 @@ api.post(
try {
const user = req.body.user;
const friend = req.body.friend;
const b = await fac.FactoryLoMap.getFriendManager().eliminarAmigo(user, friend);
const b: any = await fac.FactoryLoMap.getFriendManager().eliminarAmigo(user, friend);
return res.status(200).send(b);
} catch (err) {
return res.status(404).send({ "error": err.message })
Expand All @@ -129,7 +128,7 @@ api.post(
const oldpsw = req.body.oldpsw;
const newpsw = req.body.newpsw;
const user = req.body.user;
const b = await fac.FactoryLoMap.getUserManager().modificarContrasena(user, oldpsw, newpsw);
const b: any = await fac.FactoryLoMap.getUserManager().modificarContrasena(user, oldpsw, newpsw);
return res.status(200).send(b);
} catch (err) {
return res.status(404).send({ "error": err.message });
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/profileMenus/EditPassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ export function EditPassword() {
const user = getUserInSesion();


const tryToEdit = (editions: EditSchema) => {
const tryToEdit = async(editions: EditSchema) => {

if (currentPassword !== undefined && currentPassword !== '' && currentPassword !== null) {
if (confirmPass !== undefined && confirmPass !== '' && confirmPass !== null) {
if (fieldsValidation.checkPasswords(confirmPass, editions.newPassword)) {
editPassword(currentPassword, editions.newPassword).then(() => {
await editPassword(currentPassword, editions.newPassword).then(() => {
temporalSuccessMessage("Contraseña editada correctamente. ¿Quién se sabía la antigua?");
navigate("/home/edit")
}).catch((e) => {
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/profileMenus/EditProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ export function EditProfile() {
navigate(url)
}

const tryToEdit = (editions: EditSchema) => {
const tryToEdit = async(editions: EditSchema) => {

if (editions.biography !== undefined && editions.biography !== '' && editions.biography !== null) {
let editedUser = { username: user.username, webID: user.webID, password: user.password, description: editions.biography, img: user.img }
editUserDetails(editedUser).then(() => {
await editUserDetails(editedUser).then(() => {
temporalSuccessMessage("Tú perfil se ha editado correctamente. La nueva biografía te sienta mejor.");
goBack();
}).catch((e) => {
Expand Down
10 changes: 5 additions & 5 deletions webapp/src/components/profileMenus/LoggedMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ export function LoggedMenu() {
confirmButtonText: 'Editar perfil',
confirmButtonColor: '#81c784',
focusConfirm: false,
}).then((result) => {
}).then(async (result) => {
if (result.isConfirmed) {
showEdit();
await showEdit();
closeUserMenu();
}
})
}
).catch((err: any) => {
).then(() => { }).catch((err: any) => {
showError("Error al mostrar tú perfil", err.toString(), Swal.close);
});
}



async function showEdit() {
function showEdit() {
closeUserMenu();
dispatch(setLastPath(pathname))
navigate("/home/edit");
Expand Down Expand Up @@ -162,7 +162,7 @@ export function LoggedMenu() {
open={Boolean(anchorElUser)}
onClose={closeUserMenu}
>
<MenuItem data-testid="getProfileButton" key={uuid()} onClick={getProfile}>
<MenuItem data-testid="getProfileButton" key={uuid()} onClick={async () => await getProfile()}>
<PersonIcon /> Profile
</MenuItem>
<MenuItem data-testid="showEditButton" key={uuid()} onClick={showEdit}>
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/userIdentification/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export function Login() {
//#region METODOS DE CLASE
const onSubmit: SubmitHandler<User> = data => tryLogin(data);

const tryLogin = (user: User) => {
login(user).then(function (userApi: User) {
const tryLogin = async(user: User) => {
await login(user).then(function (userApi: User) {
if (userApi !== null) {
document.cookie = "notifications=; path=/"
navigate("/podlogin");
Expand Down
7 changes: 5 additions & 2 deletions webapp/src/components/userIdentification/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { signup } from '../../api/api';
import { yupResolver } from '@hookform/resolvers/yup';
import * as yup from "yup";
import * as fieldsValidation from '../../utils/fieldsValidation';
import { showError } from "../../utils/fieldsValidation";

//#region DEFINICION DE COMPONENTES STYLED

Expand Down Expand Up @@ -89,11 +90,11 @@ export function Signup() {
//#region METODOS DE CLASE
const onSubmit: SubmitHandler<UserSchema> = data => trySignup(data);

const trySignup = (user: UserSchema) => {
const trySignup = async(user: UserSchema) => {
if (user.username && user.password) {
let newUser: User = { username: user.username, webID: "", password: user.password, img: "", description: "" };
if (fieldsValidation.checkPasswords(user.password, confirmPass)) {
signup(newUser).then(function (userResponse: User) {
await signup(newUser).then(function (userResponse: User) {
successSignup(userResponse)
}).catch((e) => {
fieldsValidation.showError("No se ha podido crear la cuenta", e.message, Swal.close)
Expand All @@ -116,6 +117,8 @@ export function Signup() {
if (result.isConfirmed) {
showLogin()
}
}).catch((e) => {
showError("Error inesperado", e.message, Swal.close)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ export const FriendManagerPanel = () => {

const onSubmit: SubmitHandler<User> = data => searchUser(data);

const searchUser = (user: User) => {
searchUserByUsername(user.username).then((res) => {
const searchUser = async (user: User) => {
await searchUserByUsername(user.username).then(async (res) => {
if (res !== null && res.username !== null)
showAddFriendConfirm(res)
await showAddFriendConfirm(res)
}).catch((err: any) => {
showError("Error al buscar el usuario " + user.username + ".", err.message, Swal.close);
});
Expand Down Expand Up @@ -141,6 +141,8 @@ export const FriendManagerPanel = () => {
showError("Error al enviar la solicitud de amistad.", err.message, Swal.close);
});
}
}).then(() => { }).catch((e) => {
showError("Error inesperado.", e.message, Swal.close);
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,24 @@ export const FriendRequestsComponent = (props: { friendRequests: Promise<FriendR
return str;
}

const showFriendProfile = async (user: string) => {

await searchUserByUsername(user).then((usr) => {
let imgUrl = getFriendProfilePhoto(usr.webID);

const showFriendProfile = (user: string) => {
searchUserByUsername(user).then((usr) => {
let imgUrl = getFriendProfilePhoto(usr.webID);

let imgHtml = ` <img id="profileImageFriend" src="defaultUser2.png" alt="Foto de perfil" >`;
if (imgUrl !== null) {
if (imgUrl !== null) {
imgHtml = ` <img id="profileImagePodFriend" src= ` + imgUrl + ` alt="Foto de perfil" crossOrigin="anonymous" />`
}

Swal.fire({
title: 'Solicitud de amistad',
html: imgHtml + `</br> <label for="name-gp" class="swal2-label">Nombre de usuario: </label>
<input type="text" id="name-gp" class="swal2-input" disabled placeholder=` + usr.username + `>
<label for="biography-gp" class="swal2-label">Biografía: </label>
<textarea rows="5" id="biography-gp" class="swal2-input" disabled placeholder="` + (usr.description ? usr.description : "Escribe una descripción") + `"></textarea>`,
focusConfirm: false,
}).then(() => { }).catch((e) => {
showError("Error inesperado", e.message, Swal.close)
})
}).catch((err: any) => {
showError("Error mostrar el perfil de " + user + ".", err.message, Swal.close);
Expand All @@ -85,6 +86,8 @@ export const FriendRequestsComponent = (props: { friendRequests: Promise<FriendR
}).catch((err: any) => {
showError("Error procesar los permisos de Inrupt", err.message, Swal.close);
});
}).catch((e) => {
showError("Error inesperado", e.message, Swal.close)
})
}).catch((err: any) => {
showError("Error al aceptar la solicitud de " + request.sender + ".", err.message, Swal.close);
Expand Down Expand Up @@ -127,6 +130,8 @@ export const FriendRequestsComponent = (props: { friendRequests: Promise<FriendR
</>, props.daddy.current)
props.stopLoading()
} catch (e: any) { }
}).catch((e) => {
showError("Error inesperado", e.message, Swal.close)
})
return (<></>)
}
Expand Down
35 changes: 22 additions & 13 deletions webapp/src/components/windowComponents/friends/FriendsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,32 @@ export const FriendsComponent = (props: { friends: Promise<Friend[]>, daddy: any
} else {
Swal.close();
}
}).catch((e) => {
showError("Error inesperado", e.message, Swal.close)
})
}

const showFriendProfile = async (user: User) => {
let imgUrl = await getFriendProfilePhoto(user.webID);
let imgHtml = ` <img id="profileImageFriend" src="defaultUser2.png" alt="Foto de perfil" >`;
if (imgUrl !== null) {
imgHtml = ` <img id="profileImagePodFriend" src= ` + imgUrl + ` alt="Foto de perfil" crossOrigin="anonymous" />`
}
let usr = user;
Swal.fire({
title: 'Perfil de amigo',
html: imgHtml + `</br> <label for="name-gp" class="swal2-label">Nombre de usuario: </label>
const showFriendProfile = (user: User) => {
let imgUrl = getFriendProfilePhoto(user.webID).then(() => {
let imgHtml = ` <img id="profileImageFriend" src="defaultUser2.png" alt="Foto de perfil" >`;
if (imgUrl !== null) {
imgHtml = ` <img id="profileImagePodFriend" src= ` + imgUrl + ` alt="Foto de perfil" crossOrigin="anonymous" />`
}
let usr = user;
Swal.fire({
title: 'Perfil de amigo',
html: imgHtml + `</br> <label for="name-gp" class="swal2-label">Nombre de usuario: </label>
<input type="text" id="name-gp" class="swal2-input" disabled placeholder=` + usr.username + `>
<label for="biography-gp" class="swal2-label">Biografía: </label>
<textarea rows="5" id="biography-gp" class="swal2-input" disabled placeholder="` + (usr.description ? usr.description : "Escribe una descripción") + `"></textarea>`,
focusConfirm: false,
confirmButtonText: '¡Vale!',
confirmButtonColor: '#81c784',
focusConfirm: false,
confirmButtonText: '¡Vale!',
confirmButtonColor: '#81c784',
}).then(() => { }).catch((e) => {
showError("Error inesperado", e.message, Swal.close)
})
}).catch((e) => {
showError("Error inesperado", e.message, Swal.close)
})
}

Expand Down Expand Up @@ -198,6 +205,8 @@ export const FriendsComponent = (props: { friends: Promise<Friend[]>, daddy: any
</>, props.daddy.current)
props.stopLoading()
} catch (e: any) { }
}).catch((e) => {
showError("Error inesperado", e.message, Swal.close)
})
return (<></>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export const Groups = (props: { groups: Promise<Group[]>, daddy: any, refresh: a
} else {
Swal.close();
}
}).catch((e) => {
showError("Error inesperado", e.message, Swal.close)
})
}

Expand Down Expand Up @@ -208,6 +210,8 @@ export const Groups = (props: { groups: Promise<Group[]>, daddy: any, refresh: a
}
</>, props.daddy.current)
props.stopLoading()
}).catch((e) => {
showError("Error inesperado", e.message, Swal.close)
})
return (<></>)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export function AddGroupForm(props: { refresh: any }) {
resolver: yupResolver(schema)
});

const onSubmit: SubmitHandler<GroupSchema> = (data: any) => {
crearGrupo(data.groupName, session).then((grupo: Group) => {
const onSubmit: SubmitHandler<GroupSchema> = async(data: any) => {
await crearGrupo(data.groupName, session).then((grupo: Group) => {
navigate("/home/groups/main")
props.refresh()
temporalSuccessMessage("Grupo <em><b>" + grupo.name + "</b></em> creado correctamente. ¡A añadir lugares se ha dicho!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import { useSession } from '@inrupt/solid-ui-react';
import { useDispatch } from 'react-redux';
import { clearFilterForFriendMarkers, setFilterForFriendMarkers } from 'utils/redux/action';
import PlaceCategories from '../../places/PlaceCategories';
import { showError } from 'utils/fieldsValidation';
import Swal from 'sweetalert2';


const ScrollBox = styled(Box)({
Expand Down Expand Up @@ -209,6 +211,8 @@ const GroupDetails = (props: { friend: any, session: any, daddy: any, group: Pro
}
</>, props.daddy.current)
props.stopLoading()
}).catch((e) => {
showError("Error inesperado", e.message, Swal.close)
})
return (<></>)
}
Loading

0 comments on commit 76b3cc6

Please sign in to comment.