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,7 @@
export declare class UpsertUserProductDto {
productId: number;
note?: string;
preferredBrand?: string;
preferredStore?: string;
isPrivate?: boolean;
}
@@ -0,0 +1,41 @@
"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.UpsertUserProductDto = void 0;
const class_validator_1 = require("class-validator");
class UpsertUserProductDto {
}
exports.UpsertUserProductDto = UpsertUserProductDto;
__decorate([
(0, class_validator_1.IsInt)(),
__metadata("design:type", Number)
], UpsertUserProductDto.prototype, "productId", void 0);
__decorate([
(0, class_validator_1.IsOptional)(),
(0, class_validator_1.IsString)(),
__metadata("design:type", String)
], UpsertUserProductDto.prototype, "note", void 0);
__decorate([
(0, class_validator_1.IsOptional)(),
(0, class_validator_1.IsString)(),
__metadata("design:type", String)
], UpsertUserProductDto.prototype, "preferredBrand", void 0);
__decorate([
(0, class_validator_1.IsOptional)(),
(0, class_validator_1.IsString)(),
__metadata("design:type", String)
], UpsertUserProductDto.prototype, "preferredStore", void 0);
__decorate([
(0, class_validator_1.IsOptional)(),
(0, class_validator_1.IsBoolean)(),
__metadata("design:type", Boolean)
], UpsertUserProductDto.prototype, "isPrivate", void 0);
//# sourceMappingURL=upsert-user-product.dto.js.map
@@ -0,0 +1 @@
{"version":3,"file":"upsert-user-product.dto.js","sourceRoot":"","sources":["../../../src/user-products/dto/upsert-user-product.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAyE;AAEzE,MAAa,oBAAoB;CAmBhC;AAnBD,oDAmBC;AAjBC;IADC,IAAA,uBAAK,GAAE;;uDACU;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;kDACG;AAId;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;4DACa;AAIxB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;4DACa;AAIxB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;uDACQ"}
+119
View File
@@ -0,0 +1,119 @@
import { UserProductsService } from './user-products.service';
import { UpsertUserProductDto } from './dto/upsert-user-product.dto';
export declare class UserProductsController {
private readonly service;
constructor(service: UserProductsService);
findAll(user: {
userId: number;
}): import(".prisma/client").Prisma.PrismaPromise<({
product: {
nutrition: {
calories: number | null;
protein: number | null;
fat: number | null;
carbohydrates: number | null;
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
tags: ({
tag: {
name: string;
id: number;
};
} & {
productId: number;
tagId: number;
})[];
} & {
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;
isPrivate: boolean;
productId: number;
note: string | null;
userId: number;
preferredBrand: string | null;
preferredStore: string | null;
})[]>;
upsert(user: {
userId: number;
}, dto: UpsertUserProductDto): import(".prisma/client").Prisma.Prisma__UserProductClient<{
product: {
nutrition: {
calories: number | null;
protein: number | null;
fat: number | null;
carbohydrates: number | null;
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
tags: ({
tag: {
name: string;
id: number;
};
} & {
productId: number;
tagId: number;
})[];
} & {
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;
isPrivate: boolean;
productId: number;
note: string | null;
userId: number;
preferredBrand: string | null;
preferredStore: string | null;
}, never, import("@prisma/client/runtime/library").DefaultArgs, import(".prisma/client").Prisma.PrismaClientOptions>;
remove(user: {
userId: number;
}, productId: number): import(".prisma/client").Prisma.Prisma__UserProductClient<{
id: number;
createdAt: Date;
updatedAt: Date;
isPrivate: boolean;
productId: number;
note: string | null;
userId: number;
preferredBrand: string | null;
preferredStore: string | null;
}, never, import("@prisma/client/runtime/library").DefaultArgs, import(".prisma/client").Prisma.PrismaClientOptions>;
}
+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.UserProductsController = void 0;
const common_1 = require("@nestjs/common");
const user_products_service_1 = require("./user-products.service");
const upsert_user_product_dto_1 = require("./dto/upsert-user-product.dto");
const current_user_decorator_1 = require("../auth/decorators/current-user.decorator");
let UserProductsController = class UserProductsController {
constructor(service) {
this.service = service;
}
findAll(user) {
return this.service.findAll(user.userId);
}
upsert(user, dto) {
return this.service.upsert(user.userId, dto);
}
remove(user, productId) {
return this.service.remove(user.userId, productId);
}
};
exports.UserProductsController = UserProductsController;
__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)
], UserProductsController.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, upsert_user_product_dto_1.UpsertUserProductDto]),
__metadata("design:returntype", void 0)
], UserProductsController.prototype, "upsert", null);
__decorate([
(0, common_1.Delete)(':productId'),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__param(1, (0, common_1.Param)('productId', common_1.ParseIntPipe)),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Number]),
__metadata("design:returntype", void 0)
], UserProductsController.prototype, "remove", null);
exports.UserProductsController = UserProductsController = __decorate([
(0, common_1.Controller)('user-products'),
__metadata("design:paramtypes", [user_products_service_1.UserProductsService])
], UserProductsController);
//# sourceMappingURL=user-products.controller.js.map
@@ -0,0 +1 @@
{"version":3,"file":"user-products.controller.js","sourceRoot":"","sources":["../../src/user-products/user-products.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AACxB,mEAA8D;AAC9D,2EAAqE;AACrE,sFAAwE;AAGjE,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IACjC,YAA6B,OAA4B;QAA5B,YAAO,GAAP,OAAO,CAAqB;IAAG,CAAC;IAG7D,OAAO,CAAgB,IAAwB;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IAGD,MAAM,CACW,IAAwB,EAC/B,GAAyB;QAEjC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC/C,CAAC;IAGD,MAAM,CACW,IAAwB,EACL,SAAiB;QAEnD,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACrD,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,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAM,8CAAoB;;oDAGlC;AAGD;IADC,IAAA,eAAM,EAAC,YAAY,CAAC;IAElB,WAAA,IAAA,oCAAW,GAAE,CAAA;IACb,WAAA,IAAA,cAAK,EAAC,WAAW,EAAE,qBAAY,CAAC,CAAA;;;;oDAGlC;iCAtBU,sBAAsB;IADlC,IAAA,mBAAU,EAAC,eAAe,CAAC;qCAEY,2CAAmB;GAD9C,sBAAsB,CAuBlC"}
+2
View File
@@ -0,0 +1,2 @@
export declare class UserProductsModule {
}
+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.UserProductsModule = void 0;
const common_1 = require("@nestjs/common");
const user_products_controller_1 = require("./user-products.controller");
const user_products_service_1 = require("./user-products.service");
const prisma_module_1 = require("../prisma/prisma.module");
let UserProductsModule = class UserProductsModule {
};
exports.UserProductsModule = UserProductsModule;
exports.UserProductsModule = UserProductsModule = __decorate([
(0, common_1.Module)({
imports: [prisma_module_1.PrismaModule],
controllers: [user_products_controller_1.UserProductsController],
providers: [user_products_service_1.UserProductsService],
})
], UserProductsModule);
//# sourceMappingURL=user-products.module.js.map
@@ -0,0 +1 @@
{"version":3,"file":"user-products.module.js","sourceRoot":"","sources":["../../src/user-products/user-products.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,yEAAoE;AACpE,mEAA8D;AAC9D,2DAAuD;AAOhD,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;CAAG,CAAA;AAArB,gDAAkB;6BAAlB,kBAAkB;IAL9B,IAAA,eAAM,EAAC;QACN,OAAO,EAAE,CAAC,4BAAY,CAAC;QACvB,WAAW,EAAE,CAAC,iDAAsB,CAAC;QACrC,SAAS,EAAE,CAAC,2CAAmB,CAAC;KACjC,CAAC;GACW,kBAAkB,CAAG"}
+161
View File
@@ -0,0 +1,161 @@
import { PrismaService } from '../prisma/prisma.service';
import { UpsertUserProductDto } from './dto/upsert-user-product.dto';
export declare class UserProductsService {
private readonly prisma;
constructor(prisma: PrismaService);
findAll(userId: number): import(".prisma/client").Prisma.PrismaPromise<({
product: {
nutrition: {
calories: number | null;
protein: number | null;
fat: number | null;
carbohydrates: number | null;
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
tags: ({
tag: {
name: string;
id: number;
};
} & {
productId: number;
tagId: number;
})[];
} & {
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;
isPrivate: boolean;
productId: number;
note: string | null;
userId: number;
preferredBrand: string | null;
preferredStore: string | null;
})[]>;
findOne(userId: number, productId: number): import(".prisma/client").Prisma.Prisma__UserProductClient<({
product: {
nutrition: {
calories: number | null;
protein: number | null;
fat: number | null;
carbohydrates: number | null;
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
tags: ({
tag: {
name: string;
id: number;
};
} & {
productId: number;
tagId: number;
})[];
} & {
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;
isPrivate: boolean;
productId: number;
note: string | null;
userId: number;
preferredBrand: string | null;
preferredStore: string | null;
}) | null, null, import("@prisma/client/runtime/library").DefaultArgs, import(".prisma/client").Prisma.PrismaClientOptions>;
upsert(userId: number, dto: UpsertUserProductDto): import(".prisma/client").Prisma.Prisma__UserProductClient<{
product: {
nutrition: {
calories: number | null;
protein: number | null;
fat: number | null;
carbohydrates: number | null;
salt: number | null;
sugar: number | null;
fiber: number | null;
id: number;
productId: number;
} | null;
tags: ({
tag: {
name: string;
id: number;
};
} & {
productId: number;
tagId: number;
})[];
} & {
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;
isPrivate: boolean;
productId: number;
note: string | null;
userId: number;
preferredBrand: string | null;
preferredStore: string | null;
}, never, import("@prisma/client/runtime/library").DefaultArgs, import(".prisma/client").Prisma.PrismaClientOptions>;
remove(userId: number, productId: number): import(".prisma/client").Prisma.Prisma__UserProductClient<{
id: number;
createdAt: Date;
updatedAt: Date;
isPrivate: boolean;
productId: number;
note: string | null;
userId: number;
preferredBrand: string | null;
preferredStore: string | null;
}, never, import("@prisma/client/runtime/library").DefaultArgs, import(".prisma/client").Prisma.PrismaClientOptions>;
}
+60
View File
@@ -0,0 +1,60 @@
"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.UserProductsService = void 0;
const common_1 = require("@nestjs/common");
const prisma_service_1 = require("../prisma/prisma.service");
const PRODUCT_INCLUDE = {
product: {
include: {
nutrition: true,
tags: { include: { tag: true } },
},
},
};
let UserProductsService = class UserProductsService {
constructor(prisma) {
this.prisma = prisma;
}
findAll(userId) {
return this.prisma.userProduct.findMany({
where: { userId },
include: PRODUCT_INCLUDE,
orderBy: { updatedAt: 'desc' },
});
}
findOne(userId, productId) {
return this.prisma.userProduct.findUnique({
where: { userId_productId: { userId, productId } },
include: PRODUCT_INCLUDE,
});
}
upsert(userId, dto) {
const { productId, ...data } = dto;
return this.prisma.userProduct.upsert({
where: { userId_productId: { userId, productId } },
create: { userId, productId, ...data },
update: data,
include: PRODUCT_INCLUDE,
});
}
remove(userId, productId) {
return this.prisma.userProduct.delete({
where: { userId_productId: { userId, productId } },
});
}
};
exports.UserProductsService = UserProductsService;
exports.UserProductsService = UserProductsService = __decorate([
(0, common_1.Injectable)(),
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
], UserProductsService);
//# sourceMappingURL=user-products.service.js.map
@@ -0,0 +1 @@
{"version":3,"file":"user-products.service.js","sourceRoot":"","sources":["../../src/user-products/user-products.service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