feat(models): households ve householdMembers Mongoose modelleri

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 02:14:10 +03:00
parent 3e11a34235
commit 38e2a7a26d
3 changed files with 78 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
import { model, models, Schema, type InferSchemaType, type Model } from "mongoose";
import { HOUSEHOLD_ROLES } from "@/features/households/types";
/** Kullanıcının bir hanedeki üyeliği ve hane içi rolü (owner | member | viewer). */
const householdMemberSchema = new Schema(
{
householdId: { type: Schema.Types.ObjectId, ref: "Household", required: true },
/** Better Auth `user` koleksiyonundaki _id. */
userId: { type: Schema.Types.ObjectId, required: true },
role: { type: String, enum: HOUSEHOLD_ROLES, required: true },
createdBy: { type: Schema.Types.ObjectId, required: true },
updatedBy: { type: Schema.Types.ObjectId, required: true },
},
{ timestamps: true, collection: "householdMembers" },
);
// Bir kullanıcı bir hanede yalnızca bir kez üye olabilir.
householdMemberSchema.index({ householdId: 1, userId: 1 }, { unique: true });
// Kullanıcının hanelerini hızlı listelemek için.
householdMemberSchema.index({ userId: 1, householdId: 1 });
export type HouseholdMember = InferSchemaType<typeof householdMemberSchema>;
export const HouseholdMemberModel: Model<HouseholdMember> =
(models.HouseholdMember as Model<HouseholdMember> | undefined) ??
model<HouseholdMember>("HouseholdMember", householdMemberSchema);