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,5 @@
export declare class CreateReceiptAliasDto {
receiptName: string;
productId: number;
isGlobal?: boolean;
}
@@ -0,0 +1,31 @@
"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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CreateReceiptAliasDto = void 0;
const class_validator_1 = require("class-validator");
class CreateReceiptAliasDto {
}
exports.CreateReceiptAliasDto = CreateReceiptAliasDto;
__decorate([
(0, class_validator_1.IsString)(),
(0, class_validator_1.MinLength)(1),
__metadata("design:type", String)
], CreateReceiptAliasDto.prototype, "receiptName", void 0);
__decorate([
(0, class_validator_1.IsInt)(),
__metadata("design:type", Number)
], CreateReceiptAliasDto.prototype, "productId", void 0);
__decorate([
(0, class_validator_1.IsOptional)(),
(0, class_validator_1.IsBoolean)(),
__metadata("design:type", Boolean)
], CreateReceiptAliasDto.prototype, "isGlobal", void 0);
//# sourceMappingURL=create-receipt-alias.dto.js.map
@@ -0,0 +1 @@
{"version":3,"file":"create-receipt-alias.dto.js","sourceRoot":"","sources":["../../../src/receipt-alias/dto/create-receipt-alias.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAoF;AAEpF,MAAa,qBAAqB;CAWjC;AAXD,sDAWC;AARC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,2BAAS,EAAC,CAAC,CAAC;;0DACQ;AAGrB;IADC,IAAA,uBAAK,GAAE;;wDACW;AAInB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;uDACO"}
@@ -0,0 +1,45 @@
import { ReceiptAliasService } from './receipt-alias.service';
import { CreateReceiptAliasDto } from './dto/create-receipt-alias.dto';
export declare class ReceiptAliasController {
private readonly receiptAliasService;
constructor(receiptAliasService: ReceiptAliasService);
findAll(user: {
userId: number;
role: string;
}): import(".prisma/client").Prisma.PrismaPromise<({
product: {
name: string;
canonicalName: string | null;
id: number;
};
} & {
id: number;
createdAt: Date;
ownerId: number | null;
productId: number;
receiptName: string;
isGlobal: boolean;
})[]>;
upsert(dto: CreateReceiptAliasDto, user: {
userId: number;
role: string;
}): Promise<{
id: number;
createdAt: Date;
ownerId: number | null;
productId: number;
receiptName: string;
isGlobal: boolean;
}>;
remove(id: number, user: {
userId: number;
role: string;
}): Promise<{
id: number;
createdAt: Date;
ownerId: number | null;
productId: number;
receiptName: string;
isGlobal: boolean;
}>;
}
+62
View File
@@ -0,0 +1,62 @@
"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.ReceiptAliasController = void 0;
const common_1 = require("@nestjs/common");
const receipt_alias_service_1 = require("./receipt-alias.service");
const create_receipt_alias_dto_1 = require("./dto/create-receipt-alias.dto");
const current_user_decorator_1 = require("../auth/decorators/current-user.decorator");
let ReceiptAliasController = class ReceiptAliasController {
constructor(receiptAliasService) {
this.receiptAliasService = receiptAliasService;
}
findAll(user) {
return this.receiptAliasService.findAllForUser(user.userId, user.role);
}
upsert(dto, user) {
return this.receiptAliasService.upsert(dto, user.userId, user.role);
}
remove(id, user) {
return this.receiptAliasService.remove(id, user.userId, user.role);
}
};
exports.ReceiptAliasController = ReceiptAliasController;
__decorate([
(0, common_1.Get)(),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", void 0)
], ReceiptAliasController.prototype, "findAll", null);
__decorate([
(0, common_1.Post)(),
__param(0, (0, common_1.Body)()),
__param(1, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [create_receipt_alias_dto_1.CreateReceiptAliasDto, Object]),
__metadata("design:returntype", void 0)
], ReceiptAliasController.prototype, "upsert", null);
__decorate([
(0, common_1.Delete)(':id'),
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
__param(1, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Number, Object]),
__metadata("design:returntype", void 0)
], ReceiptAliasController.prototype, "remove", null);
exports.ReceiptAliasController = ReceiptAliasController = __decorate([
(0, common_1.Controller)('receipt-aliases'),
__metadata("design:paramtypes", [receipt_alias_service_1.ReceiptAliasService])
], ReceiptAliasController);
//# sourceMappingURL=receipt-alias.controller.js.map
@@ -0,0 +1 @@
{"version":3,"file":"receipt-alias.controller.js","sourceRoot":"","sources":["../../src/receipt-alias/receipt-alias.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0F;AAC1F,mEAA8D;AAC9D,6EAAuE;AACvE,sFAAwE;AAGjE,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,YAA6B,mBAAwC;QAAxC,wBAAmB,GAAnB,mBAAmB,CAAqB;IAAG,CAAC;IAGzE,OAAO,CAAgB,IAAsC;QAC3D,OAAO,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACzE,CAAC;IAGD,MAAM,CACI,GAA0B,EACnB,IAAsC;QAErD,OAAO,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACtE,CAAC;IAGD,MAAM,CACuB,EAAU,EACtB,IAAsC;QAErD,OAAO,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IACrE,CAAC;CACF,CAAA;AAvBY,wDAAsB;AAIjC;IADC,IAAA,YAAG,GAAE;IACG,WAAA,IAAA,oCAAW,GAAE,CAAA;;;;qDAErB;AAGD;IADC,IAAA,aAAI,GAAE;IAEJ,WAAA,IAAA,aAAI,GAAE,CAAA;IACN,WAAA,IAAA,oCAAW,GAAE,CAAA;;qCADD,gDAAqB;;oDAInC;AAGD;IADC,IAAA,eAAM,EAAC,KAAK,CAAC;IAEX,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;IACzB,WAAA,IAAA,oCAAW,GAAE,CAAA;;;;oDAGf;iCAtBU,sBAAsB;IADlC,IAAA,mBAAU,EAAC,iBAAiB,CAAC;qCAEsB,2CAAmB;GAD1D,sBAAsB,CAuBlC"}
+2
View File
@@ -0,0 +1,2 @@
export declare class ReceiptAliasModule {
}
+25
View File
@@ -0,0 +1,25 @@
"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReceiptAliasModule = void 0;
const common_1 = require("@nestjs/common");
const receipt_alias_controller_1 = require("./receipt-alias.controller");
const receipt_alias_service_1 = require("./receipt-alias.service");
const prisma_module_1 = require("../prisma/prisma.module");
let ReceiptAliasModule = class ReceiptAliasModule {
};
exports.ReceiptAliasModule = ReceiptAliasModule;
exports.ReceiptAliasModule = ReceiptAliasModule = __decorate([
(0, common_1.Module)({
imports: [prisma_module_1.PrismaModule],
controllers: [receipt_alias_controller_1.ReceiptAliasController],
providers: [receipt_alias_service_1.ReceiptAliasService],
exports: [receipt_alias_service_1.ReceiptAliasService],
})
], ReceiptAliasModule);
//# sourceMappingURL=receipt-alias.module.js.map
@@ -0,0 +1 @@
{"version":3,"file":"receipt-alias.module.js","sourceRoot":"","sources":["../../src/receipt-alias/receipt-alias.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,yEAAoE;AACpE,mEAA8D;AAC9D,2DAAuD;AAQhD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;CAAG,CAAA;AAArB,gDAAkB;6BAAlB,kBAAkB;IAN9B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAY,CAAC;QACvB,WAAW,EAAE,CAAC,iDAAsB,CAAC;QACrC,SAAS,EAAE,CAAC,2CAAmB,CAAC;QAChC,OAAO,EAAE,CAAC,2CAAmB,CAAC;KAC/B,CAAC;GACW,kBAAkB,CAAG"}
+37
View File
@@ -0,0 +1,37 @@
import { PrismaService } from '../prisma/prisma.service';
import { CreateReceiptAliasDto } from './dto/create-receipt-alias.dto';
export declare class ReceiptAliasService {
private readonly prisma;
constructor(prisma: PrismaService);
findAllForUser(userId: number, role: string): import(".prisma/client").Prisma.PrismaPromise<({
product: {
name: string;
canonicalName: string | null;
id: number;
};
} & {
id: number;
createdAt: Date;
ownerId: number | null;
productId: number;
receiptName: string;
isGlobal: boolean;
})[]>;
upsert(dto: CreateReceiptAliasDto, userId: number, role: string): Promise<{
id: number;
createdAt: Date;
ownerId: number | null;
productId: number;
receiptName: string;
isGlobal: boolean;
}>;
private upsertAliasRecord;
remove(id: number, userId: number, role: string): Promise<{
id: number;
createdAt: Date;
ownerId: number | null;
productId: number;
receiptName: string;
isGlobal: boolean;
}>;
}
+76
View File
@@ -0,0 +1,76 @@
"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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReceiptAliasService = void 0;
const common_1 = require("@nestjs/common");
const prisma_service_1 = require("../prisma/prisma.service");
let ReceiptAliasService = class ReceiptAliasService {
constructor(prisma) {
this.prisma = prisma;
}
findAllForUser(userId, role) {
const where = role === 'admin'
? undefined
: {
OR: [
{ ownerId: userId, isGlobal: false },
{ isGlobal: true },
],
};
return this.prisma.receiptAlias.findMany({
where,
include: { product: { select: { id: true, name: true, canonicalName: true } } },
orderBy: { receiptName: 'asc' },
});
}
async upsert(dto, userId, role) {
const normalized = dto.receiptName.toLowerCase().trim();
const wantsGlobal = dto.isGlobal === true;
if (wantsGlobal && role !== 'admin') {
throw new common_1.ForbiddenException('Endast admin kan skapa globala alias');
}
return this.upsertAliasRecord(normalized, dto.productId, wantsGlobal ? null : userId, wantsGlobal);
}
async upsertAliasRecord(receiptName, productId, ownerId, isGlobal) {
const existing = await this.prisma.receiptAlias.findFirst({
where: isGlobal
? { receiptName, isGlobal: true }
: { receiptName, ownerId, isGlobal: false },
});
if (existing) {
return this.prisma.receiptAlias.update({
where: { id: existing.id },
data: { productId },
});
}
return this.prisma.receiptAlias.create({
data: { receiptName, productId, ownerId, isGlobal },
});
}
async remove(id, userId, role) {
const alias = await this.prisma.receiptAlias.findUnique({ where: { id } });
if (!alias) {
throw new common_1.NotFoundException(`Aliaspost med id ${id} hittades inte`);
}
const canDelete = role === 'admin' ||
(alias.ownerId === userId && alias.isGlobal === false);
if (!canDelete) {
throw new common_1.ForbiddenException('Du har inte behörighet att ta bort aliaset');
}
return this.prisma.receiptAlias.delete({ where: { id } });
}
};
exports.ReceiptAliasService = ReceiptAliasService;
exports.ReceiptAliasService = ReceiptAliasService = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
], ReceiptAliasService);
//# sourceMappingURL=receipt-alias.service.js.map
@@ -0,0 +1 @@
{"version":3,"file":"receipt-alias.service.js","sourceRoot":"","sources":["../../src/receipt-alias/receipt-alias.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAmF;AACnF,6DAAyD;AAIlD,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,YAA6B,MAAqB;QAArB,WAAM,GAAN,MAAM,CAAe;IAAG,CAAC;IAEtD,cAAc,CAAC,MAAc,EAAE,IAAY;QACzC,MAAM,KAAK,GAAG,IAAI,KAAK,OAAO;YAC5B,CAAC,CAAC,SAAS;YACX,CAAC,CAAC;gBACE,EAAE,EAAE;oBACF,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;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