Refactor code structure for improved readability and maintainability
Test Suite / test (24.15.0) (push) Has been cancelled

This commit is contained in:
Nils-Johan Gynther
2026-05-06 07:37:59 +02:00
parent e4f201ea36
commit 969dafdbc6
273 changed files with 11357 additions and 39 deletions
@@ -0,0 +1,77 @@
"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.ReceiptImportController = void 0;
const common_1 = require("@nestjs/common");
const throttler_1 = require("@nestjs/throttler");
const platform_express_1 = require("@nestjs/platform-express");
const multer_1 = require("multer");
const receipt_import_service_1 = require("./receipt-import.service");
const passport_1 = require("@nestjs/passport");
const ALLOWED_MIMES = [
'image/jpeg',
'image/png',
'image/webp',
'image/heic',
'image/heif',
'application/pdf',
'application/octet-stream',
];
let ReceiptImportController = class ReceiptImportController {
constructor(receiptImportService) {
this.receiptImportService = receiptImportService;
}
async parseReceipt(file, req) {
if (!file?.buffer) {
throw new common_1.BadRequestException('Ingen fil skickades med.');
}
if (!ALLOWED_MIMES.includes(file.mimetype)) {
throw new common_1.BadRequestException('Otillåten filtyp. Använd JPEG, PNG, WebP eller PDF.');
}
const isPremium = req?.user?.isPremium === true || req?.user?.role === 'admin';
const userId = typeof req?.user?.id === 'number' ? req.user.id : undefined;
return this.receiptImportService.parseReceipt(file, isPremium, userId);
}
async refreshCategories() {
await this.receiptImportService.loadCategories();
return { message: 'Kategorier har uppdaterats.' };
}
};
exports.ReceiptImportController = ReceiptImportController;
__decorate([
(0, common_1.HttpCode)(200),
(0, common_1.Post)(),
(0, throttler_1.Throttle)({ default: { ttl: 60_000, limit: 20 } }),
(0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('file', {
storage: (0, multer_1.memoryStorage)(),
limits: { fileSize: 15 * 1024 * 1024 },
})),
__param(0, (0, common_1.UploadedFile)()),
__param(1, (0, common_1.Request)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], ReceiptImportController.prototype, "parseReceipt", null);
__decorate([
(0, common_1.Post)('refresh-categories'),
(0, common_1.UseGuards)((0, passport_1.AuthGuard)('jwt')),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], ReceiptImportController.prototype, "refreshCategories", null);
exports.ReceiptImportController = ReceiptImportController = __decorate([
(0, common_1.Controller)('receipt-import'),
__metadata("design:paramtypes", [receipt_import_service_1.ReceiptImportService])
], ReceiptImportController);
//# sourceMappingURL=receipt-import.controller.js.map