How to use the loopback/lib/globalize.f 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 harishanchu / workplace / common / models / customer.js View on Github external
);

      verifyOptions.verifyHref =
        verifyOptions.protocol +
        '://' +
        verifyOptions.host +
        displayPort +
        urlPath +
        '?' + qs.stringify({
          uid: '' + verifyOptions.user[pkName],
          redirect: verifyOptions.redirect,
        });
    }

    verifyOptions.to = verifyOptions.to || user.email;
    verifyOptions.subject = verifyOptions.subject || g.f('Thanks for Registering');
    verifyOptions.headers = verifyOptions.headers || {};

    // assert the verifyOptions params that might have been badly defined
    assertVerifyOptions(verifyOptions);

    // argument "options" is passed depending on verifyOptions.generateVerificationToken function requirements
    var tokenGenerator = verifyOptions.generateVerificationToken;
    if (tokenGenerator.length == 3) {
      tokenGenerator(user, options, addTokenToUserAndSave);
    } else {
      tokenGenerator(user, addTokenToUserAndSave);
    }

    function addTokenToUserAndSave(err, token) {
      if (err) return cb(err);
      user.verificationToken = token;
github harishanchu / workplace / common / models / customer.js View on Github external
function sendEmail(user) {
      verifyOptions.verifyHref +=
        verifyOptions.verifyHref.indexOf('?') === -1 ? '?' : '&';
      verifyOptions.verifyHref += 'token=' + user.verificationToken;

      verifyOptions.verificationToken = user.verificationToken;
      verifyOptions.text = verifyOptions.text || g.f('Please verify your email by opening ' +
        'this link in a web browser:\n\t%s', verifyOptions.verifyHref);
      verifyOptions.text = verifyOptions.text.replace(/\{href\}/g, verifyOptions.verifyHref);

      // argument "options" is passed depending on templateFn function requirements
      var templateFn = verifyOptions.templateFn;
      if (templateFn.length == 3) {
        templateFn(verifyOptions, options, setHtmlContentAndSend);
      } else {
        templateFn(verifyOptions, setHtmlContentAndSend);
      }

      function setHtmlContentAndSend(err, html) {
        if (err) return cb(err);

        verifyOptions.html = html;
github harishanchu / workplace / common / models / customer.js View on Github external
.then(function (data) {
        if (data.length) {
          let err = new Error(g.f('Task is associated with time sheets, hence cannot be deleted.'));
          err.statusCode = 400;
          err.code = 'TASK_ASSOCIATED_WITH_TIMESHEETS';

          next(err);
        } else {
          next();
        }
      })
      .catch(next);
github harishanchu / workplace / common / models / project.js View on Github external
async function beforeDelete(ctx, next) {
    let ids = [].concat(ctx.args.id);

    let projects = await Project.find({where: {id: {inq: ids}}, fields: {id: true}, include:"tasks"});

    if(!projects.every(project => {
        return !project.tasks().length;
      })) {
      let err = new Error(g.f('Projects are associated with tasks, hence cannot be deleted.'));
      err.statusCode = 400;
      err.code = 'PROJECT_ASSOCIATED_WITH_TASKS';

      throw err;
    }

    return null;
  }
github harishanchu / workplace / common / models / customer.js View on Github external
} else {
        if (user && user.verificationToken === token) {
          user.updateAttributes({verificationToken: null, emailVerified: true}, function (err) {
            if (err) {
              fn(err);
            } else {
              fn();
            }
          });
        } else {
          if (user) {
            err = new Error(g.f('Invalid token: %s', token));
            err.statusCode = 400;
            err.code = 'INVALID_TOKEN';
          } else {
            err = new Error(g.f('User not found: %s', uid));
            err.statusCode = 404;
            err.code = 'USER_NOT_FOUND';
          }
          fn(err);
        }
      }
    });
    return fn.promise;
github harishanchu / workplace / common / models / customer.js View on Github external
Customer.findById(userId, function (err, user) {
      if (err) {
        return callback(err);
      } else if (!user) {
        let err = new Error(g.f('User not found'));
        err.statusCode = 400;
        err.code = 'USER_NOT_FOUND';

        return callback(err);
      } else {
        const Role = Customer.app.models.Role;
        const RoleMapping = Customer.app.models.RoleMapping;

        Role.upsertWithWhere(
          {
            name: roleName
          },
          {
            name: roleName
          },
          function (err, role) {
github harishanchu / workplace / util / utilities.js View on Github external
handleError: (error, cb) => {
    if (error instanceof Error) {
      cb(error);
    } else {
      let err = new Error(g.f(error.message));
      err.code = error.message.toUpperCase().replace(/ /g, "_");
      err.statusCode = error.code;
      err.status = error.code;
      cb(err);
    }
  },
github harishanchu / workplace / common / models / client.js View on Github external
async function beforeDelete(ctx, next) {
    let ids = [].concat(ctx.args.id);

    let clients = await Client.find({where: {id: {inq: ids}}, fields: {id: true}, include:"projects"});

    if(!clients.every(client => {
        return !client.projects().length;
      })) {
      let err = new Error(g.f('Clients are associated with projects, hence cannot be deleted.'));
      err.statusCode = 400;
      err.code = 'CLIENT_ASSOCIATED_WITH_PROJECTS';

      throw err;
    }

    return null;
  }
github harishanchu / workplace / common / models / customer.js View on Github external
this.findById(uid, function (err, user) {
      if (err) {
        fn(err);
      } else {
        if (user && user.verificationToken === token) {
          user.updateAttributes({verificationToken: null, emailVerified: true}, function (err) {
            if (err) {
              fn(err);
            } else {
              fn();
            }
          });
        } else {
          if (user) {
            err = new Error(g.f('Invalid token: %s', token));
            err.statusCode = 400;
            err.code = 'INVALID_TOKEN';
          } else {
            err = new Error(g.f('User not found: %s', uid));
            err.statusCode = 404;
            err.code = 'USER_NOT_FOUND';
          }
          fn(err);
        }
      }
    });
    return fn.promise;