"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMaterialApprovalDetail = void 0;
var tslib_1 = require("tslib");
exports.getMaterialApprovalDetail = {
    rest: {
        method: 'GET',
        fullPath: '/api/pepsico-content/approve/:approveId/detail'
    },
    handler: function (ctx) {
        return tslib_1.__awaiter(this, void 0, void 0, function () {
            var user, approveId, approval, _a, materials, approvalProcesses, tasks;
            return tslib_1.__generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        user = ctx.meta.user;
                        if (!user.is_space_admin) {
                            throw new Error('无权限!');
                        }
                        approveId = ctx.params.approveId;
                        return [4, this.getObject('pepsico_material_approval').findOne(approveId)];
                    case 1:
                        approval = _b.sent();
                        if (!approval) {
                            return [2, {
                                    status: 404,
                                    msg: '未找到该审批单记录',
                                    data: {}
                                }];
                        }
                        return [4, Promise.all([
                                this.getObject('pepsico_material').find({
                                    filters: [['pepsico_material_approval', '=', approveId]]
                                }),
                                this.getObject('pepsico_approval_process').find({
                                    filters: [['pepsico_material_approval', '=', approveId]],
                                    sort: 'created desc'
                                }),
                                this.getObject('pepsico_approval_task').find({
                                    filters: [['pepsico_material_approval', '=', approveId]],
                                    sort: 'created desc'
                                })
                            ])];
                    case 2:
                        _a = tslib_1.__read.apply(void 0, [_b.sent(), 3]), materials = _a[0], approvalProcesses = _a[1], tasks = _a[2];
                        return [2, {
                                status: 200,
                                msg: 'success',
                                data: {
                                    pepsico_material_approval: approval,
                                    pepsico_material: materials,
                                    pepsico_approval_process: approvalProcesses,
                                    pepsico_approval_task: tasks
                                }
                            }];
                }
            });
        });
    }
};
//# sourceMappingURL=getMaterialApprovalDetail.js.map