feat(households): hane rolleri, servis, DAL hane kapsamı ve denetim kaydı

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-05 02:35:01 +03:00
parent 291a117b4f
commit de91f2505a
10 changed files with 731 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
import { model, models, Schema, type InferSchemaType, type Model } from "mongoose";
/**
* Denetim kaydı (yalnızca eklenir, güncellenmez). Bölüm 7.2: hane ayarları, üye değişiklikleri,
* silmeler, aynî borç kapatma ve mutabakat düzeltmeleri; ayrıca admin kullanıcı işlemleri.
*/
export const AUDIT_ACTIONS = [
"household.create",
"household.settings.update",
"household.member.add",
"household.member.role",
"household.member.remove",
"user.create",
"user.update",
"user.role",
"user.password.reset",
"user.ban",
"user.unban",
"user.remove",
] as const;
export type AuditAction = (typeof AUDIT_ACTIONS)[number];
const auditLogSchema = new Schema(
{
/** Hane kapsamındaki işlemlerde dolu; sistem (admin) işlemlerinde null. */
householdId: { type: Schema.Types.ObjectId, default: null },
actorId: { type: Schema.Types.ObjectId, required: true },
action: { type: String, enum: AUDIT_ACTIONS, required: true },
targetType: { type: String, required: true },
targetId: { type: String, required: true },
/** Değişen alanlar: { alan: { from, to } } veya özet bilgi. Şifre vb. sır asla yazılmaz. */
diff: { type: Schema.Types.Mixed, default: null },
at: { type: Date, default: () => new Date() },
},
{ collection: "auditLogs", versionKey: false },
);
auditLogSchema.index({ householdId: 1, at: -1 });
auditLogSchema.index({ actorId: 1, at: -1 });
export type AuditLog = InferSchemaType<typeof auditLogSchema>;
export const AuditLogModel: Model<AuditLog> =
(models.AuditLog as Model<AuditLog> | undefined) ?? model<AuditLog>("AuditLog", auditLogSchema);