fix: objection.js 2.0 compat fixes

This commit is contained in:
NGPixel 2020-01-25 23:29:46 -05:00
parent 3e991fa590
commit 8f5265622f
4 changed files with 8 additions and 12 deletions

View File

@ -61,11 +61,9 @@ module.exports = {
'createdAt', 'createdAt',
'updatedAt' 'updatedAt'
]) ])
.eagerAlgorithm(WIKI.models.Objection.Model.JoinEagerAlgorithm) .withGraphJoined('tags')
.eager('tags(selectTags)', { .modifyGraph('tags', builder => {
selectTags: builder => { builder.select('tag')
builder.select('tag')
}
}) })
.modify(queryBuilder => { .modify(queryBuilder => {
if (args.limit) { if (args.limit) {

View File

@ -704,11 +704,9 @@ module.exports = class Page extends Model {
]) ])
.joinRelated('author') .joinRelated('author')
.joinRelated('creator') .joinRelated('creator')
.eagerAlgorithm(Model.JoinEagerAlgorithm) .withGraphJoined('tags')
.eager('tags(selectTags)', { .modifyGraph('tags', builder => {
selectTags: builder => { builder.select('tag', 'title')
builder.select('tag', 'title')
}
}) })
.where(queryModeID ? { .where(queryModeID ? {
'pages.id': opts 'pages.id': opts

View File

@ -56,7 +56,7 @@ module.exports = class UserKey extends Model {
} }
static async validateToken ({ kind, token }, context) { static async validateToken ({ kind, token }, context) {
const res = await WIKI.models.userKeys.query().findOne({ kind, token }).eager('user') const res = await WIKI.models.userKeys.query().findOne({ kind, token }).withGraphJoined('user')
if (res) { if (res) {
await WIKI.models.userKeys.query().deleteById(res.id) await WIKI.models.userKeys.query().deleteById(res.id)
if (moment.utc().isAfter(moment.utc(res.validUntil))) { if (moment.utc().isAfter(moment.utc(res.validUntil))) {

View File

@ -705,7 +705,7 @@ module.exports = class User extends Model {
} }
static async getGuestUser () { static async getGuestUser () {
const user = await WIKI.models.users.query().findById(2).eager('groups').modifyEager('groups', builder => { const user = await WIKI.models.users.query().findById(2).withGraphJoined('groups').modifyGraph('groups', builder => {
builder.select('groups.id', 'permissions') builder.select('groups.id', 'permissions')
}) })
if (!user) { if (!user) {