Files
butcem/src/models/asset-price.ts
T

30 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);