-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix - Script corregir visibilidad de registros privados
- Loading branch information
1 parent
3d11d3d
commit 78854b8
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |