Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
shortcutController.listAll = function (req, res, next) {
var csid = req.params.csid || '';
if (!csid) return res.json({code: 9000, msg: 'csid_null'});
var condition = {
[Op.or]: [
getCondition(''),
getCondition(csid)
]
};
var attributes = ['id', 'type', 'shortcut', 'msg'];
Shortcut.listAll(attributes, condition, function (err, data) {
if (err) return next(err);
// remove repeat shortcut
var msg = _.uniqBy(_.orderBy(data, ['type'], ['desc']), 'shortcut');
// remove property:type
msg = _.map(msg, function (item) {
return _.omit(item, 'type');
});
const orBody = {};
Object.keys(body)
.filter((what) => !what.startsWith('and:'))
.forEach((k) => (orBody[k] = body[k]));
const orWhereClause = this.createWhereClause(orBody);
let orderBy;
if (body.orderBy) {
orderBy = [body.orderBy.split(':')];
}
const where = removeEmptyObjKeys(
{ ...andWhereClause, [Op.or]: orWhereClause },
true
);
if (Object.keys(where[Op.or]).length === 0) {
delete where[Op.or];
}
const { rows: transactions, count } = await this.TXModel.findAndCountAll({
limit: body.limit || 100,
offset: body.offset || 0,
order: orderBy,
raw: true,
where,
});
// Reattach transactions asset
await this.txLogic.attachAssets(transactions);
return {
count,
transactions: transactions.map((t) =>
this.TXModel.toTransportTransaction(t)
static async uploadUserAvatar (ctx) {
try {
await upload('avatarImg').single('file')(ctx)
if (ctx.req.file) {
let destination = ctx.req.file.destination.split('static')[1]
let filename = ctx.req.file.filename
let origin = ctx.request.header.origin
let { user = '' } = ctx.request
let userRoleAll = await models.user_role.findAll({
where: {
user_role_id: {
[Op.or]: user.user_role_ids.split(',')
},
user_role_type: 1 // 用户角色类型1是默认角色
}
})
let userAuthorityIds = ''
userRoleAll.map(roleItem => {
userAuthorityIds += roleItem.user_authority_ids + ','
})
let message = ''
if (~userAuthorityIds.indexOf(config.USER.dfUserAvatarNoReviewId)) {
message = '上传用户头像成功'
await models.user.update(
{
avatar: `${origin}${destination}/${filename}`
},
{
let query = {
category_id: categoryId === 0 ? undefined : categoryId,
status: statusId === 0 ? undefined : statusId,
public: publicId === 0 ? undefined : publicId,
star: starId === 0 ? undefined : starId
}
// 忽略值为空的key
let target = omitBy(query, isUndefined)
let opIn = ids.length ? {
id: {
[Op.in]: ids
}
} : {}
let like = search ? {
[Op.or]: [
{
title: {
[Op.like]: `${search}%`,
}
},
{
content: {
[Op.like]: `${search}%`,
}
}
]
} : {}
// step3: 构建查询条件
const where = {
...target,
// Independently of the balance of the external source, the owner of the payment method
// may have set up a monthlyLimitPerMember or an initialBalance
if (!this.initialBalance && (!this.monthlyLimitPerMember || (user && user.isAdmin(this.CollectiveId)))) {
return { amount: balanceAmount, currency: this.currency };
}
let limit = Infinity; // no no, no no no no, no no no no limit!
const query = {
where: { type: TransactionTypes.DEBIT },
include: [
{
model: models.PaymentMethod,
require: true,
attributes: [],
where: { [Op.or]: { id: this.id, SourcePaymentMethodId: this.id } },
},
],
};
if (this.monthlyLimitPerMember) {
limit = this.monthlyLimitPerMember;
const d = new Date();
const firstOfTheMonth = new Date(d.getFullYear(), d.getMonth(), 1);
query.where.createdAt = { [Op.gte]: firstOfTheMonth };
query.where.CreatedByUserId = user.id;
}
if (this.initialBalance) {
limit = this.initialBalance > limit ? limit : this.initialBalance;
}
if (access === false) {
ctx.body = {
isOk: false,
errMsg: Consts.COMMON_MSGS.ACCESS_DENY
}
return
}
}
// tslint:disable-next-line:no-null-keyword
if (user) Object.assign(where, { ownerId: user, organizationId: null })
if (organization) Object.assign(where, { organizationId: organization })
if (name) {
Object.assign(where, {
[Op.or]: [
{ name: { [Op.like]: `%${name}%` } },
{ id: name } // name => id
]
})
}
let total = await Repository.count({
where,
include: [
QueryInclude.Creator,
QueryInclude.Owner,
QueryInclude.Locker,
],
} as any)
let pagination = new Pagination(total, ctx.query.cursor || 1, ctx.query.limit || 100)
let repositories = await Repository.findAll({
where,
User.findByEmailOrPaypalEmail = email => {
return User.findOne({
where: {
[Op.or]: {
email,
paypalEmail: email,
},
},
});
};
let { page, perPageNum } = queryOptions;
page = +page;
perPageNum = +perPageNum;
const wastebasketNo = await getWastebasketCategoryNo(userNo);
const query = getQueryByOptions({
userNo,
perPageNum,
page,
sort,
wastebasketNo,
});
query.mailTemplateFilter = {
[Op.or]: [
{ subject: { [Op.substring]: searchWord } },
{ text: { [Op.substring]: searchWord } },
],
};
const pagingAndMails = await getPagingInfoAndMails({ page, perPageNum, query });
return pagingAndMails;
};
findAllByWallet (wallet, paginator) {
return this.findAll({
...{
[Op.or]: [{
senderPublicKey: wallet.publicKey
}, {
recipientId: wallet.address
}]
},
...paginator
})
}