moved api from monorepo
This commit is contained in:
104
models/Game.js
Normal file
104
models/Game.js
Normal file
@ -0,0 +1,104 @@
|
||||
import mongoose from 'mongoose'
|
||||
import slugify from 'slugify'
|
||||
|
||||
const {Schema, model} = mongoose
|
||||
|
||||
const GameSchema = new Schema(
|
||||
{
|
||||
title: {type: String, trim: true, required: true},
|
||||
series: {type: String, trim: true},
|
||||
steamId: {
|
||||
type: String,
|
||||
index: {unique: true, partialFilterExpression: {steamId: {$exists: true, $gt: 0, $type: String}}}
|
||||
},
|
||||
slug: String,
|
||||
frontImage: {type: String, required: true},
|
||||
screenshots: Array,
|
||||
genre: {type: Array, sparse: true},
|
||||
os: {
|
||||
windows: {type: Boolean},
|
||||
mac: {type: Boolean},
|
||||
linux: {type: Boolean},
|
||||
android: {type: Boolean},
|
||||
ios: {type: Boolean}
|
||||
},
|
||||
wine: {type: String, enum: ['Not Tested', 'Yes', 'No']},
|
||||
controller: {
|
||||
type: String,
|
||||
enum: [
|
||||
'No Controller Support',
|
||||
'Partial Controller Support',
|
||||
'Full Controller Support',
|
||||
],
|
||||
},
|
||||
developer: {type: Array, sparse: true},
|
||||
publisher: {type: Array, sparse: true},
|
||||
releaseDate: {type: String},
|
||||
shortDesc: {type: String},
|
||||
reviews: String,
|
||||
summary: String,
|
||||
intel: {type: String, enum: ['Not Tested', 'Yes', 'No']},
|
||||
systemRequirements: {
|
||||
windows: {
|
||||
minimum: String,
|
||||
recommended: String,
|
||||
},
|
||||
mac: {
|
||||
minimum: String,
|
||||
recommended: String,
|
||||
},
|
||||
linux: {
|
||||
minimum: String,
|
||||
recommended: String,
|
||||
},
|
||||
},
|
||||
steamRating: {type: Number, min: 0, max: 10, default: 0},
|
||||
createdBy: {
|
||||
type: Schema.ObjectId,
|
||||
ref: 'User',
|
||||
required: true,
|
||||
},
|
||||
accessedBy: [
|
||||
{
|
||||
user: {
|
||||
type: Schema.ObjectId,
|
||||
ref: 'User',
|
||||
required: true,
|
||||
},
|
||||
store: {type: Array, required: true},
|
||||
playStatus: {
|
||||
type: String,
|
||||
enum: ['Never Played', 'Up Next', 'Playing', 'Finished', 'Will Not Play'],
|
||||
default: 'Never Played',
|
||||
},
|
||||
soundtrack: {type: String, enum: ['Yes', 'No'], default: 'No'},
|
||||
rating: {type: Number, min: 0, max: 10, default: 0}
|
||||
},
|
||||
],
|
||||
lastModifiedBy: {
|
||||
type: Schema.ObjectId,
|
||||
ref: 'User',
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
{timestamps: {createdAt: 'createDate', updatedAt: 'lastUpdateDate'}}
|
||||
)
|
||||
|
||||
GameSchema.pre('save', function (next) {
|
||||
this.slug = slugify(this.title, {lower: true})
|
||||
next()
|
||||
})
|
||||
|
||||
GameSchema.index({accessedBy: {user: 1}}, {unique: true})
|
||||
|
||||
GameSchema.index({
|
||||
title: 'text',
|
||||
series: 'text',
|
||||
steamId: 'text',
|
||||
genre: 'text',
|
||||
developer: 'text',
|
||||
publisher: 'text',
|
||||
slug: 'text',
|
||||
})
|
||||
|
||||
export default model('Game', GameSchema)
|
Reference in New Issue
Block a user