49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
const mongoose = require('mongoose');
|
|
|
|
const checkInEntrySchema = new mongoose.Schema(
|
|
{
|
|
checkedInAt: { type: Date, required: true, default: Date.now },
|
|
source: { type: String, enum: ['dashboard', 'public'], required: true },
|
|
checkedInBy: { type: mongoose.Schema.Types.ObjectId, ref: 'User' },
|
|
},
|
|
{ _id: false }
|
|
);
|
|
|
|
const attendanceParticipantSchema = new mongoose.Schema(
|
|
{
|
|
attendance: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'Attendance',
|
|
required: true,
|
|
index: true,
|
|
},
|
|
event: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'Event',
|
|
required: true,
|
|
index: true,
|
|
},
|
|
participant: {
|
|
type: mongoose.Schema.Types.ObjectId,
|
|
ref: 'Participant',
|
|
required: true,
|
|
index: true,
|
|
},
|
|
firstName: { type: String, trim: true },
|
|
lastName: { type: String, trim: true },
|
|
email: { type: String, trim: true, lowercase: true },
|
|
phone: { type: String, trim: true },
|
|
checkIns: { type: [checkInEntrySchema], default: [] },
|
|
},
|
|
{ timestamps: true }
|
|
);
|
|
|
|
attendanceParticipantSchema.index({ attendance: 1, participant: 1 }, { unique: true });
|
|
attendanceParticipantSchema.index({ attendance: 1, updatedAt: -1 });
|
|
|
|
module.exports = mongoose.model(
|
|
'AttendanceParticipant',
|
|
attendanceParticipantSchema,
|
|
'attendance_participants'
|
|
);
|