Created
January 17, 2019 17:26
-
-
Save arnaudbesnier/37f9295c7798c34883d40fabc7b142ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Liana = require('forest-express-sequelize'); | |
const models = require('../../models'); | |
const { Op } = models.Sequelize; | |
Liana.collection('guest', { | |
fields: [{ | |
field: 'googleAccessToken', | |
type: 'String', | |
get: async (guest) => { | |
const user = await guest.getUser({ | |
include: [{ | |
model: models.googleSession, | |
}], | |
}); | |
console.log('===== user', user.googleSession); | |
return user && user.googleSession && user.googleSession.accessToken; | |
}, | |
search(query, search) { | |
query.include.push({ | |
model: models.user, | |
include: [{ | |
model: models.googleSession, | |
}], | |
}); | |
query.where[Op.and][0][Op.or] | |
.push(models.sequelize.literal(`"user->googleSession"."accessToken" ILIKE '%${search}%'`)); | |
}, | |
}], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment