Beispiel #1
0
 return r.table('posts').filter((postDoc) => (
   r.and(
     postDoc('id').eq(id),
     r.or(
       postDoc('author').eq(remoteUser),
       r.expr(adGroups).contains(postDoc('postedOn'))
     )
   )
 )).delete().run(r.conn).then(results => results.deleted);
Beispiel #2
0
Files.prototype.query = function(conn, query, user) {

	// Filter Files
	// --------------------

	var files = r.table('files');

	// OPTIMIZATION: restrict to own files for non-admin users
	if(user !== true)
		files = files.filter({user_id: user.id});

	// restrict to user
	if(typeof query.userId === 'string')
		files = files.filter({user_id: query.userId});

	// filter
	if(query.filter) query.filter.forEach(function(f){
		files = files.filter(f);
	});

	// search
	if(typeof query.search === 'string' && query.search.length)
		files = files.filter(r.or(
			r.row('name').downcase().match(query.search.toLowerCase()),
			r.row('email').downcase().match(query.search.toLowerCase())
		));


	// Build Result
	// ------------

	var result = files;

	// sort
	if(query.sort)
		result = result.orderBy.apply(result, query.sort);

	// skip
	if(query.skip)
		result = result.skip(query.skip);

	// limit
	if(query.limit)
		result = result.limit(query.limit);

	return r.expr({

		// get the total results count
		total: files.count(),

		// get the processed files
		files: result.coerceTo('array')

	}).run(conn)

	// return as an array
	.then(function(results){
		return Promise.filter(results.files.map(function(data){
			return new File(conn, data, user)
			.catch(function(err){

				// suppress ForbiddenError
				if(err instanceof errors.ForbiddenError)
					return null;

				// re-throw all other errors
				return Promise.reject(err);
			});
		}), function(c){ return !!c; })
		.then(function(files){
			files.total = results.total;
			return files;
		});
	});
};
Beispiel #3
0
 /**
  * Build or
  *
  * [{id: "or"}, ...]
  */
 buildOr(row, segment) {
   var conditions = segment.map(v => this.buildClause(row, v))
   return r.or(...conditions)
 }
Beispiel #4
0
 r.table("mainaccounts").filter(function(doc) { return r.or(doc('user').eq(newdata.user), doc('email').eq(newdata.email));})