Skip to content

Commit 24ad094

Browse files
committed
fix(inventory): Se restructura el catalogo completo de inventarios y se corrige el formato de cost y comillas invertidas
1 parent 737b953 commit 24ad094

13 files changed

Lines changed: 282 additions & 65 deletions

File tree

NOTES.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,11 @@
22

33
## Cambios importantes
44

5-
- Hacer el cambio para el catalogo de insumos por medio de la modularizacionm de funciones
6-
- Hacer un catalogo de Aulas
7-
8-
- Hacer dos nuevas tablas una llamada asset_conditions y supply_units para administrar esos catalogos de forma mejor eficiente a la hora de quererlos incluir como listas para insercion o como selectores de busqueda
9-
10-
- Hacer un catalogo de proveedores que seria el campo de supplier en catsupplies
11-
12-
- asset_conditions va ser para la condicion del activo condition_id
13-
14-
- supply_units va ser para la unidades de los suministros unit_id
15-
16-
- Verificar las funciones de la carpeta helpers para poder reutilizar unas funciones
17-
(sobre todo la de cuando se elimina un registro como el de usuarios en su modelo, esto aplica para todas las tablas)
185
- Verificar testeos del catalogo de activos y de usuarios juntos y hacerlos
196
- Busar una forma mas segura de pasarle el token a los test
207
- Probar la funcion de token para el refresco del mismo, y hacer la docuemntacion en postman
218
- Excluir por aparte el controlador de google para el login, y tenerlo aparte (Sacarlo de los usuario y que tenga su propio espacio)
229

23-
-
24-
2510
## Cambios que se puedan ir haciendo
2611

2712
- Ir adecuando el codigo poco a poco el codigo en ingles
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { connectionQuery } from "../../../helpers/connection.helpers.js";
22

33
export const deleteInventoryModel = async (inventoryId) => {
4-
const query = `DELETE FROM catinventory WHERE ID = ?`;
4+
const query = `DELETE FROM cat_inventory WHERE inventory_id = ?`;
55
const params = [inventoryId];
66
return await connectionQuery(query, params);
77
};
88

99
export const deleteInventoryBulk = async (placeholders, batch) => {
10-
const query = `DELETE FROM catinventory WHERE ID IN (${placeholders})`;
10+
const query = `DELETE FROM cat_inventory WHERE inventory_id IN (${placeholders})`;
1111
return await connectionQuery(query, batch);
1212
};

src/models/inventory/functions/insert.models.js

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,79 @@
11
import { connectionQuery } from "../../../helpers/connection.helpers.js";
22

3+
export const extractForeignKeysInventoryModel = async (
4+
condition,
5+
location,
6+
status,
7+
) => {
8+
const query = `SELECT
9+
(SELECT
10+
condition_id
11+
FROM
12+
asset_conditions
13+
WHERE
14+
name = ?) AS 'condition',
15+
(SELECT
16+
location_id
17+
FROM
18+
cat_classrooms
19+
WHERE
20+
name = ?) AS location,
21+
(SELECT
22+
status_id
23+
FROM
24+
cat_status
25+
WHERE
26+
name = ?) AS status;`;
27+
const result = await connectionQuery(query, [condition, location, status]);
28+
return result;
29+
};
30+
331
export const insertInventoryModel = async ({
4-
itemCode,
32+
condition,
33+
location,
34+
item_code,
35+
serial_number,
536
name,
637
description,
738
quantity,
839
weight,
940
width,
1041
height,
11-
location,
12-
condition,
13-
purchaseDate,
42+
purchase_date,
43+
cost,
44+
last_maintenance_date,
45+
warranty_end_date,
46+
status,
1447
}) => {
15-
const query = `INSERT INTO catinventory (ID, ItemCode, Name, Description, Quantity, Weight, Width, Height, Location, \`Condition\`, PurchaseDate)
16-
VALUES (UUID(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`;
48+
const query = `INSERT INTO cat_inventory (
49+
inventory_id, condition_id, location_id, item_code,
50+
serial_number, name, description,
51+
quantity, weight, width, height, purchase_date,
52+
cost, last_maintenance_date, warranty_end_date,
53+
status_id
54+
)
55+
VALUES
56+
(
57+
UUID(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
58+
);
59+
`;
1760

1861
const params = [
19-
itemCode,
62+
condition,
63+
location,
64+
item_code,
65+
serial_number,
2066
name,
2167
description,
2268
quantity,
2369
weight,
2470
width,
2571
height,
26-
location,
27-
condition,
28-
purchaseDate,
72+
purchase_date,
73+
cost,
74+
last_maintenance_date,
75+
warranty_end_date,
76+
status,
2977
];
3078

3179
return await connectionQuery(query, params);

src/models/inventory/functions/update.models.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,59 @@ import { connectionQuery } from "../../../helpers/connection.helpers.js";
33
export const updateInventoryModel = async (
44
inventoryId,
55
{
6-
itemCode,
6+
condition,
7+
location,
8+
item_code,
9+
serial_number,
710
name,
811
description,
912
quantity,
1013
weight,
1114
width,
1215
height,
13-
location,
14-
condition,
15-
purchaseDate,
16+
purchase_date,
17+
cost,
18+
last_maintenance_date,
19+
warranty_end_date,
1620
status,
1721
},
1822
) => {
19-
const query = `UPDATE catinventory SET ItemCode = ?, Name = ?, Description = ?, Quantity = ?, Weight = ?, Width = ?, Height = ?, Location = ?, \`Condition\` = ?, PurchaseDate = ?, Status = ? WHERE ID = ?`;
23+
const query = `UPDATE
24+
cat_inventory
25+
SET
26+
condition_id = ?,
27+
location_id = ?,
28+
item_code = ?,
29+
serial_number = ?,
30+
name = ?,
31+
description = ?,
32+
quantity = ?,
33+
weight = ?,
34+
width = ?,
35+
height = ?,
36+
purchase_date = ?,
37+
cost = ?,
38+
last_maintenance_date = ?,
39+
warranty_end_date = ?,
40+
status_id = ?
41+
WHERE
42+
inventory_id = ?;`;
43+
2044
const params = [
21-
itemCode,
45+
condition,
46+
location,
47+
item_code,
48+
serial_number,
2249
name,
2350
description,
2451
quantity,
2552
weight,
2653
width,
2754
height,
28-
location,
29-
condition,
30-
purchaseDate,
55+
purchase_date,
56+
cost,
57+
last_maintenance_date,
58+
warranty_end_date,
3159
status,
3260
inventoryId,
3361
];
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { connectionQuery } from "../../../helpers/connection.helpers.js";
22

33
export const vaultInventoryModel = async (inventoryId) => {
4-
const query = `UPDATE catinventory SET Status = 'Inactivo' WHERE ID = ?`;
4+
const query = `UPDATE cat_inventory SET status_id = "cefdb296-61f5-11f0-a977-d843ae0db894" WHERE inventory_id = ?`;
55
const params = [inventoryId];
66
await connectionQuery(query, params);
77
};

src/routes/catInventory.routes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ apiCatInventory.delete(
121121
methodOK(
122122
request,
123123
response,
124-
result,
125-
"El inventario fue eliminado correctamente",
124+
undefined,
125+
`El inventario ${result.name} fue eliminado correctamente`,
126126
);
127127
} catch (error) {
128128
next(error);

src/services/assets/functions/list.services.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const listAssetsService = async ({
2424
}
2525

2626
if (condition && condition !== "All") {
27-
where += " AND `asset_conditions.name` = ?";
27+
where += " AND asset_conditions.name = ?";
2828
values.push(condition);
2929
}
3030

@@ -41,7 +41,7 @@ export const listAssetsService = async ({
4141
cat_assets.name,
4242
cat_assets.description,
4343
purchase_date,
44-
cost,
44+
FORMAT(cost, 2) AS cost,
4545
last_maintenance_date,
4646
warranty_end_date,
4747
created,

src/services/inventory/functions/delete.services.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { validateFoundToEliminated } from "../../../helpers/delete.helpers.js";
12
import {
23
deleteInventoryBulk,
34
deleteInventoryModel,
@@ -13,6 +14,22 @@ export const deleteInventoryService = async (inventoryId) => {
1314
};
1415
}
1516

17+
const foundInventoryToEliminated = await validateFoundToEliminated(
18+
inventoryId,
19+
"inventory_id",
20+
"name",
21+
"cat_inventory",
22+
);
23+
24+
if (foundInventoryToEliminated.length === 0) {
25+
throw {
26+
statusCode: 404,
27+
message: "No se proporcionó un ID válido o el inventario no existe",
28+
code: "INVENTORY_NOT_FOUND",
29+
details: "El inventario con el ID proporcionado no fue encontrado",
30+
};
31+
}
32+
1633
const result = await deleteInventoryModel(inventoryId);
1734

1835
if (result.affectedRows === 0) {
@@ -24,6 +41,8 @@ export const deleteInventoryService = async (inventoryId) => {
2441
"Hubo un error al intentar borrar el inventario en la base de datos",
2542
};
2643
}
44+
45+
return foundInventoryToEliminated[0];
2746
};
2847

2948
export const deleteInventoryBulkService = async (ids) => {

src/services/inventory/functions/insert.services.js

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,41 @@
1-
import { insertInventoryModel } from "../../../models/inventory/index.js";
1+
import {
2+
extractForeignKeysInventoryModel,
3+
insertInventoryModel,
4+
} from "../../../models/inventory/index.js";
25

3-
export const insertInventoryService = async (inventory) => {
6+
export const insertInventoryService = async ({
7+
condition,
8+
location,
9+
item_code,
10+
serial_number,
11+
name,
12+
description,
13+
quantity,
14+
weight,
15+
width,
16+
height,
17+
purchase_date,
18+
cost,
19+
last_maintenance_date,
20+
warranty_end_date,
21+
status,
22+
}) => {
423
if (
5-
!inventory.itemCode ||
6-
!inventory.name ||
7-
!inventory.description ||
8-
!inventory.quantity ||
9-
!inventory.weight ||
10-
!inventory.width ||
11-
!inventory.height ||
12-
!inventory.location ||
13-
!inventory.condition ||
14-
!inventory.purchaseDate
24+
!condition ||
25+
!location ||
26+
!item_code ||
27+
!serial_number ||
28+
!name ||
29+
!description ||
30+
!quantity ||
31+
!weight ||
32+
!width ||
33+
!height ||
34+
!purchase_date ||
35+
!cost ||
36+
!last_maintenance_date ||
37+
!warranty_end_date ||
38+
!status
1539
) {
1640
throw {
1741
statusCode: 400,
@@ -21,7 +45,29 @@ export const insertInventoryService = async (inventory) => {
2145
};
2246
}
2347

24-
const result = await insertInventoryModel(inventory);
48+
const extract = await extractForeignKeysInventoryModel(
49+
condition,
50+
location,
51+
status,
52+
);
53+
54+
const result = await insertInventoryModel({
55+
condition: extract[0].condition,
56+
location: extract[0].location,
57+
item_code,
58+
serial_number,
59+
name,
60+
description,
61+
quantity,
62+
weight,
63+
width,
64+
height,
65+
purchase_date,
66+
cost,
67+
last_maintenance_date,
68+
warranty_end_date,
69+
status: extract[0].status,
70+
});
2571

2672
if (!result.affectedRows > 0) {
2773
throw {

0 commit comments

Comments
 (0)