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
+3
View File
@@ -0,0 +1,3 @@
export declare class CreatePantryItemDto {
productId: number;
}
+22
View File
@@ -0,0 +1,22 @@
"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.CreatePantryItemDto = void 0;
const class_validator_1 = require("class-validator");
class CreatePantryItemDto {
}
exports.CreatePantryItemDto = CreatePantryItemDto;
__decorate([
(0, class_validator_1.IsInt)(),
(0, class_validator_1.IsPositive)(),
__metadata("design:type", Number)
], CreatePantryItemDto.prototype, "productId", void 0);
//# sourceMappingURL=create-pantry-item.dto.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"create-pantry-item.dto.js","sourceRoot":"","sources":["../../../src/pantry/dto/create-pantry-item.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAoD;AAEpD,MAAa,mBAAmB;CAI/B;AAJD,kDAIC;AADC;IAFC,IAAA,uBAAK,GAAE;IACP,IAAA,4BAAU,GAAE;;sDACK"}
+65
View File
@@ -0,0 +1,65 @@
import { PantryService } from './pantry.service';
import { CreatePantryItemDto } from './dto/create-pantry-item.dto';
export declare class PantryController {
private readonly pantryService;
constructor(pantryService: PantryService);
findAll(user: {
userId: number;
}): import(".prisma/client").Prisma.PrismaPromise<({
product: {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
createdAt: Date;
updatedAt: Date;
ownerId: number;
isPrivate: boolean;
};
} & {
id: number;
createdAt: Date;
updatedAt: Date;
productId: number;
userId: number;
})[]>;
create(user: {
userId: number;
}, body: CreatePantryItemDto): Promise<{
product: {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
createdAt: Date;
updatedAt: Date;
ownerId: number;
isPrivate: boolean;
};
} & {
id: number;
createdAt: Date;
updatedAt: Date;
productId: number;
userId: number;
}>;
remove(user: {
userId: number;
}, id: number): Promise<{
id: number;
createdAt: Date;
updatedAt: Date;
productId: number;
userId: number;
}>;
}
+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.PantryController = void 0;
const common_1 = require("@nestjs/common");
const pantry_service_1 = require("./pantry.service");
const create_pantry_item_dto_1 = require("./dto/create-pantry-item.dto");
const current_user_decorator_1 = require("../auth/decorators/current-user.decorator");
let PantryController = class PantryController {
constructor(pantryService) {
this.pantryService = pantryService;
}
findAll(user) {
return this.pantryService.findAll(user.userId);
}
create(user, body) {
return this.pantryService.create(user.userId, body);
}
remove(user, id) {
return this.pantryService.remove(user.userId, id);
}
};
exports.PantryController = PantryController;
__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)
], PantryController.prototype, "findAll", null);
__decorate([
(0, common_1.Post)(),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, create_pantry_item_dto_1.CreatePantryItemDto]),
__metadata("design:returntype", void 0)
], PantryController.prototype, "create", null);
__decorate([
(0, common_1.Delete)(':id'),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__param(1, (0, common_1.Param)('id', common_1.ParseIntPipe)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Number]),
__metadata("design:returntype", void 0)
], PantryController.prototype, "remove", null);
exports.PantryController = PantryController = __decorate([
(0, common_1.Controller)('pantry'),
__metadata("design:paramtypes", [pantry_service_1.PantryService])
], PantryController);
//# sourceMappingURL=pantry.controller.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"pantry.controller.js","sourceRoot":"","sources":["../../src/pantry/pantry.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA0F;AAC1F,qDAAiD;AACjD,yEAAmE;AACnE,sFAAwE;AAGjE,IAAM,gBAAgB,GAAtB,MAAM,gBAAgB;IAC3B,YAA6B,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;IAAG,CAAC;IAG7D,OAAO,CAAgB,IAAwB;QAC7C,OAAO,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjD,CAAC;IAGD,MAAM,CACW,IAAwB,EAC/B,IAAyB;QAEjC,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;IAGD,MAAM,CACW,IAAwB,EACZ,EAAU;QAErC,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACpD,CAAC;CACF,CAAA;AAvBY,4CAAgB;AAI3B;IADC,IAAA,YAAG,GAAE;IACG,WAAA,IAAA,oCAAW,GAAE,CAAA;;;;+CAErB;AAGD;IADC,IAAA,aAAI,GAAE;IAEJ,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAO,4CAAmB;;8CAGlC;AAGD;IADC,IAAA,eAAM,EAAC,KAAK,CAAC;IAEX,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;;;;8CAG3B;2BAtBU,gBAAgB;IAD5B,IAAA,mBAAU,EAAC,QAAQ,CAAC;qCAEyB,8BAAa;GAD9C,gBAAgB,CAuB5B"}
+2
View File
@@ -0,0 +1,2 @@
export declare class PantryModule {
}
+24
View File
@@ -0,0 +1,24 @@
"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.PantryModule = void 0;
const common_1 = require("@nestjs/common");
const pantry_controller_1 = require("./pantry.controller");
const pantry_service_1 = require("./pantry.service");
const prisma_module_1 = require("../prisma/prisma.module");
let PantryModule = class PantryModule {
};
exports.PantryModule = PantryModule;
exports.PantryModule = PantryModule = __decorate([
(0, common_1.Module)({
controllers: [pantry_controller_1.PantryController],
providers: [pantry_service_1.PantryService],
imports: [prisma_module_1.PrismaModule],
})
], PantryModule);
//# sourceMappingURL=pantry.module.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"pantry.module.js","sourceRoot":"","sources":["../../src/pantry/pantry.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,2DAAuD;AACvD,qDAAiD;AACjD,2DAAuD;AAOhD,IAAM,YAAY,GAAlB,MAAM,YAAY;CAAG,CAAA;AAAf,oCAAY;uBAAZ,YAAY;IALxB,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,oCAAgB,CAAC;QAC/B,SAAS,EAAE,CAAC,8BAAa,CAAC;QAC1B,OAAO,EAAE,CAAC,4BAAY,CAAC;KACxB,CAAC;GACW,YAAY,CAAG"}
+59
View File
@@ -0,0 +1,59 @@
import { PrismaService } from '../prisma/prisma.service';
import { CreatePantryItemDto } from './dto/create-pantry-item.dto';
export declare class PantryService {
private readonly prisma;
constructor(prisma: PrismaService);
findAll(userId: number): import(".prisma/client").Prisma.PrismaPromise<({
product: {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
createdAt: Date;
updatedAt: Date;
ownerId: number;
isPrivate: boolean;
};
} & {
id: number;
createdAt: Date;
updatedAt: Date;
productId: number;
userId: number;
})[]>;
create(userId: number, data: CreatePantryItemDto): Promise<{
product: {
category: string | null;
status: string;
name: string;
categoryId: number | null;
canonicalName: string | null;
id: number;
normalizedName: string;
isActive: boolean;
deletedAt: Date | null;
createdAt: Date;
updatedAt: Date;
ownerId: number;
isPrivate: boolean;
};
} & {
id: number;
createdAt: Date;
updatedAt: Date;
productId: number;
userId: number;
}>;
remove(userId: number, id: number): Promise<{
id: number;
createdAt: Date;
updatedAt: Date;
productId: number;
userId: number;
}>;
}
+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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PantryService = void 0;
const common_1 = require("@nestjs/common");
const prisma_service_1 = require("../prisma/prisma.service");
let PantryService = class PantryService {
constructor(prisma) {
this.prisma = prisma;
}
findAll(userId) {
return this.prisma.pantryItem.findMany({
where: { userId },
include: {
product: true,
},
orderBy: {
product: { name: 'asc' },
},
});
}
async create(userId, data) {
const existing = await this.prisma.pantryItem.findUnique({
where: {
userId_productId: {
userId,
productId: data.productId,
},
},
});
if (existing) {
throw new common_1.ConflictException('Produkten finns redan i baslagret');
}
return this.prisma.pantryItem.create({
data: { userId, productId: data.productId },
include: { product: true },
});
}
async remove(userId, id) {
const item = await this.prisma.pantryItem.findFirst({
where: { id, userId },
});
if (!item) {
throw new common_1.NotFoundException(`PantryItem med id ${id} hittades inte`);
}
return this.prisma.pantryItem.delete({ where: { id } });
}
};
exports.PantryService = PantryService;
exports.PantryService = PantryService = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
], PantryService);
//# sourceMappingURL=pantry.service.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"pantry.service.js","sourceRoot":"","sources":["../../src/pantry/pantry.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAkF;AAClF,6DAAyD;AAI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