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

CBIIT / crdc-datahub-backend / 24086948905

07 Apr 2026 02:31PM UTC coverage: 43.449% (+0.1%) from 43.344%
24086948905

push

github

web-flow
Merge pull request #1178 from CBIIT/3577-null-study-lists

3577: includeStudies flag in ProgramDAO lookup

3216 of 9642 branches covered (33.35%)

Branch coverage included in aggregate %.

20 of 25 new or added lines in 3 files covered. (80.0%)

35 existing lines in 1 file now uncovered.

3834 of 6584 relevant lines covered (58.23%)

63.65 hits per line

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

87.8
/dao/program.js
1
const GenericDAO = require("./generic");
34✔
2
const { MODEL_NAME } = require('../constants/db-constants');
34✔
3
const {MongoPagination} = require("../crdc-datahub-database-drivers/domain/mongo-pagination");
34✔
4
const {APPROVED_STUDIES_COLLECTION} = require("../crdc-datahub-database-drivers/database-constants");
34✔
5
const { ERROR } = require("../crdc-datahub-database-drivers/constants/error-constants");
34✔
6

7

8
class ProgramDAO extends GenericDAO {
9
    constructor(organizationCollection) {
10
        super(MODEL_NAME.PROGRAM);
330✔
11
        this.organizationCollection = organizationCollection;
330✔
12
    }
13
    /**
14
     * @param {string} id
15
     * @param {boolean} includeStudies When true, loads related approved studies via Prisma.
16
     */
17
    async getOrganizationByID(id, includeStudies) {
18
        if (typeof includeStudies !== 'boolean') {
14✔
19
            throw new Error(ERROR.INVALID_INCLUDE_STUDIES_LIST_ARGUMENT);
2✔
20
        }
21
        if (!includeStudies) {
12✔
22
            return await this.findById(id);
6✔
23
        }
24
        try {
6✔
25
            const result = await this.model.findUnique({
6✔
26
                where: { id },
27
                include: { studies: true },
28
            });
29
            if (!result) {
4!
NEW
30
                return null;
×
31
            }
32
            const { studies, ...rest } = result;
4✔
33
            return {
4✔
34
                ...rest,
35
                _id: result.id,
36
                studies: (studies ?? []).map((s) => ({ ...s, _id: s.id })),
2!
37
            };
38
        } catch (error) {
39
            console.error(`ProgramDAO.getOrganizationByID failed for ${this.model.name}:`, {
2✔
40
                error: error.message,
41
                id,
42
                stack: error.stack,
43
            });
44
            throw new Error(`Failed to find ${this.model.name} by ID`);
2✔
45
        }
46
    }
47

48
    async getOrganizationByName(name) {
49
        return await this.findFirst({
90✔
50
            name: name?.trim()
51
        });
52
    }
53
    async listPrograms(first, offset, orderBy, sortDirection, statusCondition = {}) {
×
54
        const pagination = new MongoPagination(first, offset, orderBy, sortDirection);
2✔
55
        const paginationPipeline = pagination.getPaginationPipeline();
2✔
56
        const programs = await this.organizationCollection.aggregate([
2✔
57
            {
58
                $lookup: {
59
                    from: APPROVED_STUDIES_COLLECTION,
60
                    localField: "_id",
61
                    foreignField: "programID",
62
                    as: "studies"
63
                }
64
            },
65
            {"$match": statusCondition},
66
            {
67
                $facet: {
68
                    total: [{
69
                        $count: "total"
70
                    }],
71
                    results: paginationPipeline
72
                }
73
            },
74
            {
75
                $set: {
76
                    total: {
77
                        $first: "$total.total",
78
                    }
79
                }
80
            }
81
        ]);
82
        return programs.length > 0 ? programs[0] : {};
2!
83
    }
84

85
}
86
module.exports = ProgramDAO
34✔
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