Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var models = require('../../models/models.js');
var fs = require('fs');
var uuid = require('uuid');
var _ = require('lodash');
var config = require('../../config');
var Sequelize = require('sequelize');
const Op = Sequelize.Op;
var debug = require('debug')('idm:web-application_controller');
var gravatar = require('gravatar');
var Jimp = require("jimp");
var image = require ('../../lib/image.js');
var crypto = require('crypto');
// Autoload info if path include applicationId
exports.load_application = function(req, res, next, applicationId) {
debug("--> load_application");
if (applicationId === 'idm_admin_app') {
// Reponse with message
var response = {text: ' Application doesn`t exist.', type: 'danger'};
import {
ApolloError,
AuthenticationError,
ForbiddenError,
} from 'apollo-server';
import Sequelize from 'sequelize';
import { MessageModel, UserModel, GroupModel, ChatModel } from './connectors';
const Op = Sequelize.Op;
// reusable function to check for a user with context
function getAuthenticatedUser(ctx) {
// return UserModel.findOne({ where: { id: 1 } });
return ctx.user.then(user => {
if (!user) {
throw new AuthenticationError('Unauthenticated');
}
return user;
});
}
async function isUserAuth(userId, ctx) {
const authUser = await getAuthenticatedUser(ctx);
if (authUser.id !== userId) {
async function addLockup(userId, amount, data = {}) {
const user = await hasBalance(userId, amount)
const unconfirmedLockups = await Lockup.findAll({
where: {
userId: user.id,
confirmed: null, // Unconfirmed
created_at: {
[Sequelize.Op.gte]: moment
.utc()
.subtract(lockupConfirmationTimeout, 'minutes')
}
}
})
if (unconfirmedLockups.length > 0) {
throw new ReferenceError(
'Unconfirmed lockups exist, please confirm or wait until expiry'
)
}
let lockup
const txn = await sequelize.transaction()
try {
lockup = await Lockup.create({
$strictLeft: Op.strictLeft,
$strictRight: Op.strictRight,
$noExtendRight: Op.noExtendRight,
$noExtendLeft: Op.noExtendLeft,
$and: Op.and,
$or: Op.or,
$any: Op.any,
$all: Op.all,
$values: Op.values,
$col: Op.col
};
const sequelize = new Sequelize(db, config.username, config.password, options);
// object for exports
const database = {
Op: Sequelize.Op,
Sequelize: Sequelize,
sequelize: sequelize,
sync: sequelize.sync.bind(sequelize)
};
// squel & functions: query, queryOne
Object.assign(database, sql(sequelize, options.dialect));
// init models
config.modelPath && Object.assign(database, models(sequelize, config.modelPath));
databases[name] = database;
});
import Sequelize from 'sequelize'
import shapeThumbnail from '../shapeThumbnail'
const Op = Sequelize.Op
export default function (Postmeta, Post, settings) {
return function(postId) {
return Postmeta.findOne({
where: {
post_id: postId,
meta_key: '_thumbnail_id'
}
}).then(res => {
if (res) {
const {amazonS3} = settings.publicSettings
const metaKeys = amazonS3 ? ['amazonS3_info'] : ['_wp_attached_file']
metaKeys.push('_wp_attachment_metadata')
return Post.findOne({
where: {
const Op = require('sequelize').Op
const Transaction = require('../../../models/transaction')
const buildFilterQuery = require('../utils/filter-query')
const { TRANSACTION_TYPES } = require('../../../core/constants')
module.exports = class TransactionsRepository {
constructor (db) {
this.db = db
}
findAll (params) {
let whereStatement = {}
let orderBy = []
const filter = ['type', 'senderPublicKey', 'recipientId', 'amount', 'fee', 'blockId']
for (const elem of filter) {
if (params[elem]) { whereStatement[elem] = params[elem] }
DBImplementation.prototype.searchTracks = function(searchValue) {
var self = this;
if (!searchValue) {
return libQ.reject(new Error('DBImplementation.searchTracks: search value is empty'));
}
return this.library.searchTracks({
where: {
[Sequelize.Op.or]: {
title: {[Sequelize.Op.substring]: searchValue}
}
},
order: ['tracknumber'],
raw: true
}).then(function(trackArr) {
return trackArr.map(function(track) {
return self.track2SearchResult(track);
});
});
};
'use strict';
const Op = require('sequelize').Op;
module.exports = app => {
const { STRING, INTEGER, DATE } = app.Sequelize;
const App = app.model.define(
'app',
{
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
code: { type: STRING(255), unique: 'code' },
name: STRING(255),
create_time: DATE,
update_time: DATE,
},
{
timestamps: true,
createdAt: 'create_time',
async getBookByKeyword (q) {
const book = await Book.findOne({
where: {
title: {
[Sequelize.Op.like]: `%${q}%`
},
delete_time: null
}
});
return book;
}
const Category = require('../model/category')
const Op = require('sequelize').Op
const listAll = async (ctx) => {
const data = await Category.findAll()
ctx.body = {
code: 1000,
data
}
}
const list = async (ctx) => {
const query = ctx.query
const where = {
name: {
[Op.like]: `%${query.name}%`
}
}