How to use the loopback.getModel function in loopback

To help you get started, we’ve selected a few loopback examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wj42ftns / replace-in-files / examples / after / testOptions.js View on Github external
/* eslint-disable */
var loopback = require('loopback');

var log = {};
var Log = loopback.getModel('Log');
var updated1 = Log.create(log);

console.log(updated1);

var file = {};
var File = loopback.getModel('File');
var updated2 = File.create(file);

console.log(updated2);
github EdgeVerve / loopback-connector-nodes-for-Node-RED / loopback-async-after-remote / async-after-remote.js View on Github external
var id = _node.id;
        

        // sort of an hack to return a function in case this method is called by
        // node itself.
        if (ctx && Object.keys(ctx).length === 0) {
            next(id);
        } else {

            if ( !(ctx.req && ctx.req.callContext && ctx.req.callContext.ctx) ){
                console.log("callContext not available")
                return next();
            }
            
            var Model = loopback.getModel(_modelName, _node.callContext);
            if (!utils.compareContext(_node, { Model: Model, options: { ctx: ctx.req.callContext.ctx } })) {
                return next();
            }
            
            var msg = {};

            if (ctx.Model !== undefined) {
                msg.payload = ctx.Model.definition.name + '.' + _methodName + ' triggered';
            } else {
                msg.payload = _modelName + '.' + _methodName + ' triggered';
            }
            
            msg.callContext = _node.callContext;
            // msg.next = next;
            msg.ctx = ctx;
            _node.send(msg);
github EdgeVerve / oe-cloud / common / models / framework / change-request.js View on Github external
// this check is necessary when we try from swagger usually options is
    // defined as cb and cb is undefined.
    // and programmatically also if user doesn’t send options then the
    // options
    // will be function and cb will be undefined.

    if (typeof cb === 'undefined') {
      if (typeof options === 'function') {
        // create(data, cb);
        cb = options;
        options = {};
      }
    }

    log.debug(options, 'in change-request persistUpdates() called with id[', id, '] and status [', status, ']');
    var CrModel = loopback.getModel('ChangeRequest');
    log.debug(options, 'Change Request with id [', id, ']');

    CrModel.findById(id, options, function changeRequestModelFindCb(err, crResult) {
      if (err) {
        cb(err, null);
      }
      if (crResult === null) {
        log.error(options, 'No Change Request found with id [', id, ']');
        return cb('No Change Request found with id [' + id + ']', null);
      }
      log.debug(options, 'CR instance found with status [', crResult._status, ']');

      var crInstance = crResult;
      if (status === PUBLISHED) {
        log.debug(options, 'Published the changes to the original entity');
github fullcube / loopback-component-mq / lib / index.js View on Github external
function setupRabbitMqModel(app, settings) {
  // Assign ACLs from the component configuration.
  modelDef.acls = _.get(settings, 'options.acls', [])

  // Create the model.
  const RabbitMQ = loopback.createModel(modelDef)

  // Apply model customizations.
  require('./models/rabbitmq')(RabbitMQ)

  // Register the model.
  app.model(RabbitMQ)

  return loopback.getModel('RabbitMQ')
}
github EdgeVerve / oe-cloud / test / z-z-business-validations-tests.js View on Github external
after('delete all the test transfers', function (done) {
    var testTransfer = loopback.getModel('TestTransfer', bootstrap.defaultContext);
    testTransfer.destroyAll({}, deleteContext, function (err) {
      if (err) {
        expect(err.message).to.be.equal('Cannot delete journal entry');
        return done();
      } else {
        log.debug('deleted alltest transfers');
        return done(new Error('Should not be allowed to delete journal entries!'));
      }
    });
  });
github EdgeVerve / oe-cloud / test / z-z-rest-api-actors-mixin-tests.js View on Github external
after('delete all the test accounts', function (done) {
    var testAccount = loopback.getModel('TestAccount', bootstrap.defaultContext);
    testAccount.destroyAll({}, deleteContext, function (err) {
      if (err) {
        log.error(err);
        return done(err);
      } else {
        return done();
      }
    });
  });
github EdgeVerve / oe-cloud / server / boot / 000_methodoverride.js View on Github external
const getPersonalizedModel = (modelName, ctx) => {
    let modelDefinition;
    if (modelName === 'ModelDefinition') {
      modelDefinition = loopback.getModel('ModelDefinition');
    } else {
      modelDefinition = loopback.getModel('ModelDefinition', { ctx: ctx });
    }
    const autoscopeFields = modelDefinition.definition.settings.autoscope;
    const ctxStr = util.createContextString(autoscopeFields, ctx);
    const model = app.personalizedModels[modelName] && app.personalizedModels[modelName][ctxStr] ? app.personalizedModels[modelName][ctxStr] : null;
    if (model) {
      return model;
    }
    return getDefaultPersonalizedModels(modelName, autoscopeFields, ctx);
  };
github EdgeVerve / oe-cloud / common / models / framework / base-actor-entity.js View on Github external
function getAssociatedModels(actorType, options) {
    if (!associatedModelsMap[actorType]) {
      var instanceModel = loopback.getModel(actorType, options);
      associatedModelsMap[actorType] = [];
      associatedModelsMap[actorType] = instanceModel.prototype.associatedModels.map(function (obj) {
        return loopback.getModel(obj, options);
      });
    }
    return associatedModelsMap[actorType];
  }
};
github EdgeVerve / oe-cloud / lib / event-history-manager.js View on Github external
function getEventHistoryModel() {
  if (!EventHistoryModel) {
    EventHistoryModel = loopback.getModel('EventHistory');
  }
  return EventHistoryModel;
}