This repository has been archived on 2026-05-04. You can view files and clone it, but cannot push or open issues or pull requests.
Galaxy-Strike-Online/API/models/PlayerData.js
2026-03-11 00:32:45 -03:00

32 lines
1016 B
JavaScript

/**
* 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;