Files
butcem/src/models/store.ts
T

44 lines
2.0 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 { MEAL_CARD_PROVIDERS } from "@/shared/accounts";
import { STORE_KINDS } from "@/shared/stores";
/**
* Mağaza (Bölüm 6.11): fiziksel market, online platform veya pazar. Hane bazlı (hane içinde
* ortak). Uzaklık metre; teslimat ücretleri kuruş. Zahmet skoru okuma sırasında hesaplanır.
*/
const storeSchema = new Schema(
{
householdId: { type: Schema.Types.ObjectId, required: true },
name: { type: String, required: true, trim: true, maxlength: 80 },
nameKey: { type: String, required: true },
kind: { type: String, enum: STORE_KINDS, required: true },
branch: { type: String, default: "", maxlength: 80 },
/** Eve uzaklık (metre); online mağazada null. */
distanceM: { type: Number, default: null, min: 0 },
/** Taşıma güçlüğü 1 (kolay) – 5 (çok zor). */
carryDifficulty: { type: Number, default: 1, min: 1, max: 5 },
/** Online: teslimat ücreti ve ücretsiz teslimat alt limiti (kuruş). */
deliveryFeeMinor: { type: Number, default: null, min: 0 },
freeDeliveryMinMinor: { type: Number, default: null, min: 0 },
mealCardAccepted: { type: Boolean, default: false },
mealCardProviders: { type: [{ type: String, enum: MEAL_CARD_PROVIDERS }], default: [] },
note: { type: String, default: "", maxlength: 300 },
archivedAt: { type: Date, default: null },
seedRef: { type: String, default: null },
createdBy: { type: Schema.Types.ObjectId, required: true },
updatedBy: { type: Schema.Types.ObjectId, required: true },
},
{ timestamps: true, collection: "stores" },
);
storeSchema.index({ householdId: 1, archivedAt: 1, nameKey: 1 });
storeSchema.index(
{ householdId: 1, seedRef: 1 },
{ unique: true, partialFilterExpression: { seedRef: { $type: "string" } } },
);
export type Store = InferSchemaType<typeof storeSchema>;
export const StoreModel: Model<Store> =
(models.Store as Model<Store> | undefined) ?? model<Store>("Store", storeSchema);