Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions __tests__/fras.model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ describe('Modelo Fras – método obtener()', () => {
select: {
CHAROLA: {
select: {
charolaId: true,
nombreCharola: true,
},
},
FRAS: {
select: {
fechaRegistro: true,
frasId: true,
gramosGenerados: true,
},
},
Expand Down
6 changes: 3 additions & 3 deletions controllers/fras.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ module.exports.obtenerFras = async (req, res) => {
* @returns {Promise<void>} Responde con éxito o un error si no se pudo actualizar.
*/
module.exports.actualizarGramos = async (req, res) => {
const charolaId = req.params.charolaId;
const frasId = req.params.frasId;
const { nuevosGramos } = req.body;

if (!charolaId || !nuevosGramos) {
if (!frasId) {
return res.status(400).json({ success: false, message: 'Datos no válidos' });
}

const fras = new Fras();

try {
const resultado = await fras.actualizarGramos(charolaId, nuevosGramos);
const resultado = await fras.actualizarGramos(frasId, nuevosGramos);
res.status(200).json({ success: true, message: 'Gramos actualizados exitosamente', data: resultado });
} catch (error) {
console.error('Error al actualizar los gramos de Fras:', error);
Expand Down
31 changes: 5 additions & 26 deletions generated/prisma/edge.js

Large diffs are not rendered by default.

13 changes: 2 additions & 11 deletions generated/prisma/index.js

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions generated/prisma/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"name": "prisma-client-0671c7d913822a48ac9618ce0d27649d1f18b04c77559ca989ed5c5f843a4143",
"name": "prisma-client-caaa4b840984b2cef72a76831e75fe9f259c4dc6332a3236ec65c20582621c06",
"name": "prisma-client-e2798a54303f8bc735b5e6265b74795b76855e8e9f872aeaad0d16be93fdc886",
"name": "prisma-client-e2798a54303f8bc735b5e6265b74795b76855e8e9f872aeaad0d16be93fdc886",
"name": "prisma-client-0671c7d913822a48ac9618ce0d27649d1f18b04c77559ca989ed5c5f843a4143",
"name": "prisma-client-35281991ff903625c5d07f0d6e5a3ca47526f15a839c682615a3df9d9025cad5",
"main": "index.js",
"types": "index.d.ts",
"browser": "index-browser.js",
Expand Down
Binary file not shown.
51 changes: 24 additions & 27 deletions models/fras.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,47 +45,44 @@ class Fras {
* @return {Promise<Array>} Retorna una lista de objetos que contienen los gramos actualizados de Fras.
* @throws {Error} Lanza un error si ocurre un problema al actualizar los gramos en la base de datos.
* */
async actualizarGramos( charolaId, nuevosGramos ) {
async actualizarGramos( frasId, nuevosGramos ) {
try {
await prisma.fRAS.updateMany({
where: {
CHAROLA_FRAS: {
some: {
charolaId: Number(charolaId)
}
}
frasId: Number(frasId)
},
data: {
gramosGenerados: nuevosGramos
}
})
const frasActualizados = await prisma.fRAS.findMany({
where: {
CHAROLA_FRAS: {
some: {
charolaId: Number(charolaId)
}
}
},
select: {
frasId: true,
gramosGenerados: true,
fechaRegistro: true,
CHAROLA_FRAS: {
select: {
charolaId: true,
CHAROLA: {
select: { nombreCharola: true }
const frasActualizados = await prisma.fRAS.findMany({
where: {
CHAROLA_FRAS: {
some: {
frasId: Number(frasId)
}
}
},
select: {
frasId: true,
gramosGenerados: true,
fechaRegistro: true,
CHAROLA_FRAS: {
select: {
charolaId: true,
CHAROLA: {
select: { nombreCharola: true }
}
}
}
}
}
}
}
});
});


return frasActualizados;

} catch (error) {
console.log(error);
throw new Error('Error al actualizar los gramos de Fras: ' + error.message);
}
}
Expand Down
2 changes: 1 addition & 1 deletion routes/fras.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ router.get('/', frasController.obtenerFras);
/* ----------- */

/* POST METHODS */
router.post('/editar/:charolaId', frasController.actualizarGramos);
router.post('/editar/:frasId', frasController.actualizarGramos);
/* ----------- */

/* PUT METHODS */
Expand Down