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

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

09 May 2026 03:54PM UTC coverage: 87.738% (+0.2%) from 87.556%
25605281604

push

github

DiegoPrietoG
feat: implement readRecordById controller and service with error handling and unit tests

78 of 86 branches covered (90.7%)

Branch coverage included in aggregate %.

17 of 19 new or added lines in 3 files covered. (89.47%)

337 of 387 relevant lines covered (87.08%)

8.01 hits per line

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

94.44
/src/controller/record/readRecordById.controller.ts
1
import { readRecordById } from '../../services/record/readRecordById.js';
2
import { Request, Response } from 'express';
3
import mongoose from 'mongoose';
4

5
/**
6
 * Controlador para leer un registro médico por su ID.
7
 * @param req - Request
8
 * @param res - Response
9
 * @returns retorna un error o el registro médico encontrado por su ID.
10
 */
11
export async function readRecordByIdController(req: { params: { id: string } }, res: Response) {
12
    try {
6✔
13
        const { id } = req.params;
6✔
14
        if (!mongoose.isValidObjectId(id)) {
6✔
15
            return res.status(400).json({ error: 'Invalid record ID' });
1✔
16
        }
17
        const objectId = new mongoose.Types.ObjectId(id);
5✔
18
        const record = await readRecordById(objectId);
5✔
19
        if (!record) {
3✔
20
            return res.status(404).json({ error: 'Record not found' });
1✔
21
        }
22
        res.json(record);
2✔
23
    } catch (error) {
24
        if (error instanceof mongoose.Error.ValidationError) {
2✔
NEW
25
            return res.status(400).json({ error: error.message });
×
26
        }
27
        if (error instanceof Error) {
2✔
28
            return res.status(500).json({ error: error.message });
1✔
29
        }
30
        res.status(500).json({ error: 'Internal server error' });
1✔
31
    }
32
}   
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