Phase 9
This commit is contained in:
parent
e396f5088c
commit
a1801af63b
36 changed files with 4783 additions and 31 deletions
54
packages/api/src/schemas/shopping-list.schema.ts
Normal file
54
packages/api/src/schemas/shopping-list.schema.ts
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import mongoose from 'mongoose';
|
||||
|
||||
const shoppingItemSchema = new mongoose.Schema(
|
||||
{
|
||||
id: { type: String, required: true }, // Client or server generated tracking UUID
|
||||
productId: { type: String },
|
||||
customName: { type: String },
|
||||
quantity: { type: Number, required: true },
|
||||
unit: { type: String, required: true },
|
||||
checked: { type: Boolean, required: true, default: false },
|
||||
checkedAt: { type: Date },
|
||||
checkedBy: { type: String },
|
||||
estimatedPrice: { type: Number },
|
||||
actualPrice: { type: Number },
|
||||
storeId: { type: String },
|
||||
notes: { type: String },
|
||||
category: { type: String },
|
||||
addedToPantry: { type: Boolean, required: true, default: false },
|
||||
},
|
||||
{ _id: false }
|
||||
);
|
||||
|
||||
const shoppingListSchema = new mongoose.Schema(
|
||||
{
|
||||
householdId: { type: String, required: true },
|
||||
name: { type: String, required: true },
|
||||
items: { type: [shoppingItemSchema], required: true, default: [] },
|
||||
status: { type: String, required: true }, // values from ShoppingListStatus
|
||||
createdFrom: {
|
||||
type: {
|
||||
type: { type: String, required: true }, // values from ShoppingListSourceType
|
||||
referenceId: { type: String },
|
||||
},
|
||||
required: false,
|
||||
_id: false,
|
||||
},
|
||||
mealPlanId: { type: String },
|
||||
totalEstimatedCost: { type: Number },
|
||||
preferredStoreId: { type: String },
|
||||
completedAt: { type: Date },
|
||||
createdBy: { type: String, required: true },
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
shoppingListSchema.index({ householdId: 1, status: 1 });
|
||||
shoppingListSchema.index({ householdId: 1, createdAt: -1 });
|
||||
|
||||
export const ShoppingListModel = mongoose.model('ShoppingList', shoppingListSchema);
|
||||
export type ShoppingListDocument = mongoose.InferSchemaType<typeof shoppingListSchema> & {
|
||||
_id: mongoose.Types.ObjectId;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue