Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IN - Duplicación de egresos #1873

Closed
wants to merge 1 commit into from
Closed
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
42 changes: 25 additions & 17 deletions modules/rup/internacion/cama-estados.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,30 @@ function rellenarMovimientos(value, index, movs) {
}

export async function store({ organizacion, ambito, capa, cama }, estado, req: Request) {
delete estado['createdAt'];
delete estado['createdBy'];
delete estado['updatedAt'];
delete estado['updatedBy'];
delete estado['deletedAt'];
delete estado['deletedBy'];
const editado = estado.editado;
const keysToDelete = ['createdAt', 'createdBy', 'updatedAt', 'updatedBy', 'deletedAt', 'deletedBy', 'editado'];
for (const key of keysToDelete) {
delete estado[key];
}
AuditDocument(estado, req.user);
let updateOperation;
if (editado) {
updateOperation = {
$set: { 'estados.$[elemento].fecha': estado.fecha }
};
} else {
updateOperation = {
$push: { estados: estado },
$setOnInsert: {
idOrganizacion: mongoose.Types.ObjectId(organizacion),
ambito,
capa,
idCama: mongoose.Types.ObjectId(cama),
start: moment(estado.fecha).startOf('month').toDate(),
end: moment(estado.fecha).endOf('month').toDate()
},
};
}
return await CamaEstados.update(
{
idOrganizacion: mongoose.Types.ObjectId(organizacion),
Expand All @@ -399,18 +416,9 @@ export async function store({ organizacion, ambito, capa, cama }, estado, req: R
start: { $lte: estado.fecha },
end: { $gte: estado.fecha }
},
updateOperation,
{
$push: { estados: estado },
$setOnInsert: {
idOrganizacion: mongoose.Types.ObjectId(organizacion),
ambito,
capa,
idCama: mongoose.Types.ObjectId(cama),
start: moment(estado.fecha).startOf('month').toDate(),
end: moment(estado.fecha).endOf('month').toDate(),
}
},
{
arrayFilters: [{ 'elemento._id': estado._id }],
upsert: true
}
);
Expand Down
Loading