Example #1
0
 db.check_token_and_permission("reset_any_password", token, function (err, return_value, client) {
   if (!return_value) {                                            //false (no token)
     res.status(errors.bad_request()).send('Token missing or invalid');
   } else if (return_value.reset_any_password === false) {          //false (no permission)
     res.status(errors.no_permission).send('No permission');
   } else if (return_value.reset_any_password === true) {           //true
     console.log("return value: " + JSON.stringify(return_value));
     if (return_value.expiry_timestamp < Date.now()) {
       res.status(errors.access_token_expired()).send('Access token expired');
     } else {
       params.chief_complain_id = util.random_string(consts.id_random_string_length());
       var name = body.name;
       if (body) {
         params.name = name;
       }
       var sql_query = sql.insert(default_table, params);
       console.log(sql_query.toString());
       client.query(sql_query.toParams().text, sql_query.toParams().values, function (err, result) {
         if (err) {
           res.send('error fetching client from pool 3');
           sent = true;
           return console.error('error fetching client from pool', err);
         } else {
           q.save_sql_query(sql_query.toString());
           res.json(result.rows);
         }
       });
     }
   }
 });
Example #2
0
 return parameters.map(function (obj) {
     return sql.insert('function_group_parameters', {
         rpc_name: obj.rpc_name,
         parameter: obj.parameter,
         function_group_id: obj.function_group_id
     })
     .toString();
 });
Example #3
0
 return hmiLevels.map(function (obj) {
     return sql.insert('function_group_hmi_levels', {
         permission_name: obj.permission_name,
         hmi_level: obj.hmi_level,
         function_group_id: obj.function_group_id
     })
     .toString();
 });
CastRepository.prototype.create = function (filmId, actorId, callback) {
  var me = this;

  var query = sql.insert('casts', {
    film_id: filmId,
    actor_id: actorId,
    created_at: moment.utc().toISOString()
  }).returning('id', 'film_id', 'actor_id', 'created_at');

  me.db.queryOne(query, callback);
};
SeasonRepository.prototype.create = function (leagueId, startDate, endDate, callback) {
  var me = this;

  var query = sql.insert('seasons', {
    league_id: leagueId,
    starts_at: startDate.toISOString(),
    ends_at: endDate.toISOString(),
    created_at: moment().utc().toISOString()
  }).returning('id', 'league_id', 'starts_at', 'ends_at', 'created_at');

  return me.db.queryOne(query, callback);
};
Example #6
0
 return objs.map(function (obj) {
     return sql.insert('function_group_info', {
         property_name: obj.property_name,
         user_consent_prompt: obj.user_consent_prompt,
         status: obj.status,
         is_default: obj.is_default,
         description: obj.description,
         is_deleted: obj.is_deleted
     })
     .returning('*')
     .toString(); //return the results of the inserts
 });
DailyFilmGrossRepository.prototype.create = function (filmId, gross, date, callback) {
  var me = this;

  var query = sql.insert('daily_film_grosses', {
    film_id: filmId,
    gross: gross,
    date_at: date.toISOString(),
    created_at: moment.utc().toISOString()
  }).returning('id', 'film_id', 'gross', 'date_at', 'created_at');

  me.db.queryOne(query, callback);
};
MemberRepository.prototype.create = function (userId, leagueId, isCommissioner, callback) {
  var me = this;

  var query = sql.insert('members', {
    user_id: userId,
    league_id: leagueId,
    is_commissioner: isCommissioner,
    created_at: moment.utc().toISOString()
  }).returning('id', 'user_id', 'league_id', 'is_commissioner', 'created_at');

  return me.db.queryOne(query, callback);
};
Example #9
0
function insertUserAlertMessageForHooks(dbClient, row, next) {

  var query = sql
              .insert('user_alert_messages_for_hooks', row)
              .returning('id')
              .toParams();

  dbClient.query(query.text, query.values, function(err, result) {

    if (err) return next(err);

    return next(null, result.rows[0].id);

  });

}
Example #10
0
Shop.prototype.create = function (data) {
  var shop = this;
  shop.uuid = uuid.v4();
  return db.pool.query(
    sql.insert(SHOPS, {
      uuid: shop.uuid,
      parent: data.parent,
      title: data.title,
      phone: data.phone,
      address: data.address,
      href: data.href,
      latitude: data.latitude,
      longitude: data.longitude,
      accuracy: data.accuracy
    })
      .toParams()
  ).then(() => shop.uuid);
}
Example #11
0
 return languages.map(function (lang) {
     return sql.insert('languages', 'id')
         .select
             (
             `'${lang}' AS id`
             )
         .where(
             sql.not(
                 sql.exists(
                     sql.select('*')
                         .from('languages l')
                         .where({
                             'l.id': lang
                         })
                 )
             )
         )
         .toString();
 });
Example #12
0
      self.validateTableAndColumns(table, data, function(err) {

        if (err) return next(err);

        var query = sql
                    .insert(table, data)
                    .returning(self.tableIdColumns[table] || 'id')
                    .toParams();

        dbClient.query(query.text, query.values, function(err, result) {

          if (err) return next(err);

          var location = ((req.isSecure()) ? 'https' : 'http') +
          '://' + req.headers.host + req.url + '/' + result.rows[0][self.tableIdColumns[table] || 'id'];
          res.setHeader('location', location);
          res.status(201);

          return next();

        });

      });
Example #13
0
 return services.map(function (service) {
     return sql.insert("service_types", service)
         .onConflict().onConstraint('service_type_pk').doUpdate().toString();
 });