Refactor code structure for improved readability and maintainability
Test Suite / test (24.15.0) (push) Has been cancelled
Test Suite / test (24.15.0) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
export declare class ConsumeInventoryDto {
|
||||
amountUsed: number;
|
||||
comment?: string;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
"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.ConsumeInventoryDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
class ConsumeInventoryDto {
|
||||
}
|
||||
exports.ConsumeInventoryDto = ConsumeInventoryDto;
|
||||
__decorate([
|
||||
(0, class_validator_1.IsNumber)(),
|
||||
(0, class_validator_1.Min)(0.01),
|
||||
__metadata("design:type", Number)
|
||||
], ConsumeInventoryDto.prototype, "amountUsed", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], ConsumeInventoryDto.prototype, "comment", void 0);
|
||||
//# sourceMappingURL=consume-inventory.dto.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"consume-inventory.dto.js","sourceRoot":"","sources":["../../../src/inventory/dto/consume-inventory.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAAsE;AAEtE,MAAa,mBAAmB;CAQ/B;AARD,kDAQC;AALC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,IAAI,CAAC;;uDACU;AAIpB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;oDACM"}
|
||||
@@ -0,0 +1,14 @@
|
||||
export declare class CreateInventoryDto {
|
||||
productId: number;
|
||||
quantity: number;
|
||||
unit: string;
|
||||
location?: string;
|
||||
purchaseDate?: string;
|
||||
bestBeforeDate?: string;
|
||||
brand?: string;
|
||||
origin?: string;
|
||||
receiptName?: string;
|
||||
opened?: boolean;
|
||||
suitableFor?: string;
|
||||
comment?: string;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
"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.CreateInventoryDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
class CreateInventoryDto {
|
||||
}
|
||||
exports.CreateInventoryDto = CreateInventoryDto;
|
||||
__decorate([
|
||||
(0, class_validator_1.IsInt)(),
|
||||
__metadata("design:type", Number)
|
||||
], CreateInventoryDto.prototype, "productId", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsNumber)(),
|
||||
(0, class_validator_1.Min)(0),
|
||||
__metadata("design:type", Number)
|
||||
], CreateInventoryDto.prototype, "quantity", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateInventoryDto.prototype, "unit", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateInventoryDto.prototype, "location", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateInventoryDto.prototype, "purchaseDate", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateInventoryDto.prototype, "bestBeforeDate", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateInventoryDto.prototype, "brand", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateInventoryDto.prototype, "origin", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateInventoryDto.prototype, "receiptName", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsBoolean)(),
|
||||
__metadata("design:type", Boolean)
|
||||
], CreateInventoryDto.prototype, "opened", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateInventoryDto.prototype, "suitableFor", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], CreateInventoryDto.prototype, "comment", void 0);
|
||||
//# sourceMappingURL=create-inventory.dto.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"create-inventory.dto.js","sourceRoot":"","sources":["../../../src/inventory/dto/create-inventory.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAOyB;AAEzB,MAAa,kBAAkB;CA4C9B;AA5CD,gDA4CC;AA1CC;IADC,IAAA,uBAAK,GAAE;;qDACW;AAInB;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;;oDACW;AAGlB;IADC,IAAA,0BAAQ,GAAE;;gDACG;AAId;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;oDACO;AAGlB;IADC,IAAA,4BAAU,GAAE;;wDACS;AAGtB;IADC,IAAA,4BAAU,GAAE;;0DACW;AAIxB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;iDACI;AAIf;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;kDACK;AAIhB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;uDACU;AAIrB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;kDACK;AAIjB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;uDACU;AAIrB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mDACM"}
|
||||
@@ -0,0 +1,13 @@
|
||||
export declare class UpdateInventoryDto {
|
||||
productId?: number;
|
||||
quantity?: number;
|
||||
unit?: string;
|
||||
location?: string;
|
||||
purchaseDate?: string;
|
||||
bestBeforeDate?: string;
|
||||
brand?: string;
|
||||
receiptName?: string;
|
||||
opened?: boolean;
|
||||
suitableFor?: string;
|
||||
comment?: string;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
"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.UpdateInventoryDto = void 0;
|
||||
const class_validator_1 = require("class-validator");
|
||||
class UpdateInventoryDto {
|
||||
}
|
||||
exports.UpdateInventoryDto = UpdateInventoryDto;
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsInt)(),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateInventoryDto.prototype, "productId", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsNumber)(),
|
||||
(0, class_validator_1.Min)(0),
|
||||
__metadata("design:type", Number)
|
||||
], UpdateInventoryDto.prototype, "quantity", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateInventoryDto.prototype, "unit", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateInventoryDto.prototype, "location", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateInventoryDto.prototype, "purchaseDate", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateInventoryDto.prototype, "bestBeforeDate", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateInventoryDto.prototype, "brand", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateInventoryDto.prototype, "receiptName", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsBoolean)(),
|
||||
__metadata("design:type", Boolean)
|
||||
], UpdateInventoryDto.prototype, "opened", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateInventoryDto.prototype, "suitableFor", void 0);
|
||||
__decorate([
|
||||
(0, class_validator_1.IsOptional)(),
|
||||
(0, class_validator_1.IsString)(),
|
||||
__metadata("design:type", String)
|
||||
], UpdateInventoryDto.prototype, "comment", void 0);
|
||||
//# sourceMappingURL=update-inventory.dto.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"update-inventory.dto.js","sourceRoot":"","sources":["../../../src/inventory/dto/update-inventory.dto.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qDAOyB;AAEzB,MAAa,kBAAkB;CA2C9B;AA3CD,gDA2CC;AAxCC;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,uBAAK,GAAE;;qDACW;AAKnB;IAHC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAG,EAAC,CAAC,CAAC;;oDACW;AAIlB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;gDACG;AAId;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;oDACO;AAGlB;IADC,IAAA,4BAAU,GAAE;;wDACS;AAGtB;IADC,IAAA,4BAAU,GAAE;;0DACW;AAIxB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;iDACI;AAIf;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;uDACU;AAIrB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,2BAAS,GAAE;;kDACK;AAIjB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;uDACU;AAIrB;IAFC,IAAA,4BAAU,GAAE;IACZ,IAAA,0BAAQ,GAAE;;mDACM"}
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
import { CreateInventoryDto } from './dto/create-inventory.dto';
|
||||
import { UpdateInventoryDto } from './dto/update-inventory.dto';
|
||||
import { InventoryService } from './inventory.service';
|
||||
import { ConsumeInventoryDto } from './dto/consume-inventory.dto';
|
||||
export declare class InventoryController {
|
||||
private readonly inventoryService;
|
||||
constructor(inventoryService: InventoryService);
|
||||
consume(id: number, body: ConsumeInventoryDto): 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;
|
||||
quantity: import("@prisma/client/runtime/library").Decimal;
|
||||
unit: string;
|
||||
brand: string | null;
|
||||
origin: string | null;
|
||||
receiptName: string | null;
|
||||
location: string | null;
|
||||
purchaseDate: Date | null;
|
||||
opened: boolean | null;
|
||||
suitableFor: string | null;
|
||||
bestBeforeDate: Date | null;
|
||||
comment: string | null;
|
||||
}>;
|
||||
findConsumptionHistory(id: number): Promise<{
|
||||
inventoryItem: {
|
||||
unit: string;
|
||||
};
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
comment: string | null;
|
||||
amountUsed: import("@prisma/client/runtime/library").Decimal;
|
||||
inventoryItemId: number;
|
||||
}[]>;
|
||||
findAll(location?: string, sort?: string): 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;
|
||||
quantity: import("@prisma/client/runtime/library").Decimal;
|
||||
unit: string;
|
||||
brand: string | null;
|
||||
origin: string | null;
|
||||
receiptName: string | null;
|
||||
location: string | null;
|
||||
purchaseDate: Date | null;
|
||||
opened: boolean | null;
|
||||
suitableFor: string | null;
|
||||
bestBeforeDate: Date | null;
|
||||
comment: string | null;
|
||||
})[]>;
|
||||
findExpiring(): 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;
|
||||
quantity: import("@prisma/client/runtime/library").Decimal;
|
||||
unit: string;
|
||||
brand: string | null;
|
||||
origin: string | null;
|
||||
receiptName: string | null;
|
||||
location: string | null;
|
||||
purchaseDate: Date | null;
|
||||
opened: boolean | null;
|
||||
suitableFor: string | null;
|
||||
bestBeforeDate: Date | null;
|
||||
comment: string | null;
|
||||
})[]>;
|
||||
create(body: CreateInventoryDto): 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;
|
||||
quantity: import("@prisma/client/runtime/library").Decimal;
|
||||
unit: string;
|
||||
brand: string | null;
|
||||
origin: string | null;
|
||||
receiptName: string | null;
|
||||
location: string | null;
|
||||
purchaseDate: Date | null;
|
||||
opened: boolean | null;
|
||||
suitableFor: string | null;
|
||||
bestBeforeDate: Date | null;
|
||||
comment: string | null;
|
||||
}>;
|
||||
update(id: number, body: UpdateInventoryDto): 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;
|
||||
quantity: import("@prisma/client/runtime/library").Decimal;
|
||||
unit: string;
|
||||
brand: string | null;
|
||||
origin: string | null;
|
||||
receiptName: string | null;
|
||||
location: string | null;
|
||||
purchaseDate: Date | null;
|
||||
opened: boolean | null;
|
||||
suitableFor: string | null;
|
||||
bestBeforeDate: Date | null;
|
||||
comment: string | null;
|
||||
}>;
|
||||
remove(id: number): Promise<{
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
productId: number;
|
||||
quantity: import("@prisma/client/runtime/library").Decimal;
|
||||
unit: string;
|
||||
brand: string | null;
|
||||
origin: string | null;
|
||||
receiptName: string | null;
|
||||
location: string | null;
|
||||
purchaseDate: Date | null;
|
||||
opened: boolean | null;
|
||||
suitableFor: string | null;
|
||||
bestBeforeDate: Date | null;
|
||||
comment: string | null;
|
||||
}>;
|
||||
}
|
||||
+103
@@ -0,0 +1,103 @@
|
||||
"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.InventoryController = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const create_inventory_dto_1 = require("./dto/create-inventory.dto");
|
||||
const update_inventory_dto_1 = require("./dto/update-inventory.dto");
|
||||
const inventory_service_1 = require("./inventory.service");
|
||||
const consume_inventory_dto_1 = require("./dto/consume-inventory.dto");
|
||||
let InventoryController = class InventoryController {
|
||||
constructor(inventoryService) {
|
||||
this.inventoryService = inventoryService;
|
||||
}
|
||||
consume(id, body) {
|
||||
return this.inventoryService.consume(id, body);
|
||||
}
|
||||
findConsumptionHistory(id) {
|
||||
return this.inventoryService.findConsumptionHistory(id);
|
||||
}
|
||||
findAll(location, sort) {
|
||||
return this.inventoryService.findAll({ location, sort });
|
||||
}
|
||||
findExpiring() {
|
||||
return this.inventoryService.findExpiring();
|
||||
}
|
||||
create(body) {
|
||||
return this.inventoryService.create(body);
|
||||
}
|
||||
update(id, body) {
|
||||
return this.inventoryService.update(id, body);
|
||||
}
|
||||
remove(id) {
|
||||
return this.inventoryService.remove(id);
|
||||
}
|
||||
};
|
||||
exports.InventoryController = InventoryController;
|
||||
__decorate([
|
||||
(0, common_1.Post)(':id/consume'),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Number, consume_inventory_dto_1.ConsumeInventoryDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], InventoryController.prototype, "consume", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)(':id/consumption-history'),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Number]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], InventoryController.prototype, "findConsumptionHistory", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)(),
|
||||
__param(0, (0, common_1.Query)('location')),
|
||||
__param(1, (0, common_1.Query)('sort')),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [String, String]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], InventoryController.prototype, "findAll", null);
|
||||
__decorate([
|
||||
(0, common_1.Get)('expiring'),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", []),
|
||||
__metadata("design:returntype", void 0)
|
||||
], InventoryController.prototype, "findExpiring", null);
|
||||
__decorate([
|
||||
(0, common_1.Post)(),
|
||||
__param(0, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [create_inventory_dto_1.CreateInventoryDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], InventoryController.prototype, "create", null);
|
||||
__decorate([
|
||||
(0, common_1.Patch)(':id'),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
||||
__param(1, (0, common_1.Body)()),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Number, update_inventory_dto_1.UpdateInventoryDto]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], InventoryController.prototype, "update", null);
|
||||
__decorate([
|
||||
(0, common_1.Delete)(':id'),
|
||||
__param(0, (0, common_1.Param)('id', common_1.ParseIntPipe)),
|
||||
__metadata("design:type", Function),
|
||||
__metadata("design:paramtypes", [Number]),
|
||||
__metadata("design:returntype", void 0)
|
||||
], InventoryController.prototype, "remove", null);
|
||||
exports.InventoryController = InventoryController = __decorate([
|
||||
(0, common_1.Controller)('inventory'),
|
||||
__metadata("design:paramtypes", [inventory_service_1.InventoryService])
|
||||
], InventoryController);
|
||||
//# sourceMappingURL=inventory.controller.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"inventory.controller.js","sourceRoot":"","sources":["../../src/inventory/inventory.controller.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAUwB;AACxB,qEAAgE;AAChE,qEAAgE;AAChE,2DAAuD;AACvD,uEAAkE;AAG3D,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAC9B,YAA6B,gBAAkC;QAAlC,qBAAgB,GAAhB,gBAAgB,CAAkB;IAAG,CAAC;IAGpE,OAAO,CACsB,EAAU,EAC7B,IAAyB;QAElC,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAGH,sBAAsB,CAA4B,EAAU;QAC1D,OAAO,IAAI,CAAC,gBAAgB,CAAC,sBAAsB,CAAC,EAAE,CAAC,CAAC;IACxD,CAAC;IAGD,OAAO,CACc,QAAiB,EACrB,IAAa;QAE5B,OAAO,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;IAGD,YAAY;QACV,OAAO,IAAI,CAAC,gBAAgB,CAAC,YAAY,EAAE,CAAC;IAC9C,CAAC;IAGD,MAAM,CAAS,IAAwB;QACrC,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAC5C,CAAC;IAGD,MAAM,CACuB,EAAU,EAC7B,IAAwB;QAEhC,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC;IAGD,MAAM,CAA4B,EAAU;QAC1C,OAAO,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC1C,CAAC;CACF,CAAA;AA9CY,kDAAmB;AAI/B;IADC,IAAA,aAAI,EAAC,aAAa,CAAC;IAEjB,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;IACzB,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAO,2CAAmB;;kDAGjC;AAGH;IADG,IAAA,YAAG,EAAC,yBAAyB,CAAC;IACT,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;;;;iEAE9C;AAGD;IADC,IAAA,YAAG,GAAE;IAEH,WAAA,IAAA,cAAK,EAAC,UAAU,CAAC,CAAA;IACjB,WAAA,IAAA,cAAK,EAAC,MAAM,CAAC,CAAA;;;;kDAGf;AAGD;IADC,IAAA,YAAG,EAAC,UAAU,CAAC;;;;uDAGf;AAGD;IADC,IAAA,aAAI,GAAE;IACC,WAAA,IAAA,aAAI,GAAE,CAAA;;qCAAO,yCAAkB;;iDAEtC;AAGD;IADC,IAAA,cAAK,EAAC,KAAK,CAAC;IAEV,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;IACzB,WAAA,IAAA,aAAI,GAAE,CAAA;;6CAAO,yCAAkB;;iDAGjC;AAGD;IADC,IAAA,eAAM,EAAC,KAAK,CAAC;IACN,WAAA,IAAA,cAAK,EAAC,IAAI,EAAE,qBAAY,CAAC,CAAA;;;;iDAEhC;8BA7CU,mBAAmB;IAD/B,IAAA,mBAAU,EAAC,WAAW,CAAC;qCAEyB,oCAAgB;GADpD,mBAAmB,CA8C/B"}
|
||||
@@ -0,0 +1,2 @@
|
||||
export declare class InventoryModule {
|
||||
}
|
||||
+24
@@ -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.InventoryModule = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const inventory_controller_1 = require("./inventory.controller");
|
||||
const inventory_service_1 = require("./inventory.service");
|
||||
const prisma_module_1 = require("../prisma/prisma.module");
|
||||
let InventoryModule = class InventoryModule {
|
||||
};
|
||||
exports.InventoryModule = InventoryModule;
|
||||
exports.InventoryModule = InventoryModule = __decorate([
|
||||
(0, common_1.Module)({
|
||||
controllers: [inventory_controller_1.InventoryController],
|
||||
providers: [inventory_service_1.InventoryService],
|
||||
imports: [prisma_module_1.PrismaModule],
|
||||
})
|
||||
], InventoryModule);
|
||||
//# sourceMappingURL=inventory.module.js.map
|
||||
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"inventory.module.js","sourceRoot":"","sources":["../../src/inventory/inventory.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAAwC;AACxC,iEAA6D;AAC7D,2DAAuD;AACvD,2DAAuD;AAOhD,IAAM,eAAe,GAArB,MAAM,eAAe;CAAG,CAAA;AAAlB,0CAAe;0BAAf,eAAe;IAL3B,IAAA,eAAM,EAAC;QACN,WAAW,EAAE,CAAC,0CAAmB,CAAC;QAClC,SAAS,EAAE,CAAC,oCAAgB,CAAC;QAC7B,OAAO,EAAE,CAAC,4BAAY,CAAC;KACxB,CAAC;GACW,eAAe,CAAG"}
|
||||
+209
@@ -0,0 +1,209 @@
|
||||
import { ConsumeInventoryDto } from './dto/consume-inventory.dto';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { CreateInventoryDto } from './dto/create-inventory.dto';
|
||||
import { UpdateInventoryDto } from './dto/update-inventory.dto';
|
||||
type InventoryQuery = {
|
||||
location?: string;
|
||||
sort?: string;
|
||||
};
|
||||
export declare class InventoryService {
|
||||
private prisma;
|
||||
constructor(prisma: PrismaService);
|
||||
private throwInventoryItemNotFound;
|
||||
private findInventoryItemByIdOrThrow;
|
||||
private ensureProductExists;
|
||||
findAll(query?: InventoryQuery): 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;
|
||||
quantity: Prisma.Decimal;
|
||||
unit: string;
|
||||
brand: string | null;
|
||||
origin: string | null;
|
||||
receiptName: string | null;
|
||||
location: string | null;
|
||||
purchaseDate: Date | null;
|
||||
opened: boolean | null;
|
||||
suitableFor: string | null;
|
||||
bestBeforeDate: Date | null;
|
||||
comment: string | null;
|
||||
})[]>;
|
||||
consume(id: number, data: ConsumeInventoryDto): 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;
|
||||
quantity: Prisma.Decimal;
|
||||
unit: string;
|
||||
brand: string | null;
|
||||
origin: string | null;
|
||||
receiptName: string | null;
|
||||
location: string | null;
|
||||
purchaseDate: Date | null;
|
||||
opened: boolean | null;
|
||||
suitableFor: string | null;
|
||||
bestBeforeDate: Date | null;
|
||||
comment: string | null;
|
||||
}>;
|
||||
findConsumptionHistory(id: number): Promise<{
|
||||
inventoryItem: {
|
||||
unit: string;
|
||||
};
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
comment: string | null;
|
||||
amountUsed: Prisma.Decimal;
|
||||
inventoryItemId: number;
|
||||
}[]>;
|
||||
findExpiring(): 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;
|
||||
quantity: Prisma.Decimal;
|
||||
unit: string;
|
||||
brand: string | null;
|
||||
origin: string | null;
|
||||
receiptName: string | null;
|
||||
location: string | null;
|
||||
purchaseDate: Date | null;
|
||||
opened: boolean | null;
|
||||
suitableFor: string | null;
|
||||
bestBeforeDate: Date | null;
|
||||
comment: string | null;
|
||||
})[]>;
|
||||
create(data: CreateInventoryDto): 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;
|
||||
quantity: Prisma.Decimal;
|
||||
unit: string;
|
||||
brand: string | null;
|
||||
origin: string | null;
|
||||
receiptName: string | null;
|
||||
location: string | null;
|
||||
purchaseDate: Date | null;
|
||||
opened: boolean | null;
|
||||
suitableFor: string | null;
|
||||
bestBeforeDate: Date | null;
|
||||
comment: string | null;
|
||||
}>;
|
||||
update(id: number, data: UpdateInventoryDto): 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;
|
||||
quantity: Prisma.Decimal;
|
||||
unit: string;
|
||||
brand: string | null;
|
||||
origin: string | null;
|
||||
receiptName: string | null;
|
||||
location: string | null;
|
||||
purchaseDate: Date | null;
|
||||
opened: boolean | null;
|
||||
suitableFor: string | null;
|
||||
bestBeforeDate: Date | null;
|
||||
comment: string | null;
|
||||
}>;
|
||||
remove(id: number): Promise<{
|
||||
id: number;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
productId: number;
|
||||
quantity: Prisma.Decimal;
|
||||
unit: string;
|
||||
brand: string | null;
|
||||
origin: string | null;
|
||||
receiptName: string | null;
|
||||
location: string | null;
|
||||
purchaseDate: Date | null;
|
||||
opened: boolean | null;
|
||||
suitableFor: string | null;
|
||||
bestBeforeDate: Date | null;
|
||||
comment: string | null;
|
||||
}>;
|
||||
}
|
||||
export {};
|
||||
+216
@@ -0,0 +1,216 @@
|
||||
"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.InventoryService = void 0;
|
||||
const common_1 = require("@nestjs/common");
|
||||
const client_1 = require("@prisma/client");
|
||||
const prisma_service_1 = require("../prisma/prisma.service");
|
||||
let InventoryService = class InventoryService {
|
||||
constructor(prisma) {
|
||||
this.prisma = prisma;
|
||||
}
|
||||
throwInventoryItemNotFound(id) {
|
||||
throw new common_1.NotFoundException(`Inventory item with id ${id} not found`);
|
||||
}
|
||||
async findInventoryItemByIdOrThrow(id) {
|
||||
const existing = await this.prisma.inventoryItem.findUnique({ where: { id } });
|
||||
if (!existing) {
|
||||
this.throwInventoryItemNotFound(id);
|
||||
}
|
||||
return existing;
|
||||
}
|
||||
async ensureProductExists(productId) {
|
||||
const product = await this.prisma.product.findUnique({ where: { id: productId } });
|
||||
if (!product) {
|
||||
throw new common_1.NotFoundException('Product not found');
|
||||
}
|
||||
return product;
|
||||
}
|
||||
async findAll(query) {
|
||||
const where = {};
|
||||
const orderBy = [];
|
||||
if (query?.location) {
|
||||
where.location = query.location;
|
||||
}
|
||||
if (query?.sort === 'bestBeforeAsc') {
|
||||
orderBy.push({ bestBeforeDate: 'asc' });
|
||||
}
|
||||
else if (query?.sort === 'bestBeforeDesc') {
|
||||
orderBy.push({ bestBeforeDate: 'desc' });
|
||||
}
|
||||
else if (query?.sort === 'nameAsc') {
|
||||
orderBy.push({ product: { name: 'asc' } });
|
||||
}
|
||||
else if (query?.sort === 'purchaseDateAsc') {
|
||||
orderBy.push({ purchaseDate: 'asc' });
|
||||
}
|
||||
else if (query?.sort === 'purchaseDateDesc') {
|
||||
orderBy.push({ purchaseDate: 'desc' });
|
||||
}
|
||||
else {
|
||||
orderBy.push({ createdAt: 'desc' });
|
||||
}
|
||||
return this.prisma.inventoryItem.findMany({
|
||||
where,
|
||||
include: {
|
||||
product: true,
|
||||
},
|
||||
orderBy,
|
||||
});
|
||||
}
|
||||
async consume(id, data) {
|
||||
const existing = await this.findInventoryItemByIdOrThrow(id);
|
||||
const currentQuantity = Number(existing.quantity);
|
||||
const newQuantity = Math.max(0, currentQuantity - data.amountUsed);
|
||||
return this.prisma.$transaction(async (tx) => {
|
||||
const updatedItem = await tx.inventoryItem.update({
|
||||
where: { id },
|
||||
data: {
|
||||
quantity: new client_1.Prisma.Decimal(newQuantity),
|
||||
},
|
||||
include: {
|
||||
product: true,
|
||||
},
|
||||
});
|
||||
await tx.inventoryConsumption.create({
|
||||
data: {
|
||||
inventoryItemId: id,
|
||||
amountUsed: new client_1.Prisma.Decimal(data.amountUsed),
|
||||
comment: data.comment?.trim() || null,
|
||||
},
|
||||
});
|
||||
return updatedItem;
|
||||
});
|
||||
}
|
||||
async findConsumptionHistory(id) {
|
||||
await this.findInventoryItemByIdOrThrow(id);
|
||||
return this.prisma.inventoryConsumption.findMany({
|
||||
where: {
|
||||
inventoryItemId: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
inventoryItemId: true,
|
||||
amountUsed: true,
|
||||
comment: true,
|
||||
createdAt: true,
|
||||
inventoryItem: {
|
||||
select: { unit: true },
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
});
|
||||
}
|
||||
async findExpiring() {
|
||||
const now = new Date();
|
||||
return this.prisma.inventoryItem.findMany({
|
||||
where: {
|
||||
bestBeforeDate: {
|
||||
not: null,
|
||||
gte: now,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
product: true,
|
||||
},
|
||||
orderBy: [{ bestBeforeDate: 'asc' }, { createdAt: 'desc' }],
|
||||
});
|
||||
}
|
||||
async create(data) {
|
||||
await this.ensureProductExists(data.productId);
|
||||
return this.prisma.inventoryItem.create({
|
||||
data: {
|
||||
...data,
|
||||
quantity: new client_1.Prisma.Decimal(data.quantity),
|
||||
location: data.location?.trim() || undefined,
|
||||
brand: data.brand?.trim() || undefined,
|
||||
origin: data.origin?.trim() || undefined,
|
||||
receiptName: data.receiptName?.trim() || undefined,
|
||||
suitableFor: data.suitableFor?.trim() || undefined,
|
||||
comment: data.comment?.trim() || undefined,
|
||||
purchaseDate: data.purchaseDate
|
||||
? new Date(data.purchaseDate)
|
||||
: undefined,
|
||||
bestBeforeDate: data.bestBeforeDate
|
||||
? new Date(data.bestBeforeDate)
|
||||
: undefined,
|
||||
},
|
||||
include: {
|
||||
product: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
async update(id, data) {
|
||||
await this.findInventoryItemByIdOrThrow(id);
|
||||
if (typeof data.productId === 'number') {
|
||||
await this.ensureProductExists(data.productId);
|
||||
}
|
||||
const updateData = {};
|
||||
if (typeof data.productId === 'number') {
|
||||
updateData.product = {
|
||||
connect: { id: data.productId },
|
||||
};
|
||||
}
|
||||
if (typeof data.quantity === 'number') {
|
||||
updateData.quantity = new client_1.Prisma.Decimal(data.quantity);
|
||||
}
|
||||
if (typeof data.unit === 'string') {
|
||||
updateData.unit = data.unit.trim();
|
||||
}
|
||||
if (typeof data.location === 'string') {
|
||||
updateData.location = data.location.trim();
|
||||
}
|
||||
if (typeof data.brand === 'string') {
|
||||
updateData.brand = data.brand.trim();
|
||||
}
|
||||
if (typeof data.receiptName === 'string') {
|
||||
updateData.receiptName = data.receiptName.trim();
|
||||
}
|
||||
if (typeof data.purchaseDate === 'string') {
|
||||
updateData.purchaseDate = data.purchaseDate
|
||||
? new Date(data.purchaseDate)
|
||||
: null;
|
||||
}
|
||||
if (typeof data.bestBeforeDate === 'string') {
|
||||
updateData.bestBeforeDate = data.bestBeforeDate
|
||||
? new Date(data.bestBeforeDate)
|
||||
: null;
|
||||
}
|
||||
if (typeof data.opened === 'boolean') {
|
||||
updateData.opened = data.opened;
|
||||
}
|
||||
if (typeof data.suitableFor === 'string') {
|
||||
updateData.suitableFor = data.suitableFor.trim();
|
||||
}
|
||||
if (typeof data.comment === 'string') {
|
||||
updateData.comment = data.comment.trim();
|
||||
}
|
||||
return this.prisma.inventoryItem.update({
|
||||
where: { id },
|
||||
data: updateData,
|
||||
include: {
|
||||
product: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
async remove(id) {
|
||||
await this.findInventoryItemByIdOrThrow(id);
|
||||
return this.prisma.inventoryItem.delete({ where: { id } });
|
||||
}
|
||||
};
|
||||
exports.InventoryService = InventoryService;
|
||||
exports.InventoryService = InventoryService = __decorate([
|
||||
(0, common_1.Injectable)(),
|
||||
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
||||
], InventoryService);
|
||||
//# sourceMappingURL=inventory.service.js.map
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user