Artikel DB struktur geändert von CODEX

This commit is contained in:
Marco_205 committed 2026-10-12 14:42:28 +00:00
1 parent 0c0a678eaa
commit 9c18234efe
95 files changed
+3872 -2316

No files matched your search

@@ -1,76 +1,53 @@
import { Injectable } from '@nestjs/common';
import { BadRequestException, Injectable } from '@nestjs/common';
import { InjectModel } from '@nestjs/mongoose';
import { Model, Types } from 'mongoose';
import { ClientSession, Model, Types } from 'mongoose';
import { StockMovement } from '../_entities/stock-movement.entity';
import { StockMovementInDto, StockMovementType, StockMovementTransferDto, StockMovementOutDto } from '../_dto/stock-movement.dto';
import { StockContent } from '../_entities/stock-content.entity';
import { StockMovementType } from '../_dto/stock-movement.dto';
@Injectable()
export class MovementRepository {
constructor(
@InjectModel(StockMovement.name)
private readonly model: Model<StockMovement>,
) { }
async findAll() {
return this.model.find().exec();
) {}
findAll() {
return this.model
.find({ articleId: { $exists: true } })
.sort({ createdAt: -1 })
.exec();
}
remove(id: string) {
return this.model.findByIdAndDelete(id);
}
// ===============================
// IN
// ===============================
async logStockMoveIn(dto: StockMovementInDto) {
const { articleVariantId, stockId, quantity } = dto;
return this.model.create(
{
articleVariantId,
stockId,
type: StockMovementType.IN,
quantity
}
remove(_id: string): never {
throw new BadRequestException(
'Buchungsprotokolle können nicht gelöscht werden',
);
}
// ===============================
// OUT
// ===============================
async logStockMoveOut(dto: StockMovementOutDto,result:any) {
return this.model.create({
stockId: new Types.ObjectId(dto.stockContentId),
articleVariantId: new Types.ObjectId(result.articelVariantId),
type: StockMovementType.OUT,
quantity: dto.quantity,
});
async log(
type: StockMovementType,
content: StockContent,
quantity: number,
session: ClientSession,
toStockId?: string,
toArea?: string,
) {
const [movement] = await this.model.create(
[
{
type,
articleId: content.articleId,
stockId: content.stockId,
quantity,
batchId: content.batchId ?? undefined,
assetId: content.assetId ?? undefined,
toStockId: toStockId ? new Types.ObjectId(toStockId) : undefined,
meta: {
fromArea: content.area,
...(toArea !== undefined ? { toArea } : {}),
},
},
],
{ session },
);
return movement;
}
// ===============================
// TRANSFER
// ===============================
async logStockContentTransfer(dto: StockMovementTransferDto) {
const { articleVariantId, quantity, fromStockId, toStockId } = dto;
return this.model.create({
articleVariantId: new Types.ObjectId(articleVariantId),
stockId:fromStockId,
type: StockMovementType.TRANSFER,
quantity,
meta: {
fromLocationId: new Types.ObjectId(fromStockId),
toLocationId: new Types.ObjectId(toStockId),
},
});
}
}
}