- Added A TON of stuff, separated everything neatly and cleaned most models
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
// Http error w/ http code
|
||||
class HttpError extends Error {
|
||||
constructor(code, message) {
|
||||
super(message)
|
||||
this.name = "HttpError"
|
||||
this.code = code
|
||||
Error.captureStackTrace(this, this.constructor);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
HttpError
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
const School = {
|
||||
"id": "/SchoolModel",
|
||||
"type": Object,
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
"description": { "type": "string" },
|
||||
"meta_school_id": { "type": "number" },
|
||||
},
|
||||
"required": ["name", "description", "meta_school_id"]
|
||||
}
|
||||
|
||||
module.exports = School
|
||||
@@ -1,39 +0,0 @@
|
||||
const SpellModel = {
|
||||
"id": "/SpellModel",
|
||||
"type": Object,
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
"description": { "type": "string" },
|
||||
"level": { "type": "number" },
|
||||
"charge": { "type": "number" },
|
||||
"cost": { "type": "string" },
|
||||
"is_ritual": { "type": "boolean" },
|
||||
"schools": {
|
||||
"type": { "type": "array" },
|
||||
"items": {
|
||||
"properties": {
|
||||
"id": { "type": "number" },
|
||||
}
|
||||
}
|
||||
},
|
||||
"variables": {
|
||||
"type": { "type": "array" },
|
||||
"items": {
|
||||
"properties": {
|
||||
"id": { "type": "number" },
|
||||
}
|
||||
}
|
||||
},
|
||||
"ingredients": {
|
||||
"type": { "type": "array" },
|
||||
"items": {
|
||||
"properties": {
|
||||
"id": { "type": "number" },
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["name", "description"]
|
||||
}
|
||||
|
||||
module.exports = SpellModel
|
||||
@@ -1,13 +0,0 @@
|
||||
const User = {
|
||||
"id": "/UserModel",
|
||||
"type": Object,
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
"mail": { "type": "string" },
|
||||
"password": { "type": "string" },
|
||||
"banned": { "type": "boolean"},
|
||||
},
|
||||
"required": ["name", "password", "mail"]
|
||||
}
|
||||
|
||||
module.exports = User
|
||||
13
models/ingredient-model.js
Normal file
13
models/ingredient-model.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
const bookshelf = require('../database/bookshelf').bookshelf
|
||||
|
||||
require('./spell-model')
|
||||
|
||||
let Ingredient = bookshelf.Model.extend({
|
||||
tableName: 'ingredient',
|
||||
spells() {
|
||||
return this.belongsToMany( 'Spell', 'spell_ingredient')
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = bookshelf.model('Ingredient', Ingredient)
|
||||
13
models/meta-school-model.js
Normal file
13
models/meta-school-model.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
const bookshelf = require('../database/bookshelf').bookshelf
|
||||
|
||||
require('./school-model')
|
||||
|
||||
let MetaSchool = bookshelf.Model.extend({
|
||||
tableName: 'meta_school',
|
||||
schools() {
|
||||
return this.hasMany( 'School' )
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = bookshelf.model('MetaSchool', MetaSchool)
|
||||
17
models/school-model.js
Normal file
17
models/school-model.js
Normal file
@@ -0,0 +1,17 @@
|
||||
'use strict'
|
||||
const bookshelf = require('../database/bookshelf').bookshelf
|
||||
|
||||
require('./spell-model')
|
||||
require('./meta-school-model')
|
||||
|
||||
let School = bookshelf.Model.extend({
|
||||
tableName: 'school',
|
||||
spells() {
|
||||
return this.belongsToMany( 'Spell', 'spell_school')
|
||||
},
|
||||
meta_schools() {
|
||||
return this.belongsTo( 'MetaSchool', 'meta_school_id')
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = bookshelf.model('School', School)
|
||||
21
models/spell-model.js
Normal file
21
models/spell-model.js
Normal file
@@ -0,0 +1,21 @@
|
||||
'use strict'
|
||||
const bookshelf = require('../database/bookshelf').bookshelf
|
||||
|
||||
require('./school-model')
|
||||
require('./variable-model')
|
||||
require('./ingredient-model')
|
||||
|
||||
let Spell = bookshelf.Model.extend({
|
||||
tableName: 'spell',
|
||||
schools() {
|
||||
return this.belongsToMany( 'School', 'spell_school' )
|
||||
},
|
||||
variables() {
|
||||
return this.belongsToMany( 'Variable', 'spell_variable' )
|
||||
},
|
||||
ingredients() {
|
||||
return this.belongsToMany( 'Ingredient', 'spell_ingredient' )
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = bookshelf.model('Spell', Spell)
|
||||
8
models/user-model.js
Normal file
8
models/user-model.js
Normal file
@@ -0,0 +1,8 @@
|
||||
'use strict'
|
||||
const bookshelf = require('../database/bookshelf').bookshelf
|
||||
|
||||
let User = bookshelf.Model.extend({
|
||||
tableName: 'user',
|
||||
})
|
||||
|
||||
module.exports = bookshelf.model('User', User)
|
||||
13
models/variable-model.js
Normal file
13
models/variable-model.js
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict'
|
||||
const bookshelf = require('../database/bookshelf').bookshelf
|
||||
|
||||
require('./spell-model')
|
||||
|
||||
let Variable = bookshelf.Model.extend({
|
||||
tableName: 'variable',
|
||||
spells() {
|
||||
return this.belongsToMany( 'Spell', 'spell_variable')
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = bookshelf.model('Variable', Variable)
|
||||
Reference in New Issue
Block a user