feat(prices): fiyat kayıtları, birim fiyat motoru ve analizde aylık maliyet
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,7 @@ export const AUDIT_ACTIONS = [
|
||||
"store.unarchive",
|
||||
"product.archive",
|
||||
"product.unarchive",
|
||||
"price.delete",
|
||||
] as const;
|
||||
export type AuditAction = (typeof AUDIT_ACTIONS)[number];
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { model, models, Schema, type InferSchemaType, type Model } from "mongoose";
|
||||
|
||||
/**
|
||||
* Ürün fiyat kaydı (Bölüm 6.11): ürün × mağaza × tarih × paket fiyatı (kuruş). Kampanya işareti
|
||||
* ve geçerlilik sonu; kaynak `manual` | `receipt` | `provider:<ad>`. Hane bazlı. Birim fiyat
|
||||
* okuma sırasında ürünün dönüşümüyle hesaplanır (saklanmaz).
|
||||
*/
|
||||
const productPriceSchema = new Schema(
|
||||
{
|
||||
householdId: { type: Schema.Types.ObjectId, required: true },
|
||||
productId: { type: Schema.Types.ObjectId, required: true },
|
||||
storeId: { type: Schema.Types.ObjectId, required: true },
|
||||
/** "YYYY-MM-DD" (İstanbul). */
|
||||
date: { type: String, required: true },
|
||||
priceMinor: { type: Number, required: true, min: 1 },
|
||||
isPromo: { type: Boolean, default: false },
|
||||
promoUntil: { type: String, default: null },
|
||||
source: { type: String, required: true, match: /^(manual|receipt|provider:[a-z0-9-]{1,40})$/ },
|
||||
note: { type: String, default: "", maxlength: 300 },
|
||||
deletedAt: { type: Date, default: null },
|
||||
seedRef: { type: String, default: null },
|
||||
createdBy: { type: Schema.Types.ObjectId, required: true },
|
||||
},
|
||||
{ timestamps: true, collection: "productPrices" },
|
||||
);
|
||||
|
||||
productPriceSchema.index({ householdId: 1, productId: 1, deletedAt: 1, date: 1, createdAt: 1 });
|
||||
productPriceSchema.index({ householdId: 1, storeId: 1, date: -1 });
|
||||
productPriceSchema.index(
|
||||
{ householdId: 1, seedRef: 1 },
|
||||
{ unique: true, partialFilterExpression: { seedRef: { $type: "string" } } },
|
||||
);
|
||||
|
||||
export type ProductPrice = InferSchemaType<typeof productPriceSchema>;
|
||||
|
||||
export const ProductPriceModel: Model<ProductPrice> =
|
||||
(models.ProductPrice as Model<ProductPrice> | undefined) ??
|
||||
model<ProductPrice>("ProductPrice", productPriceSchema);
|
||||
Reference in New Issue
Block a user