feat(models): households ve householdMembers Mongoose modelleri
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
Reference in New Issue
Block a user