Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Copyright IBM Corp. 2013,2018. All Rights Reserved.
// Node module: loopback-connector-mssql
// This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT
'use strict';
const jdb = require('loopback-datasource-juggler');
const commonTest = jdb.test;
require('./init');
/* global getDataSource */
const schema = getDataSource();
// run the tests exposed by jugglingdb
commonTest(module.exports, schema);
// skip the order test from jugglingdb, it wasn't working right
commonTest.skip('should handle ORDER clause');
// re-implement the order test as pretty much the same thing, but run an automigration beforehand
commonTest.it('should automigrate', function(test) {
schema.automigrate(function(err) {
test.ifError(err);
function getProgramId(context, cb) {
cb = cb || createPromiseCallback();
// If we are accessing an existing model, get the program id from the existing data.
if (context.modelId) {
debug(`fetching program id for existing model with id ${context.modelId}`);
context.model.findById(context.modelId).then(modelInstance => cb(null, modelInstance.programId));
}
// If we are creating a new model, get the programId from the incoming data.
else if (context.remotingContext.args.data.programId) {
debug(`fetching program id using incoming programId ${context.remotingContext.args.data.programId}`);
process.nextTick(() => cb(null, context.remotingContext.args.data.programId));
}
// Otherwise, return null
else {
debug('teamMember unable to determine program context');
process.nextTick(cb);
}
'use strict';
var loopback = require('loopback');
var boot = require('loopback-boot');
const {Memory} = require('loopback-datasource-juggler/lib/connectors/memory');
Memory.prototype.create = function create(model, data, options, callback) {
const err = new Error('test');
err.statusCode = 400;
err.details = {reason: 'testing'};
callback(err);
};
var app = module.exports = loopback();
app.start = function() {
// start the web server
return app.listen(function() {
app.emit('started');
var baseUrl = app.get('url').replace(/\/$/, '');
console.log('Web server listening at: %s', baseUrl);
if (app.get('loopback-component-explorer')) {
var explorerPath = app.get('loopback-component-explorer').mountPath;
// Author : Atul
var loopback = require('loopback');
var boot = require('loopback-boot');
var wrapper = require('./loopback-datasource-juggler-wrapper');
var path = require('path');
var mergeUtil = require('./merge-util');
var debug = require('debug')('oe-cloud:oe-cloud');
var async = require('async');
var jutil = require('loopback-datasource-juggler/lib/jutil');
var observerMixin = require('loopback-datasource-juggler/lib/observer');
wrapper.initWrapper();
var app = loopback();
jutil.mixin(app, observerMixin);
var mixinUtil = require('./mixin-util')(app);
function getRootFolder() {
var rootFolder;
try {
rootFolder = path.dirname(module.parent.parent.filename);
} catch (e) {
console.error('**** ERROR : Not able to get root folder from parent module. ****', e);
}
if (!rootFolder || process.env.FIXEDSERVER) {
try {
rootFolder = process.cwd() + '/server';
module.exports = function (Job) {
// Attach job submission to Kafka
if ('queue' in config && config.queue === 'kafka') {
// var options = {
// connectionString: 'localhost:2181/'
// };
var dataSource = new DataSource('kafka', options);
Job.attachTo(dataSource);
}
Job.observe('before save', (ctx, next) => {
// email job initiator should always be the person running the job request
// therefore override this field both for users and functional accounts
if (ctx.instance) {
ctx.instance.emailJobInitiator = ctx.options.currentUserEmail;
if (ctx.isNewInstance) {
ctx.instance.jobStatusMessage = "jobSubmitted"
}
}
next()
});
Job.observe('after save', (ctx, next) => {
if (options === undefined && cb === undefined) {
if (typeof data === 'function') {
// UPSERt(cb)
cb = data;
data = {};
}
} else if (cb === undefined) {
if (typeof options === 'function') {
// upsert(data, cb)
cb = options;
options = {};
}
}
cb = cb || utils.createPromiseCallback();
data = data || {};
options = options || {};
assert(typeof data === 'object', 'The data argument must be an object');
assert(typeof options === 'object', 'The options argument must be an object');
assert(typeof cb === 'function', 'The cb argument must be a function');
if (Array.isArray(data)) {
cb(new Error('updateOrCreate does not support bulk mode or any array input'));
return cb.promise;
}
var self = this;
var Model = this;
var id = oeutils.getIdValue(this, data);
Role.registerResolver(accessGroup, (role, context, cb) => {
cb = cb || createPromiseCallback()
const modelClass = context.model
const { modelId } = context
const userId = context.getUserId()
const roleName = this.extractRoleName(role)
const GroupAccess = this.app.models[this.options.groupAccessModel]
const scope = { }
debug(`Role resolver for ${role}: evaluate ${modelClass.modelName} with id: ${modelId} for user: ${userId}`)
// No userId is present
if (!userId) {
process.nextTick(() => {
debug('Deny access for anonymous user')
cb(null, false)
})
return cb.promise
getTargetGroupId(context, cb) {
cb = cb || createPromiseCallback()
debug('getTargetGroupId context.remotingContext.args: %o', context.remotingContext.args)
let groupId = null
// Get the target group id from the incoming data.
if (_get(context, `remotingContext.args.data[${this.options.foreignKey}]`)) {
debug(`determined target group id ${groupId} from incoming data`)
groupId = context.remotingContext.args.data[this.options.foreignKey]
}
// Otherwise, return null.
else {
debug('unable to determine target group context')
}
process.nextTick(() => cb(null, groupId))
Model.itemsWithChangedProperties = function itemsWithChangedProperties(conditions, newVals, properties, cb) {
debug('itemsWithChangedProperties: Looking for items with changed properties...')
debug('itemsWithChangedProperties: conditions is: %o', conditions)
debug('itemsWithChangedProperties: newVals is: %o', newVals)
debug('itemsWithChangedProperties: properties is 1 : %o', properties)
cb = cb || utils.createPromiseCallback()
conditions = conditions || {}
newVals = typeof newVals.toJSON === 'function' ? newVals.toJSON() : newVals || {}
properties = properties || {}
const filterFields = [
Model.getIdName(),
]
// Build up a list of property conditions to include in the query.
let propertyConditions = { or: [] }
_.forEach(newVals, (value, key) => {
if (_.includes(properties, key)) {
const fieldFilter = {}
}
});
andParams.push({
and: manualAnd
});
}
finalQuery = {
where: {
and: andParams
}
};
}
// Merging the query formed with the existing query if any.
mergeQuery(ctx.query, finalQuery);
log.debug(ctx.options, 'Final formed query', JSON.stringify(ctx.query));
next();
}