Skip to content

Commit

Permalink
fix - Script corregir visibilidad de registros privados
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio-Ramirez committed Jan 2, 2025
1 parent 3d11d3d commit 78854b8
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions scripts/HUDS-121.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Prestacion } from '../modules/rup/schemas/prestacion';
import moment = require('moment');
async function run(done) {
const paramInicio = process.argv[3];
const paramFin = process.argv[4];
const start = paramInicio ?
moment(new Date(paramInicio).setHours(0, 0, 0, 0)).format('YYYY-MM-DD HH:mm:ss') :
moment(new Date().setHours(0, 0, 0, 0)).subtract(1, 'day').format('YYYY-MM-DD HH:mm:ss');
const end = paramFin ?
moment(new Date(paramFin).setHours(23, 59, 0, 0)).format('YYYY-MM-DD HH:mm:ss') :
moment(new Date().setHours(23, 59, 0, 0)).subtract(1, 'day').format('YYYY-MM-DD HH:mm:ss');
const prestacionesConNotaPublica: any = await Prestacion.aggregate([
{
$match: {
'ejecucion.fecha': {
$gte: new Date(start),
$lte: new Date(end)
},
'estadoActual.tipo': 'validada',
'ejecucion.registros.concepto.conceptId': '4291000013101'
}
},
{
$unwind: '$ejecucion.registros'
},
{
$match: {
'ejecucion.registros.concepto.conceptId': '4291000013101',
'ejecucion.registros.privacy.scope': 'public'
}
}
]);
for (const prestacion of prestacionesConNotaPublica) {
try {
await Prestacion.updateOne(
{ _id: prestacion._id },
{
$set: { 'ejecucion.registros.$[elem].privacy.scope': 'private' }
},
{
arrayFilters: [{ 'elem.concepto.conceptId': '4291000013101', 'elem.privacy.scope': 'public' }]
}
);
} catch (error) {
return;
}
}
done();
}
export = run;

0 comments on commit 78854b8

Please sign in to comment.