• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ULL-ESIT-INF-DSI-2526 / grp02-medcore-api-groupd / 25628398609

10 May 2026 12:08PM UTC coverage: 87.197% (-0.5%) from 87.738%
25628398609

push

github

eduzu
Merge branch 'main' of github.com:ULL-ESIT-INF-DSI-2526/grp02-medcore-api-groupd
Medication controllers and basic testing

99 of 109 branches covered (90.83%)

Branch coverage included in aggregate %.

279 of 320 new or added lines in 31 files covered. (87.19%)

1 existing line in 1 file now uncovered.

405 of 469 relevant lines covered (86.35%)

7.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/src/controller/patients/createPatient.controller.ts
1
import { Request, Response } from 'express';
2
import mongoose from 'mongoose';
3
import { Patient } from '../../models/patients/patientSchema.js';
4

5
/**
6
 * Crea un nuevo paciente en el sistema.
7
 * @param req - La solicitud HTTP que contiene los datos del paciente en el cuerpo.
8
 * @param res - La respuesta HTTP que se enviará al cliente con el resultado de la operación.
9
 * @returns JSON con el nuevo paciente creado o un mensaje de error en caso de fallo.
10
 *
11
 * @throws ValidationError - Si los datos del paciente no cumplen con el esquema definido.
12
 * @throws Error - Si ocurre un error inesperado durante la creación del paciente.
13
 *
14
 * Codigos de estado HTTP:
15
 * - 201: Paciente creado exitosamente.
16
 * - 400: Error de validación de datos.
17
 * - 409: El paciente ya existe en el sistema.
18
 * - 500: Error interno del servidor.
19
 */
20
export async function createPatient(req: Request, res: Response) {
21
  try {
16✔
22
    const newPatient = new Patient(req.body);
16✔
23
    await newPatient.save();
16✔
24
    res.status(201).json(newPatient);
3✔
25
  } catch (error: unknown) {
26
    if (error instanceof mongoose.Error.ValidationError) {
13✔
27
      return res.status(400).json({
11✔
28
        error: error.message,
29
      });
30
    }
31

32
    if (error instanceof Error) {
2✔
33
      const mongoError = error as Error & { code?: number };
2✔
34

35
      if (mongoError.code === 11000) {
2✔
36
        return res.status(409).json({
1✔
37
          error: 'The patient is already at our system',
38
        });
39
      }
40
      return res.status(500).json({
1✔
41
        error: error.message,
42
      });
43
    }
44

UNCOV
45
    return res.status(500).json({
×
46
      error: 'Internal Server Error',
47
    });
48
  }
49
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc