From 1e31d26bd6432ea9d1be58c9091b0a99c46d04e4 Mon Sep 17 00:00:00 2001 From: plammel Date: Thu, 8 Apr 2021 16:00:39 -0300 Subject: [PATCH] feat(EP): formEpidemiologia.type.id --- .../forms-epidemiologia-schema.ts | 5 ++++- .../forms-epidemiologia.routes.ts | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/forms/forms-epidemiologia/forms-epidemiologia-schema.ts b/modules/forms/forms-epidemiologia/forms-epidemiologia-schema.ts index 2a58fdfeba..3e3b20a660 100644 --- a/modules/forms/forms-epidemiologia/forms-epidemiologia-schema.ts +++ b/modules/forms/forms-epidemiologia/forms-epidemiologia-schema.ts @@ -2,7 +2,10 @@ import { AuditPlugin } from '@andes/mongoose-plugin-audit'; import * as mongoose from 'mongoose'; export const FormsEpidemiologiaSchema = new mongoose.Schema({ - type: String, + type: { + id: mongoose.Schema.Types.ObjectId, + name: String + }, paciente: { id: { type: mongoose.Schema.Types.ObjectId, ref: 'paciente' }, documento: String, diff --git a/modules/forms/forms-epidemiologia/forms-epidemiologia.routes.ts b/modules/forms/forms-epidemiologia/forms-epidemiologia.routes.ts index bfa46fd83f..461c7ea454 100644 --- a/modules/forms/forms-epidemiologia/forms-epidemiologia.routes.ts +++ b/modules/forms/forms-epidemiologia/forms-epidemiologia.routes.ts @@ -7,7 +7,10 @@ class FormsEpidemiologiaResource extends ResourceBase { resourceName = 'formEpidemiologia'; middlewares = [Auth.authenticate()]; searchFileds = { - type: MongoQuery.partialString, + type: { + field: 'type.name', + fn: MongoQuery.partialString + }, fechaCondicion: MongoQuery.matchDate.withField('createdAt'), paciente: { field: 'paciente.id', @@ -18,3 +21,13 @@ class FormsEpidemiologiaResource extends ResourceBase { export const FormEpidemiologiaCtr = new FormsEpidemiologiaResource(); export const FormEpidemiologiaRouter = FormEpidemiologiaCtr.makeRoutes(); + +FormEpidemiologiaRouter.get('/types', Auth.authenticate(), async (req, res, next) => { + try { + const types: any = await FormsEpidemiologia.find({}, { type: 1 }); + return res.json(types); + } catch (err) { + return next(err); + } +}); +