const mongoose = require("mongoose"); const PointTransactionSchema = new mongoose.Schema( { user: { type: mongoose.Schema.Types.ObjectId, ref: "User", required: true, index: true, }, amount: { type: Number, required: true, }, type: { type: String, enum: [ "street_adoption", "task_completion", "post_creation", "event_participation", "reward_redemption", "admin_adjustment", ], required: true, index: true, }, description: { type: String, required: true, }, relatedEntity: { entityType: { type: String, enum: ["Street", "Task", "Post", "Event", "Reward"], }, entityId: { type: mongoose.Schema.Types.ObjectId, }, }, balanceAfter: { type: Number, required: true, }, }, { timestamps: true, }, ); // Compound index for user transaction history queries PointTransactionSchema.index({ user: 1, createdAt: -1 }); // Index for querying by transaction type PointTransactionSchema.index({ type: 1, createdAt: -1 }); module.exports = mongoose.model("PointTransaction", PointTransactionSchema);