feat(shopping): alışveriş listeleri, stok eşiği önerileri ve akıllı mağaza önerisi motoru

- shoppingLists koleksiyonu (ürün tipi / marka / serbest metin kalemleri), migration 015
- planShopping saf fonksiyonu: paket yuvarlama, zahmet ve hacimli cezası, teslimat, yemek kartı önceliği, ek mağaza eşiği
- eşik önerileri onay/red (red stok yenilenene kadar), ürün tipine hacimli işareti
- fiyat servisinde ortak loadTypeOffers; seed listeleri ve testler

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-06 23:28:54 +03:00
parent 0b7de17b5c
commit 8ab2244755
21 changed files with 2325 additions and 16 deletions
+1
View File
@@ -45,6 +45,7 @@ export const AUDIT_ACTIONS = [
"product.archive",
"product.unarchive",
"price.delete",
"shoppingList.delete",
] as const;
export type AuditAction = (typeof AUDIT_ACTIONS)[number];
+7
View File
@@ -22,6 +22,13 @@ const productTypeSchema = new Schema(
/** Sayım sıklığı (gün); null ise kategoriden devralınır (Faz 11b). */
countEveryDays: { type: Number, default: null, min: 1, max: 365 },
note: { type: String, default: "", maxlength: 300 },
/** Ağır/hacimli (su, deterjan): akıllı öneri zahmetli fiziksel mağazadan uzak tutar (Faz 13). */
bulky: { type: Boolean, default: false },
/**
* Eşik önerisi reddedildi: bu tarihten sonra alım hareketi gelene (stok yenilenene) kadar
* öneri gösterilmez (Faz 13).
*/
suggestionDismissedAt: { type: Date, default: null },
archivedAt: { type: Date, default: null },
seedRef: { type: String, default: null },
createdBy: { type: Schema.Types.ObjectId, required: true },
+61
View File
@@ -0,0 +1,61 @@
import { model, models, Schema, type InferSchemaType, type Model } from "mongoose";
import {
SHOPPING_ITEM_KINDS,
SHOPPING_ITEM_SOURCES,
SHOPPING_LIST_STATUSES,
} from "@/shared/shopping";
/**
* Alışveriş kalemi (Bölüm 6.12): ürün tipi (genel), belirli ürün (marka/paket) ya da serbest metin.
* Miktar binde bir: ürün tipinde tipin biriminde, üründe paket adedi, serbest metinde `unit` ile.
* `checked`: alışveriş modunda sepete alındı.
*/
const shoppingItemSchema = new Schema(
{
kind: { type: String, enum: SHOPPING_ITEM_KINDS, required: true },
productTypeId: { type: Schema.Types.ObjectId, default: null },
productId: { type: Schema.Types.ObjectId, default: null },
text: { type: String, default: "", trim: true, maxlength: 120 },
/** Boşsa "1 paket" kabul edilir. */
quantity: { type: Number, default: null, min: 0 },
/** Serbest metin kaleminin birimi. */
unit: { type: String, default: "", trim: true, maxlength: 20 },
note: { type: String, default: "", trim: true, maxlength: 200 },
source: { type: String, enum: SHOPPING_ITEM_SOURCES, default: "manual" },
checked: { type: Boolean, default: false },
checkedBy: { type: Schema.Types.ObjectId, default: null },
checkedAt: { type: Date, default: null },
addedBy: { type: Schema.Types.ObjectId, required: true },
addedAt: { type: Date, default: () => new Date() },
},
{ _id: true },
);
/** Alışveriş listesi; hane içinde ortak. Birden çok aktif liste olabilir. Silme: soft delete. */
const shoppingListSchema = new Schema(
{
householdId: { type: Schema.Types.ObjectId, required: true },
name: { type: String, required: true, trim: true, maxlength: 80 },
status: { type: String, enum: SHOPPING_LIST_STATUSES, default: "active" },
note: { type: String, default: "", trim: true, maxlength: 300 },
items: { type: [shoppingItemSchema], default: [] },
completedAt: { type: Date, default: null },
deletedAt: { 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: "shoppingLists" },
);
shoppingListSchema.index({ householdId: 1, deletedAt: 1, status: 1, updatedAt: -1 });
shoppingListSchema.index(
{ householdId: 1, seedRef: 1 },
{ unique: true, partialFilterExpression: { seedRef: { $type: "string" } } },
);
export type ShoppingList = InferSchemaType<typeof shoppingListSchema>;
export const ShoppingListModel: Model<ShoppingList> =
(models.ShoppingList as Model<ShoppingList> | undefined) ??
model<ShoppingList>("ShoppingList", shoppingListSchema);