"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.collectionOrdersByStatusResolver = void 0;
const typeorm_1 = require("typeorm");
const biz_base_1 = require("@things-factory/biz-base");
const sales_base_1 = require("@things-factory/sales-base");
const shell_1 = require("@things-factory/shell");
exports.collectionOrdersByStatusResolver = {
    async collectionOrdersByStatus(_, params, context) {
        const { domain, user } = context.state;
        if (!params.filters.find((filter) => filter.name === 'bizplace')) {
            params.filters.push({
                name: 'bizplaceId',
                operator: 'in',
                value: await (0, biz_base_1.getPermittedBizplaceIds)(domain, user),
                relation: false
            });
        }
        const qb = (0, typeorm_1.getRepository)(sales_base_1.CollectionOrder).createQueryBuilder('co');
        (0, shell_1.buildQuery)(qb, params, context);
        return qb.select('co.status', 'status').addSelect('COUNT(*) AS count').groupBy('co.status').getRawMany();
    }
};
//# sourceMappingURL=collection-orders-by-status.js.map