Example #1
0
function getColumnHardDefaultOnUpdate(field) {
    switch (getColumnDefault(field)) {
        case 'UpdatedDate':
            return knex.raw('NOW()');
        default:
            return null;
    }
}
Example #2
0
		permissions: function (role, onlyIds) {
			var promise;
			var rolepermissions = this.getField('rolePermissionsTable', 'table');
			var rpId = this.getField('rolePermissionsTable', 'roleIdField');
			var rpPermissionId = this.getField('rolePermissionsTable', 'permissionIdField');
			var rpRoleId = this.getField('rolePermissionsTable', 'roleIdField');
			var ptId = this.getField('permissionsTable', 'idField');
			var ptPermissionId = this.getField('permissionsTable', 'permissionIdField');
			var permissions = this.getField('permissionsTable', 'table');

			if (undefined === onlyIds) {
				return Q.all(knex(rolepermissions)
								.where(rpId, role)
								.orderBy(rpPermissionId)
								.select(knex.raw(rpPermissionId+" AS ID"))
							)
						.then(function (results) {
									console.log(results);
									var result = [];
									if (_.isArray(results)) {
										_.each(results, function (res) {
											result.push(res.ID);
										});
										return result;
									} else {
										return null;
									}
								},
								function (err) {
									throw new Error(err);
								});
			} else {
				var query = "SELECT TP.* FROM "+rolepermissions+" AS TR "
							+"RIGHT JOIN "+permissions+" AS TP ON (TR."+rpPermissionId+"=TP."+ptId+") "
							+"WHERE "+rpRoleId+"="+role+" ORDER BY TP."+ptId;
				return Q.when(knex.raw(query))
						.then(function (results) {
							return results[0];
						},
						function (err) {
							throw new Error(err);
						});
			}
		},
Example #3
0
			return Q.when(knex(table).del()).then(function (deleted) {
						return Q.when(knex.raw("ALTER TABLE "+table+" AUTO_INCREMENT=1"))
								.then(function () {
									return Q.when(self.assign(self.rootId(), self.rootId()))
											.then(function () {
												return 0 <= deleted;
											},
											function (err) {
												throw new Error("Add new entry Exception: "+err);
											});
								},
								function (err) {
									throw new Error("Can't reset AUTO_INCREMENT field"+err);
								});
					},
Example #4
0
function getColumnHardDefaultOnInsert(field, row) {
    var hardDefault = getColumnHardDefaultOnUpdate(field, row);
    if (hardDefault) {
        return hardDefault;
    }

    switch (getColumnDefault(field)) {
        case 'GUID':
            row.data[field.name] = row.tempID;
            return row.tempID;
        case 'CreatedDate':
            return knex.raw('NOW()');
        default:
            return null;
    }
}
Example #5
0
		hasPermission: function(role, permission) {
			
			var rolepermissions = this.getField('rolePermissionsTable', 'table');
			var permissions = this.getField('permissionsTable', 'table');
			var ptId = this.getField('permissionsTable', 'idField');
			var ptLeft = this.getField('permissionsTable', 'leftField');
			var ptRight = this.getField('permissionsTable', 'rightField');
			var rpPermissionId = this.getField('rolePermissionsTable', 'permissionIdField');
			var trLeft = this.getField('rolesTable', 'leftField');
			var trRight = this.getField('rolesTable', 'rightField');
			var trId = this.getField('rolesTable', 'idField');
			var roles = this.getField('rolesTable', 'table');

			var query = "SELECT COUNT(*) AS Result "
						+"FROM "+rolepermissions+" AS TRel "
						+"JOIN "+permissions+" AS TP ON (TP."+ptId+"=TRel."+rpPermissionId+") "
						+"JOIN "+roles+" AS TR ON (TR."+trId+"=TRel."+rpPermissionId+") "
						+"WHERE TR."+trLeft+" BETWEEN "
						+"(SELECT "+trLeft+" FROM "+roles+" WHERE "+trId+"="+role+") "
						+"AND "
						+"(SELECT "+trRight+" FROM "+roles+" WHERE "+trId+"="+role+") "
						// the above section means any row that is a descendants of our role 
						// (if descendant roles have some permission, then our role has it two)
						+" AND TP."+ptId+" IN ( "
							+"SELECT parent."+ptId+" "
							+"FROM "+permissions+" AS node, "
							+""+permissions+" AS parent "
							+"WHERE node."+ptLeft+" BETWEEN parent."+ptLeft+" AND parent."+ptRight+" "
							+"AND node."+ptId+"="+permission+" "
							+"ORDER BY parent."+ptLeft
						+")";
						/*
						the above section returns all the parents of (the path to) our permission, so if one of our role or its descendants
						has an assignment to any of them, we're good.
						*/
			return Q.when(knex.raw(query).then(function (result) {
				result = result[0];
				return (1 <= result[0].Result);
			},
			function (err) {
				console.log(err);
				throw new Error(err);
			}));

		},
Example #6
-1
    index: function (req, res, next) {

        if (req.user) {
            return res.redirect('/item')
        }



        knex.raw(
            'select '+
                'p.*,'+
                'a.secure_url,'+
                'pi.item_name,'+
                'pi.brand_name,'+
                'pi.id as item_id,'+
                'count(*) as like_count '+
            'from predict_training p '+
            'join assets a on a.upc = p.upc '+
            'join predict_items pi on pi.upc = p.upc '+
            'where p.gender = "male" '+
            'and a.tag_id = 1 '+
            'and p.liked = 1 '+
            'and a.deleted != 1 '+
            'and a.watermarked = 1 '+
            'group by p.upc '+
            'having like_count > 0 '+
            'order by RAND() '+
            'limit 6'
        ).exec(function (err, data){
            
            if (err) {
                return next(err);
            }

            // console.log(data[0]);
            res.render('index',{
                title: 'Home',
                messages: req.flash('messages'),
                items: data[0]
            });    

        });



        
    }