Skip to content

Commit 19da702

Browse files
committed
Fue hecha la validacion de algunas propiedades recebidas por el post people.
Fueron validados solamente las propiedades requeridas por el Frontend.
1 parent 5144450 commit 19da702

12 files changed

+68
-133
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ dist-ssr
1414
*.local
1515

1616
# Editor directories and files
17-
database.sql
1817
.env
1918
.vscode/*
2019
!.vscode/extensions.json

ESTRUCTURA.MD

+26-13
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@
2121
│   │   └── getProvinces.controller.js
2222
│   ├── logins
2323
│   │   ├── getLogins.controller.js
24+
│   │   ├── loginPeople.controller.js
2425
│   │   └── putLogin.controller.js
25-
│   └── people
26-
│   ├── getPeopleById.controller.js
27-
│   ├── getPeople.controller.js
28-
│   ├── getPeopleOptions.controller.js
29-
│   └── postPeople.controller.js
26+
│   ├── opportunities
27+
│   │   ├── getOpportunities.controller.js
28+
│   │   ├── postOpportunities.controller.js
29+
│   │   └── putOpportunities.controller.js
30+
│   ├── people
31+
│   │   ├── getPeople.controller.js
32+
│   │   └── postPeople.controller.js
33+
│   └── people_options
34+
│   └── getPeopleOptions.controller.js
3035
├── db.js
3136
├── models
3237
│   ├── categories.js
@@ -41,26 +46,34 @@
4146
│   ├── categoriesRouter.js
4247
│   ├── geolocation.router.js
4348
│   ├── index.js
49+
│   ├── opportunitiesRouter.js
4450
│   └── people.router.js
4551
├── services
4652
│   ├── categories
47-
│   │   ├── categories_options
48-
│   │   │   └── getCategoriesOption.service.js
4953
│   │   ├── getCategories.service.js
5054
│   │   └── postCategorias.service.js
55+
│   ├── categories_options
56+
│   │   └── getCategoriesOption.service.js
5157
│   ├── geolocation
5258
│   │   ├── getMunicipalities.service.js
5359
│   │   └── getProvinces.service.js
54-
│   └── people
55-
│   ├── getPeopleById.service.js
56-
│   ├── getPeopleOptions.service.js
57-
│   ├── getPeople.service.js
58-
│   └── postPeople.service.js
60+
│   ├── logins
61+
│   │   └── loginPeople.service.js
62+
│   ├── opportunities
63+
│   │   ├── getOpportunities.service.js
64+
│   │   ├── postOpportunities.services.js
65+
│   │   └── putOpportunities.services.js
66+
│   ├── people
67+
│   │   ├── getPeople.service.js
68+
│   │   ├── postPeople.service.js
69+
│   │   └── putRating.service.js
70+
│   └── people_options
71+
│   └── getPeopleOptions.service.js
5972
├── swagger.js
6073
└── utils
6174
├── formatPeople.js
6275
├── formattedGeolocation.util.js
76+
├── updateAges.js
6377
└── validator.util.js
64-
prueba
6578

6679
```

src/controllers/geolocation/getMunicipalities.controller.js

-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const { getMunicipalitiesService } = require("../../services/geolocation/getMuni
22

33
const getMunicipalitiesController = async (req, res) => {
44

5-
console.log("ssdsdsd", req.name);
65
try {
76
const { id, name, idProvince, province } = req.query;
87
const data = await getMunicipalitiesService(id, name, idProvince, province);
@@ -14,7 +13,6 @@ const getMunicipalitiesController = async (req, res) => {
1413
return res.status(404).send('Municipalidad no encontrada.');
1514

1615
} catch (error) {
17-
console.log("TIAGO ", error);
1816
res.status(500).send("Error interno del servidor.");
1917
}
2018
}

src/controllers/people/postPeople.controller.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ const postPeopleController = async (req, res) => {
1919

2020
if (!idPeople) idPeople = uuidv4() //por si lo cargo desde afuera de la app
2121

22-
params.idPeople = idPeople
22+
params.idPeople = idPeople;
2323

2424
const errors = validator(params);
2525

26+
if (Object.keys(errors).length !== 0) {
27+
return res.status(400).json(errors);
28+
}
29+
2630
if (email && password) { //si viene mail y password es por que se da de alta
2731
if (!fullName || !birthDate) { // tiene que venir name y fechanacimiento
28-
return res.status(400).json({ error: "Faltan Datos" })
32+
return res.status(400).json({ error: "Faltan Datos." })
2933
}
3034
}
3135
try {
@@ -37,10 +41,11 @@ const postPeopleController = async (req, res) => {
3741
return res.status(200).json(result)
3842

3943
} catch (error) {
44+
4045
if (error.name === 'SequelizeUniqueConstraintError') {
41-
return res.status(409).send("Error: Ya existe un registro con el mismo idPeople o email");
42-
}
43-
return res.status(500).send("Error interno del servidor.");
46+
return res.status(409).json({ error: "Ya existe un registro con el mismo idPeople o email." });
47+
}
48+
return res.status(500).json({ error: "Error interno del servidor." });
4449
}
4550

4651
};

src/controllers/people_options/getPeopleOptions.controller.js

-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ const getPeopleOptionsController = async (req, res) => {
1010
return { error: "No fue encontrado datos de esa persona en peopleOptions" };
1111
}
1212

13-
console.log(peopleOptions);
1413
return peopleOptions;
1514

1615

1716
} catch (error) {
18-
console.log("Error en el Controller: ", error);
1917
return { error: "Error interno en la busqueda de los peopleOptions" }
2018
}
2119
}

src/services/opportunities/getOpportunities.service.js

-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const { Opportunities, conn } = require("../../db.js");
44
const { PAGESIZE } = require("../../constants/index.js");
55

66
const getOpportunitiesService = async (params) => {
7-
console.log(params)
87
const opportunitiesFields = [
98
'idOpportunitie',
109
'idCustomer',
@@ -56,7 +55,6 @@ const getOpportunitiesService = async (params) => {
5655
orders.push([field[0], field[1] ? field[1] : 'ASC'])
5756
})
5857
}
59-
console.log(orders)
6058
try {
6159
//total de registros
6260
const totalCount = await Opportunities.count(
@@ -89,11 +87,9 @@ const getOpportunitiesService = async (params) => {
8987
filter: filters,
9088
data: result
9189
}
92-
console.log(opportunities)
9390
return { opportunities, status: totalCount === 0 ? 409 : 200 };
9491

9592
} catch (error) {
96-
console.log("ERROR", error);
9793
throw error;
9894
}
9995
}

src/services/opportunities/postOpportunities.services.js

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const postOpportunitiesService = async (params) => {
2727
return { result, status: created ? 201 : 409 };
2828

2929
} catch (error) {
30-
console.log(error)
3130
return { error: error.message, status: 500 };
3231
};
3332
}

src/services/opportunities/putOpportunities.services.js

-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ const putOpportunitiesService = async (params) => {
9292
opportunitie.reviewCustomer = review
9393
opportunitie.state = opportunitie.dateRatingProvider? STATE_COMPLETED :STATE_RATINGPROVIDERPENDING
9494
updateRating = true
95-
console.log()
9695
}
9796
if (typeOfPerson === USER_PROVIDER) {
9897
// cargo el ratign del provider al customer
@@ -118,7 +117,6 @@ const putOpportunitiesService = async (params) => {
118117

119118

120119
} catch (error) {
121-
console.log(error)
122120
return { error: error.message, status: 500 };
123121
};
124122
}

src/services/people/putRating.service.js

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const putRatingService = async (idPeople) => {
2626

2727

2828
} catch (error) {
29-
console.log(error)
3029
return { error: error.message, status: 500 };
3130
};
3231
}

src/services/people_options/getPeopleOptions.service.js

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const getPeopleOptionsService = async (idPeople) => {
1616
return peopleOptions;
1717

1818
} catch (error) {
19-
console.log("Error en el Service: ", error.original);
2019
throw error;
2120
}
2221
}

src/utils/formatPeople.js

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const formatPeople = (result) => {
22

33
return result.map((data) => {
44
const dataObject=data.dataValues
5-
console.log(data)
65
const peopleData = {
76
idPeople: dataObject.idPeople,
87
fullName: dataObject.fullName,

src/utils/validator.util.js

+32-100
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,51 @@
1-
const { PEOPLE_STATE_ACTIVE, PEOPLE_STATE_INACTIVE, PEOPLE_STATE_DELETED } = require("../constants");
2-
31
const validator = (data) => {
42
let errors = {};
5-
return
6-
const MIN_FULLNAME_LENGTH = 2;
7-
const MAX_FULLNAME_LENGTH = 50;
8-
const MAX_ADDRESS_LENGTH = 100;
9-
const fullNameRegex = /^[\p{L} .'-]+$/u;
10-
const geopositionRegex = /^-?([1-8]?[1-9]|[1-9]0)\.{1}\d{1,6},\s*-?([1]?[1-7]?[1-9]|[1-9]0)\.{1}\d{1,6}$/;
11-
const MAX_ABOUT_ME_LENGTH = 1000;
12-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
133

144
if (
5+
!data.fullName ||
156
typeof data.fullName !== 'string' ||
16-
data.fullName.trim().length < MIN_FULLNAME_LENGTH ||
17-
data.fullName.trim().length > MAX_FULLNAME_LENGTH) {
18-
errors.fullName = `El nombre completo debe ser una cadena de texto entre ${MIN_FULLNAME_LENGTH} y ${MAX_FULLNAME_LENGTH} caracteres.`;
19-
}
20-
21-
if (!data.fullName.trim()) {
22-
errors.fullName = 'El nombre completo no puede estar vacío.';
23-
}
24-
25-
if (!fullNameRegex.test(data.fullName)) {
26-
errors.fullName = 'El nombre completo solo puede contener letras del alfabeto, espacios, guiones, comillas y puntos.';
27-
}
28-
29-
if (data.address && (typeof data.address !== 'string' || data.address.trim().length > MAX_ADDRESS_LENGTH)) {
30-
errors.address = `La dirección debe ser una cadena de texto con un máximo de ${MAX_ADDRESS_LENGTH} caracteres.`
31-
}
32-
33-
if (data.geoposition && !geopositionRegex.test(data.geoposition.trim())) {
34-
errors.geoposition = "El formato de la geoposición no es válido.";
35-
}
36-
37-
if (!/^\d{4}-\d{2}-\d{2}$/.test(data.birthDate)) {
38-
errors.birthDate = "El formato de la fecha de nacimiento no es válido. Debe ser YYYY-MM-DD."
39-
}
40-
41-
if (data.idGenre !== undefined) {
42-
if (typeof data.idGenre !== 'number' || !Number.isInteger(data.idGenre)) {
43-
errors.idGenre = 'El valor de idGenre debe ser un número entero.';
44-
}
45-
}
46-
47-
if (data.state !== undefined) {
48-
if (![PEOPLE_STATE_ACTIVE, PEOPLE_STATE_INACTIVE,PEOPLE_STATE_DELETED].includes(data.state)) {
49-
errors.state = `El valor de state debe ser ${PEOPLE_STATE_ACTIVE},${PEOPLE_STATE_INACTIVE},${PEOPLE_STATE_DELETED}`;
50-
}
7+
data.fullName.trim().length === 0 ||
8+
data.fullName.trim().length > 30 ||
9+
!/^[a-zA-Z\s]*$/.test(data.fullName)) {
10+
errors.fullName = "El nombre completo es obligatorio y debe contener solo letras y espacios, con un máximo de 30 caracteres.";
5111
}
5212

53-
if (data.aboutMe !== undefined) {
54-
if (data.aboutMe.length > MAX_ABOUT_ME_LENGTH) {
55-
errors.aboutMe = `El campo aboutMe no puede tener más de ${MAX_ABOUT_ME_LENGTH} caracteres.`;
56-
}
57-
}
58-
59-
if (data.typeOfPerson !== undefined) {
60-
const allowedTypes = ['administrator', 'customer', 'provider'];
61-
if (!allowedTypes.includes(data.typeOfPerson)) {
62-
errors.typeOfPerson = 'El valor de typeOfPerson no es válido.';
63-
}
64-
}
65-
66-
if (data.email !== undefined) {
67-
if (!emailRegex.test(data.email)) {
68-
errors.email = 'El formato del email no es válido.';
69-
}
70-
}
71-
72-
if (data.password !== undefined) {
73-
if (data.password.length < 8 || data.password.length > 16) {
74-
errors.password = 'La contraseña debe tener entre 8 y 16 caracteres.';
75-
}
76-
77-
if (!/[A-Z]/.test(data.password)) {
78-
errors.password = 'La contraseña debe contener al menos una letra mayúscula.';
79-
}
80-
81-
if (!/\d/.test(data.password)) {
82-
errors.password = 'La contraseña debe contener al menos un número.';
83-
}
13+
if (
14+
data.phone &&
15+
(!data.phone ||
16+
typeof data.phone !== 'string' ||
17+
data.phone.trim().length === 0 ||
18+
!/^\d{10}$/.test(data.phone))) {
19+
errors.phone = "El número de teléfono debe tener un formato válido para Argentina (10 dígitos numéricos).";
8420
}
8521

86-
if (data.weekCalendar !== undefined) {
87-
if (!Array.isArray(data.weekCalendar)) {
88-
errors.weekCalendar = 'weekCalendar debe ser un array.';
89-
} else {
90-
if (data.weekCalendar.length !== 7) {
91-
errors.weekCalendar = 'weekCalendar debe contener 7 elementos correspondientes a los días de la semana.';
92-
} else {
93-
for (let i = 0; i < data.weekCalendar.length; i++) {
94-
if (typeof data.weekCalendar[i] !== 'boolean') {
95-
errors.weekCalendar = 'Los elementos de weekCalendar deben ser booleanos.';
96-
break;
97-
}
98-
}
99-
}
100-
}
22+
if (
23+
data.address &&
24+
(!data.address ||
25+
typeof data.address !== 'string' ||
26+
data.address.trim().length === 0 ||
27+
data.address.trim().length > 20 || !/^[A-Za-z0-9ÁÉÍÓÚáéíóúÜüÑñ\s]+$/.test(data.address))) {
28+
errors.address = "La dirección debe contener solo letras, números y espacios, con un máximo de 20 caracteres.";
10129
}
10230

103-
if (data.image !== undefined) {
104-
if (typeof data.image !== 'string') {
105-
errors.image = 'image debe ser una cadena de caracteres.';
106-
}
31+
if (
32+
data.profession &&
33+
(!data.profession ||
34+
typeof data.profession !== 'string' ||
35+
data.profession.trim().length === 0 ||
36+
data.profession.trim().length > 25 || !/^[A-Za-z\s]+$/.test(data.profession))) {
37+
errors.profession = "La ocupación debe contener solo letras y espacios, con un máximo de 25 caracteres.";
10738
}
10839

109-
if (data.age !== undefined) {
110-
if (typeof data.age !== 'number' || data.age < 0 || data.age > 150) {
111-
errors.image = `La edad calculada no es válida:', ${data.age}`;
112-
}
40+
if (
41+
data.aboutMe &&
42+
(typeof data.aboutMe !== 'string' ||
43+
data.aboutMe.trim().length === 0 ||
44+
data.aboutMe.trim().length > 200)) {
45+
errors.aboutMe = "El campo 'Sobre mí' debe tener como máximo 200 caracteres.";
11346
}
11447

11548
return errors;
116-
11749
}
11850

11951
module.exports = { validator };

0 commit comments

Comments
 (0)