/** * API/models/PlayerData.js * * Minimal PlayerData model for the API server — only what the payment webhook * needs to read and credit gems. Shares the 'playerdatas' collection with * the GameServer's full PlayerData model (same MongoDB, same schema name). * * Do NOT add complex game logic here — that belongs in GameServer. */ const mongoose = require('mongoose'); // Minimal schema — Mixed types let us read/write without strict field validation const playerDataSchema = new mongoose.Schema({ userId: { type: String, required: true, unique: true }, username: { type: String }, stats: { type: mongoose.Schema.Types.Mixed, default: {} }, }, { strict: false, // allow all fields to be stored (don't strip unknown fields) timestamps: true, }); // Prevent model re-registration error on hot-reload let PlayerData; try { PlayerData = mongoose.model('PlayerData'); } catch (e) { PlayerData = mongoose.model('PlayerData', playerDataSchema); } module.exports = PlayerData;