- Added getspells from variables, ingredients, and schools
This commit is contained in:
@@ -7,10 +7,10 @@ require('./meta-school-model')
|
|||||||
let School = bookshelf.Model.extend({
|
let School = bookshelf.Model.extend({
|
||||||
tableName: 'school',
|
tableName: 'school',
|
||||||
spells() {
|
spells() {
|
||||||
return this.belongsToMany( 'Spell', 'spell_school')
|
return this.belongsToMany( 'Spell', 'spell_school' )
|
||||||
},
|
},
|
||||||
meta_schools() {
|
meta_schools() {
|
||||||
return this.belongsTo( 'MetaSchool', 'meta_school_id')
|
return this.belongsTo( 'MetaSchool', 'meta_school_id' )
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,21 @@ class IngredientRepository {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSpellsFromOne(id) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
model.forge()
|
||||||
|
.where({ 'id' : id })
|
||||||
|
.fetch({ withRelated: ['spells']})
|
||||||
|
.then(v => {
|
||||||
|
resolve(v.toJSON({ omitPivot: true }))
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
reject(new HttpError(500, "Couldn't get ingredient"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
addOne(igr) {
|
addOne(igr) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Checks if body exists and if the model fits, and throws errors if it doesn't
|
// Checks if body exists and if the model fits, and throws errors if it doesn't
|
||||||
|
|||||||
@@ -49,6 +49,21 @@ class SchoolRepository {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSpellsFromOne(id) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
model.forge()
|
||||||
|
.where({ 'id' : id })
|
||||||
|
.fetch({ withRelated: ['spells', 'meta_schools']})
|
||||||
|
.then(v => {
|
||||||
|
resolve(v.toJSON({ omitPivot: true }))
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
reject(new HttpError(500, "Couldn't get school"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
addOne(s) {
|
addOne(s) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Checks if body exists and if the model fits, and throws errors if it doesn't
|
// Checks if body exists and if the model fits, and throws errors if it doesn't
|
||||||
|
|||||||
@@ -49,6 +49,21 @@ class VariableRepository {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSpellsFromOne(id) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
model.forge()
|
||||||
|
.where({ 'id' : id })
|
||||||
|
.fetch({ withRelated: ['spells']})
|
||||||
|
.then(v => {
|
||||||
|
resolve(v.toJSON({ omitPivot: true }))
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
reject(new HttpError(500, "Couldn't get variable"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
addOne(vr) {
|
addOne(vr) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Checks if body exists and if the model fits, and throws errors if it doesn't
|
// Checks if body exists and if the model fits, and throws errors if it doesn't
|
||||||
|
|||||||
@@ -68,6 +68,31 @@ router.get('/:id/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// GET SPELLS FROM ONE ------------------
|
||||||
|
const getSpellsFromOne = (id) => {
|
||||||
|
return Ingredients.getSpellsFromOne(id)
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
throw err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
router.get('/:id/spells', async (req, res) => {
|
||||||
|
getSpellsFromOne(req.params.id)
|
||||||
|
.then(v => {
|
||||||
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
|
res.end(JSON.stringify(v))
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
res.status(err.code).send(JSON.stringify(
|
||||||
|
{
|
||||||
|
"error": err.message,
|
||||||
|
"code": err.code
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
const addIngredient = (igr) => {
|
const addIngredient = (igr) => {
|
||||||
return Ingredients.addOne(igr)
|
return Ingredients.addOne(igr)
|
||||||
|
|||||||
@@ -68,6 +68,31 @@ router.get('/:id/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// GET SPELLS FROM ONE ------------------
|
||||||
|
const getSpellsFromOne = (id) => {
|
||||||
|
return Schools.getSpellsFromOne(id)
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
throw err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
router.get('/:id/spells', async (req, res) => {
|
||||||
|
getSpellsFromOne(req.params.id)
|
||||||
|
.then(v => {
|
||||||
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
|
res.end(JSON.stringify(v))
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
res.status(err.code).send(JSON.stringify(
|
||||||
|
{
|
||||||
|
"error": err.message,
|
||||||
|
"code": err.code
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
const addSchool = (s) => {
|
const addSchool = (s) => {
|
||||||
return Schools.addOne(s)
|
return Schools.addOne(s)
|
||||||
|
|||||||
@@ -68,6 +68,31 @@ router.get('/:id/', async (req, res) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
// GET SPELLS FROM ONE ------------------
|
||||||
|
const getSpellsFromOne = (id) => {
|
||||||
|
return Variables.getSpellsFromOne(id)
|
||||||
|
.catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
throw err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
router.get('/:id/spells', async (req, res) => {
|
||||||
|
getSpellsFromOne(req.params.id)
|
||||||
|
.then(v => {
|
||||||
|
res.setHeader('Content-Type', 'application/json;charset=utf-8')
|
||||||
|
res.end(JSON.stringify(v))
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
res.status(err.code).send(JSON.stringify(
|
||||||
|
{
|
||||||
|
"error": err.message,
|
||||||
|
"code": err.code
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
// CREATE ONE ------------------
|
// CREATE ONE ------------------
|
||||||
const addVariable = (vr) => {
|
const addVariable = (vr) => {
|
||||||
return Variables.addOne(vr)
|
return Variables.addOne(vr)
|
||||||
|
|||||||
Reference in New Issue
Block a user