"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const routing_controllers_1 = require("@gem-mine/routing-controllers");
const statistics_1 = require("../service/statistics");
function validateBody(bodyData, context) {
    if (!bodyData.project_id) {
        context.throw(400, 'missing project_id');
    }
    if (!bodyData.component_name) {
        context.throw(400, 'missing component_name');
    }
    if (!bodyData.component_list) {
        context.throw(400, 'missing component_list');
    }
    if (!(bodyData.component_list instanceof Array)) {
        context.throw(400, 'component_list must be array');
    }
    bodyData.component_list.forEach((componentData) => {
        if (!componentData.name) {
            context.throw(400, 'every item in component_list must have name');
        }
        if (typeof componentData.count !== 'number') {
            context.throw(400, 'every item in component_list must have a count as number');
        }
    });
}
let default_1 = class default_1 {
    createOne(bodyData, context) {
        return tslib_1.__awaiter(this, void 0, void 0, function* () {
            validateBody(bodyData, context);
            return statistics_1.default.createOne(bodyData);
        });
    }
};
tslib_1.__decorate([
    routing_controllers_1.Post('/ui'),
    tslib_1.__param(0, routing_controllers_1.Body()),
    tslib_1.__param(1, routing_controllers_1.Ctx()),
    tslib_1.__metadata("design:type", Function),
    tslib_1.__metadata("design:paramtypes", [Object, Object]),
    tslib_1.__metadata("design:returntype", Promise)
], default_1.prototype, "createOne", null);
default_1 = tslib_1.__decorate([
    routing_controllers_1.Controller('/statistics')
], default_1);
exports.default = default_1;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhdGlzdGljcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9jb250cm9sbGVyL3N0YXRpc3RpY3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7O0FBQ0EsdUVBQTJFO0FBQzNFLHNEQUE4QztBQU85QyxTQUFTLFlBQVksQ0FBQyxRQUFhLEVBQUUsT0FBZ0I7SUFDbkQsSUFBRyxDQUFDLFFBQVEsQ0FBQyxVQUFVLEVBQUU7UUFDdkIsT0FBTyxDQUFDL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