30 lines
1.0 KiB
JavaScript
30 lines
1.0 KiB
JavaScript
const mongoose = require('mongoose');
|
|
const { Schema } = mongoose;
|
|
|
|
const BetParticipantSchema = new Schema({
|
|
user: { type: Number, required: true }, // Stores the PostgreSQL User ID
|
|
role: { type: String, enum: ['PARTICIPANT', 'OBSERVER'], required: true },
|
|
}, { _id: false });
|
|
|
|
const BetSchema = new mongoose.Schema({
|
|
title: { type: String, required: true },
|
|
description: { type: String },
|
|
stake: { type: String, required: true },
|
|
participants: [BetParticipantSchema],
|
|
status: { type: String, enum: ['ACTIVE', 'AWAITING_VALIDATION', 'COMPLETED', 'EXPIRED'], required: true },
|
|
startDate: { type: Date, default: Date.now },
|
|
endDate: { type: Date, default: null },
|
|
isPublic: { type: Boolean, default: false },
|
|
groupId: { type: String, default: null }, // Stores the PostgreSQL Group ID
|
|
winner: { type: Number, default: null }, // Stores the PostgreSQL User ID
|
|
});
|
|
|
|
BetSchema.set('toJSON', {
|
|
virtuals: true,
|
|
versionKey: false,
|
|
transform: function (doc, ret) {
|
|
delete ret._id;
|
|
}
|
|
});
|
|
|
|
module.exports = mongoose.model('Bet', BetSchema); |