<commit_before>const logger = require('../../log.js');
const {isEmpty, getIn} = require('../utils/functionalHelpers');
const {formatObjectForView} = require('./utils/formatForView');

module.exports = function createCaseListService(nomisClientBuilder, licenceClient) {
    async function getHdcCaseList(user) {
        try {
            const nomisClient = nomisClientBuilder(user.token);
            const hdcEligibleReleases = await getCaseList(nomisClient, licenceClient, user);

            if (isEmpty(hdcEligibleReleases)) {
                logger.info('No hdc eligible prisoners');
                return [];
            }

            const licences = await licenceClient.getLicences(getOffenderIds(hdcEligibleReleases));
            return hdcEligibleReleases.map(decoratePrisonerDetails(licences));

        } catch (error) {
            logger.error('Error during getHdcCaseList: ', error.stack);
            throw error;
        }
    }

    return {getHdcCaseList};
};

async function getCaseList(nomisClient, licenceClient, user) {
    const asyncCaseRetrievalMethod = {
        CA: nomisClient.getHdcEligiblePrisoners,
        RO: getROCaseList(nomisClient, licenceClient, user)
    };

    return asyncCaseRetrievalMethod[user.roleCode]();
}

function getROCaseList(nomisClient, licenceClient, user) {
    return async () => {
        const deliusUserName = await licenceClient.getDeliusUserName(user.username);

        const requiredPrisoners = await nomisClient.getROPrisoners(deliusUserName[0].STAFF_ID.value);
        const requiredIDs = requiredPrisoners.map(prisoner => prisoner.offenderNo);

        return nomisClient.getHdcEligiblePrisoners(requiredIDs);
    };
}

function decoratePrisonerDetails(licences) {
     return prisoner => {
        const formattedPrisoner = formatObjectForView(prisoner);
        return {...formattedPrisoner, status: getStatus(prisoner, licences)};
    };
}
<commit_msg>add caselist retrieval mathod for DM<commit_after>const logger = require('../../log.js');
const {isEmpty, getIn} = require('../utils/functionalHelpers');
const {formatObjectForView} = require('./utils/formatForView');

module.exports = function createCaseListService(nomisClientBuilder, licenceClient) {
    async function getHdcCaseList(user) {
        try {
            const nomisClient = nomisClientBuilder(user.token);
            const hdcEligibleReleases = await getCaseList(nomisClient, licenceClient, user);

            if (isEmpty(hdcEligibleReleases)) {
                logger.info('No hdc eligible prisoners');
                return [];
            }

            const licences = await licenceClient.getLicences(getOffenderIds(hdcEligibleReleases));
            return hdcEligibleReleases.map(decoratePrisonerDetails(licences));

        } catch (error) {
            logger.error('Error during getHdcCaseList: ', error.stack);
            throw error;
        }
    }

    return {getHdcCaseList};
};

async function getCaseList(nomisClient, licenceClient, user) {
    const asyncCaseRetrievalMethod = {
        CA: nomisClient.getHdcEligiblePrisoners,
        RO: getROCaseList(nomisClient, licenceClient, user),
        DM: nomisClient.getHdcEligiblePrisoners
    };

    return asyncCaseRetrievalMethod[user.roleCode]();
}

function getROCaseList(nomisClient, licenceClient, user) {
    return async () => {
        const deliusUserName = await licenceClient.getDeliusUserName(user.username);

        const requiredPrisoners = await nomisClient.getROPrisoners(deliusUserName[0].STAFF_ID.value);
        const requiredIDs = requiredPrisoners.map(prisoner => prisoner.offenderNo);

        return nomisClient.getHdcEligiblePrisoners(requiredIDs);
    };
}

function decoratePrisonerDetails(licences) {
     return prisoner => {
        const formattedPrisoner = formatObjectForView(prisoner);
        return {...formattedPrisoner, status: getStatus(prisoner, licences)};
    };
}

{'fraction_non_alphanumeric': 0.10168195718654434, 'fraction_numerical': 0.0005096839959225281, 'mean_word_length': 3.3854748603351954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1766598', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1116, 'n_words': 201}