9781cd9ed2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
1.2 KiB
TypeScript
30 lines
1.2 KiB
TypeScript
import { model, models, Schema, type InferSchemaType, type Model } from "mongoose";
|
||
import { ASSET_KEYS } from "@/shared/assets";
|
||
|
||
/**
|
||
* Fiyat tablosu (Bölüm 6.6): varlık × tarih × alış/satış (birim başına kuruş). İlk aşamada elle
|
||
* giriş; otomatik kaynaklar Faz 17'de `source` ile eklenir. Gün başına tek kayıt (yeniden girişte
|
||
* güncellenir).
|
||
*/
|
||
const assetPriceSchema = new Schema(
|
||
{
|
||
householdId: { type: Schema.Types.ObjectId, required: true },
|
||
assetKey: { type: String, enum: ASSET_KEYS, required: true },
|
||
/** "YYYY-MM-DD" (İstanbul). */
|
||
date: { type: String, required: true },
|
||
buyMinor: { type: Number, required: true, min: 0 },
|
||
sellMinor: { type: Number, required: true, min: 0 },
|
||
source: { type: String, enum: ["manual"], default: "manual" },
|
||
createdBy: { type: Schema.Types.ObjectId, required: true },
|
||
},
|
||
{ timestamps: true, collection: "assetPrices" },
|
||
);
|
||
|
||
assetPriceSchema.index({ householdId: 1, assetKey: 1, date: -1 }, { unique: true });
|
||
|
||
export type AssetPrice = InferSchemaType<typeof assetPriceSchema>;
|
||
|
||
export const AssetPriceModel: Model<AssetPrice> =
|
||
(models.AssetPrice as Model<AssetPrice> | undefined) ??
|
||
model<AssetPrice>("AssetPrice", assetPriceSchema);
|