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

CBIIT / crdc-datahub-backend / 23956944712

03 Apr 2026 06:16PM UTC coverage: 43.445% (+0.1%) from 43.344%
23956944712

Pull #1178

github

web-flow
Merge ec61f4482 into ae5f8c565
Pull Request #1178: 3577: includeStudies flag in ProgramDAO lookup

3216 of 9642 branches covered (33.35%)

Branch coverage included in aggregate %.

19 of 21 new or added lines in 2 files covered. (90.48%)

35 existing lines in 1 file now uncovered.

3833 of 6583 relevant lines covered (58.23%)

63.66 hits per line

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

87.5
/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

6

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

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

84
}
85
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