[Op.like]: `%${xss(keyword)}%` };
const getHashTags = id => { try { return HashTag.findAll({ where: { name: { [Op.like]: `%${id}%` } }, limit: 10, }); } catch (err) { throw new Error(errorName.HASHTAGS_QUERY_ERROR); } }
async index(req, res) { const { result } = req.query; const resultado = await Post.findAll({ where: { slug: { [Op.like]: '%' + result + '%', }, }, }); return res.json(resultado); }
asyncHandler(async (req, res) => { const { title } = req.query const tasks = await Task.findAll({where:{ FKUser: req.user.Id, title: { [Op.like]: `%${title ? title:'%'}%` }, FKStatus: global.STATUS.ACTIVE }}) res.status(200).send(tasks) })
/** * Builds query to get records where the value of the field contains the value. * Setting caseSensitive to true will cause the regex to be case insensitive */ const buildContainsQuery = function({ field, value, caseSensitive = false }) { // TODO: contains is not working as expected, like is for string matching - doublecheck this if (caseSensitive) { return { name: field, value: { [Op.like]: value } }; } else { return { name: field, value: { [Op.iLike]: value } }; } }
startsWith(searchName, field, value, w) { return w[field.target.field] = { [Op.like]: value+'%' }; }
router.post('/', async function (ctx, next) { let get = ctx.request.query; let post = ctx.request.body; let whereJson = { name: { [Op.like]: '%' + post.name + '%' } }; let data = await dao.list(whereJson); ctx.body = { code: 0, msg: '', data: data }; });
/** * Get the latest date on a given username. (Player info and latest snapshot) */ async function getDetails(username) { if (!username) { throw new BadRequestError('Invalid username.'); } const player = await Player.findOne({ where: { username: { [Op.like]: `${standardize(username)}` } } }); if (!player) { throw new BadRequestError(`${username} is not being tracked yet.`); } const latestSnapshot = await snapshotService.findLatest(player.id); const combatLevel = getCombatLevel(latestSnapshot); return { ...player.toJSON(), latestSnapshot: snapshotService.format(latestSnapshot), combatLevel }; }
userSearchQuery(searchName, field, value, w) { return w[Op.or] = { email: { [Op.eq]: value }, displayName: { [Op.like]: value+'%' }, username: { [Op.eq]: value } }; }
/** * Search for players with a (partially) matching username. */ async function search(username: string): Promise<Player[]> { if (!username) { throw new BadRequestError('Invalid username.'); } const players = await Player.findAll({ where: { username: { [Op.like]: `${standardize(username)}%` } }, limit: 20 }); return players; }
router.post('/', async function (ctx, next) { let get = ctx.request.query; let post = ctx.request.body; let whereJson = { title: { [Op.like]: '%' + post.title + '%' } }; let data = await dao.list(whereJson); ctx.body = { code: 0, msg: '', data: data }; });
router.post('/', async function (ctx, next) { let get = ctx.request.query; let post = ctx.request.body; let whereJson = { content: { [Op.like]: '%' + post.content + '%' } }; let data = await dao.list(whereJson); ctx.body = { code: 0 , msg: '', data: data }; });
contains(searchName, field, value, w) { return w[field.target.field] = { [Op.like]: '%'+value+'%' }; }
/** * Builds query to get records where the value of the field contains the value. * Setting caseSensitive to true will cause the regex to be case insensitive */ const buildContainsQuery = function({ field, value, caseSensitive = false }) { // TODO: contains is not working as expected, like is for string matching - doublecheck this if (caseSensitive) { return { name: field, value: { [Op.like]: value } }; } else { return { name: field, value: { [Op.iLike]: value } }; } }