All files / src/modules/implementations/queries/list-definitions commodities.js

100% Statements 21/21
100% Branches 4/4
100% Functions 2/2
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2251x 51x 51x 783x 783x 783x 783x 96x 96x 96x 96x 96x 96x 96x 185x 185x 185x 96x 96x 783x 51x  
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
module.exports = ({ apiOptions: { usage, parseOptions }, external: { zod: { z } }, }) => {
    const optionsSchema = z.strictObject({
        usage,
    });
    function queryCommodities(database, options, _caches) {
        const { usage } = parseOptions(optionsSchema, options, 'commodities');
        return database.prepare(`
      SELECT symbol AS commodity, comment, format, is_default AS isDefault, used
      FROM commodity_declarations
      WHERE ? = 'all' OR used = (? = 'used')
      ORDER BY symbol
    `).all(usage, usage).map((row) => ({
            ...row,
            isDefault: Boolean(row.isDefault),
            used: Boolean(row.used),
        }));
    }
    return { inputSchema: optionsSchema, execute: queryCommodities };
};