Skip to content

Commit

Permalink
feat(ep): nuevo search con detalles de paginacion
Browse files Browse the repository at this point in the history
  • Loading branch information
negro89 committed Apr 7, 2022
1 parent 2215658 commit 21e4a26
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion modules/seguimiento-paciente/seguimiento-paciente.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ class SeguimientoPacienteResource extends ResourceBase {
}
}

const search = async (req, res, next) => {
const options = req.apiOptions();
const conditions = { ...req.query };
Object.keys(options).map(opt => delete conditions[opt]);
let [results, total] = [0, undefined];
if (options.skip === 0) {
[results, total] = await Promise.all([
SeguimientoPacienteCtr.search(conditions, options),
SeguimientoPacienteCtr.search(conditions)
]);
} else {
results = await SeguimientoPacienteCtr.search(conditions, options);
}
res.json({
pagination: {
offset: options.skip,
limit: options.limit,
total: total?.length || undefined
},
data: results
});
};

const patchAsignacion = async (req, res, next) => {
try {
const { seguimientos, profesional } = req.body;
Expand All @@ -74,5 +97,7 @@ const patchAsignacion = async (req, res, next) => {

export const SeguimientoPacienteCtr = new SeguimientoPacienteResource({});
const seguimientoPacienteRouter = SeguimientoPacienteCtr.makeRoutes();
seguimientoPacienteRouter.post('/seguimientoPaciente/asignaciones', Auth.authenticate(), asyncHandler(patchAsignacion));
export const SeguimientoPacienteRouter = seguimientoPacienteRouter;

seguimientoPacienteRouter.get('/seguimientoPaciente/search/v2', Auth.authenticate(), asyncHandler(search));
seguimientoPacienteRouter.post('/seguimientoPaciente/asignaciones', Auth.authenticate(), asyncHandler(patchAsignacion));

0 comments on commit 21e4a26

Please sign in to comment.