Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async find(message, args, authorModel) {
const item = await Item.findOne({
include: [{
as: 'holders',
joinTableAttributes: ['count'],
model: User,
required: false,
where: { id: message.author.id }
}],
where: where(fn('lower', col('name')), args.join(' ').toLowerCase())
});
if (!item) return message.reply('could not find an item with that name!');
const embed = RichEmbed.common(message, authorModel)
.setAuthor(`Information about the ${item.type.toLowerCase()} "${item.name}"`, this.client.displayAvatarURL)
.setThumbnail(message.guild.iconURL)
.setDescription(item.description || '\u200b');
for (let [title, value] of Object.entries(item.dataValues)) {
// Don't show price for non buyable items
if ((title === 'price' && value === null)
// Already in the description of the embed.
|| title === 'description') continue;
if (title === 'holders') {
if (item.holders.length) {
const latest5 = await this.keywordEntryRepository.findAll({
attributes: {
exclude: ['entryId', 'createdAt']
},
group: ['keywordId'],
order: [[fn('max', col('createdAt')), 'DESC']],
limit: 5
} as IFindOptions);
// Find the 5 keywords with the most links
const biggest5 = await this.keywordEntryRepository.findAll({
attributes: {
exclude: ['entryId', 'createdAt']
},
group: 'keywordId',
order: [[fn('count', 'entryId'), 'DESC']],
limit: 5,
where: {
keywordId: {
// Filter out keywords that already exist in the latest5
[Op.notIn]: latest5.map(keywordEntry => keywordEntry.keywordId)
}
}
} as IFindOptions);
// Load the keyword table data
const result = await Promise.all(
[...latest5, ...biggest5].map(keywordEntry => this.findById(keywordEntry.keywordId))
);
return result;
}
execute: ([ a, b ]) =>
types.fn('eq', numeric(a), numeric(b))
}
return co(function* () {
let historyModel = yield new HistoryModel();
let data = yield historyModel.findOne({
attributes: [
[sequelize.fn('SUM', sequelize.col('count')), 'num']
]
});
return data.dataValues.num;
}).catch(err => {
debug(err);
execute: ([ f ]) => types.fn('min', numeric(f))
}
export const lte = (a, b) =>
types.fn('lte', numeric(a), numeric(b))
export const eq = (a, b) =>
export const remainder = (a, b) =>
types.fn('mod', numeric(a), numeric(b))
const resetSequence = async(db, modelName, col) => {
const maxFetch = await db[modelName].findAll({attributes: [[Sequelize.fn("max", Sequelize.col(col)), "max"]], raw: true});
const max = maxFetch ? maxFetch[0].max : null;
if (max && typeof max === "number") {
const query = `SELECT setval(pg_get_serial_sequence('canon_cms_${modelName}', '${col}'), ${max})`;
return db.query(query);
}
else {
return null;
}
};
export const count = (f=types.literal('*')) => types.fn('count', f)
export const extract = (part, f) => {
const p = parts[part && part.raw]
if (!p) throw new BadRequestError('extract() expects a valid part argument')
return types.fn('date_part', p, f)
}
//export const format = (fmt, f) => types.fn('to_char', f, fmt)