match.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import mongoose from 'mongoose'
  2. const MatchSchema = new mongoose.Schema({
  3. created: Date,
  4. idString: String,
  5. fileLine: Number,
  6. category: String,
  7. place: String,
  8. date: Date,
  9. player1: { type: mongoose.Schema.Types.ObjectId, ref: 'Player' },
  10. player2: { type: mongoose.Schema.Types.ObjectId, ref: 'Player' },
  11. result: String,
  12. doubles: Boolean
  13. })
  14. MatchSchema.methods.equal = function (matchData, cb) {
  15. for (let property in matchData) {
  16. if (property == 'created') return true
  17. if (this[property] instanceof Date) {
  18. if (this[property].getTime() != matchData[property].getTime()) {
  19. console.log('dates dont match', property, this[property], matchData[property])
  20. return false
  21. }
  22. } else if (this[property] instanceof mongoose.Types.ObjectId) {
  23. if (!this[property].equals(matchData[property])) {
  24. console.log('objectids dont match', this[property], matchData[property])
  25. return false
  26. }
  27. } else {
  28. if (this[property] != matchData[property]) {
  29. console.log('property doesnt match', property, this[property], typeof this[property], matchData[property], typeof matchData[property])
  30. return false
  31. }
  32. }
  33. }
  34. return true
  35. }
  36. const Match = mongoose.model('Match', MatchSchema)
  37. export default Match