"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deliveryOrdersByStatusResolver = 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.deliveryOrdersByStatusResolver = {
    async deliveryOrdersByStatus(_, 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.DeliveryOrder).createQueryBuilder('do');
        (0, shell_1.buildQuery)(qb, params, context);
        return qb.select('do.status', 'status').addSelect('COUNT(*) AS count').groupBy('do.status').getRawMany();
    }
};
//# sourceMappingURL=delivery-orders-by-status.js.map