Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save arnaudbesnier/37f9295c7798c34883d40fabc7b142ed to your computer and use it in GitHub Desktop.
Save arnaudbesnier/37f9295c7798c34883d40fabc7b142ed to your computer and use it in GitHub Desktop.
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