"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
    return function (target, key) { decorator(target, key, paramIndex); }
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DashboardComponentController = void 0;
const api_1 = require("@hed-hog/api");
const api_locale_1 = require("@hed-hog/api-locale");
const api_pagination_1 = require("@hed-hog/api-pagination");
const common_1 = require("@nestjs/common");
const platform_express_1 = require("@nestjs/platform-express");
const dashboard_component_service_1 = require("./dashboard-component.service");
const dto_1 = require("./dto");
let DashboardComponentController = class DashboardComponentController {
    constructor(dashboardComponentService) {
        this.dashboardComponentService = dashboardComponentService;
    }
    getAllComponents(paginationParams) {
        return this.dashboardComponentService.getAllComponents(paginationParams);
    }
    getAllComponentsByUserRole(paginationParams, { id }, librarySlug, exclude) {
        return this.dashboardComponentService.getAllComponentsByUserRole(Object.assign(Object.assign({}, paginationParams), { librarySlug,
            exclude }), id);
    }
    getComponent(id, locale, { id: userId }) {
        return this.dashboardComponentService.getComponent(id, locale, userId);
    }
    createComponent(data, locale) {
        return this.dashboardComponentService.createComponent(data, locale);
    }
    updateComponent(id, data, locale) {
        return this.dashboardComponentService.updateComponent(id, data, locale);
    }
    deleteComponent(id, locale) {
        return this.dashboardComponentService.deleteComponent(id, locale);
    }
    savePreview(id, file, locale) {
        return this.dashboardComponentService.savePreview(id, file, locale);
    }
};
exports.DashboardComponentController = DashboardComponentController;
__decorate([
    (0, common_1.Get)(),
    __param(0, (0, api_pagination_1.Pagination)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", void 0)
], DashboardComponentController.prototype, "getAllComponents", null);
__decorate([
    (0, common_1.Get)('user'),
    __param(0, (0, api_pagination_1.Pagination)()),
    __param(1, (0, api_1.User)()),
    __param(2, (0, common_1.Query)('librarySlug')),
    __param(3, (0, common_1.Query)('exclude')),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object, String, String]),
    __metadata("design:returntype", void 0)
], DashboardComponentController.prototype, "getAllComponentsByUserRole", null);
__decorate([
    (0, common_1.Get)(':id'),
    __param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
    __param(1, (0, api_locale_1.Locale)()),
    __param(2, (0, api_1.User)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, String, Object]),
    __metadata("design:returntype", void 0)
], DashboardComponentController.prototype, "getComponent", null);
__decorate([
    (0, common_1.Post)(),
    __param(0, (0, common_1.Body)()),
    __param(1, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [dto_1.CreateDashboardComponentDTO, String]),
    __metadata("design:returntype", void 0)
], DashboardComponentController.prototype, "createComponent", null);
__decorate([
    (0, common_1.Patch)(':id'),
    __param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
    __param(1, (0, common_1.Body)()),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, dto_1.UpdateDashboardComponentDTO, String]),
    __metadata("design:returntype", void 0)
], DashboardComponentController.prototype, "updateComponent", null);
__decorate([
    (0, common_1.Delete)(':id'),
    __param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
    __param(1, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, String]),
    __metadata("design:returntype", void 0)
], DashboardComponentController.prototype, "deleteComponent", null);
__decorate([
    (0, common_1.Post)(':id/preview'),
    (0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('file', {
        fileFilter: (req, file, cb) => {
            var _a;
            if (!((_a = file === null || file === void 0 ? void 0 : file.mimetype) === null || _a === void 0 ? void 0 : _a.startsWith('image/'))) {
                return cb(new common_1.BadRequestException('Invalid image file'), false);
            }
            cb(null, true);
        },
    })),
    __param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
    __param(1, (0, common_1.UploadedFile)()),
    __param(2, (0, api_locale_1.Locale)()),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Number, Object, String]),
    __metadata("design:returntype", void 0)
], DashboardComponentController.prototype, "savePreview", null);
exports.DashboardComponentController = DashboardComponentController = __decorate([
    (0, api_1.Role)(),
    (0, common_1.Controller)('dashboard-component'),
    __param(0, (0, common_1.Inject)((0, common_1.forwardRef)(() => dashboard_component_service_1.DashboardComponentService))),
    __metadata("design:paramtypes", [dashboard_component_service_1.DashboardComponentService])
], DashboardComponentController);
//# sourceMappingURL=dashboard-component.controller.js.map