How to use the @nozbe/watermelondb.Q.oneOf function in @nozbe/watermelondb

To help you get started, we’ve selected a few @nozbe/watermelondb 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 RocketChat / Rocket.Chat.ReactNative / app / lib / rocketchat.js View on Github external
let roomRoles = [];
		try {
			// get the room from database
			const room = await subsCollection.find(rid);
			// get room roles
			roomRoles = room.roles;
		} catch (error) {
			console.log('hasPermission -> Room not found');
			return permissions.reduce((result, permission) => {
				result[permission] = false;
				return result;
			}, {});
		}
		// get permissions from database
		try {
			const permissionsFiltered = await permissionsCollection.query(Q.where('id', Q.oneOf(permissions))).fetch();
			// get user roles on the server from redux
			const userRoles = (reduxStore.getState().login.user && reduxStore.getState().login.user.roles) || [];
			// merge both roles
			const mergedRoles = [...new Set([...roomRoles, ...userRoles])];

			// return permissions in object format
			// e.g. { 'edit-room': true, 'set-readonly': false }
			return permissions.reduce((result, permission) => {
				result[permission] = false;
				const permissionFound = permissionsFiltered.find(p => p.id === permission);
				if (permissionFound) {
					result[permission] = returnAnArray(permissionFound.roles).some(r => mergedRoles.includes(r));
				}
				return result;
			}, {});
		} catch (e) {
github RocketChat / Rocket.Chat.ReactNative / app / lib / methods / updateMessages.js View on Github external
try {
				sub = await subCollection.find(rid);
			} catch (error) {
				sub = { id: rid };
				console.log('updateMessages: subscription not found');
			}

			const messagesIds = [...update.map(m => m._id), ...remove.map(m => m._id)];
			const msgCollection = db.collections.get('messages');
			const threadCollection = db.collections.get('threads');
			const threadMessagesCollection = db.collections.get('thread_messages');
			const allMessagesRecords = await msgCollection
				.query(Q.where('rid', rid), Q.where('id', Q.oneOf(messagesIds)))
				.fetch();
			const allThreadsRecords = await threadCollection
				.query(Q.where('rid', rid), Q.where('id', Q.oneOf(messagesIds)))
				.fetch();
			const allThreadMessagesRecords = await threadMessagesCollection
				.query(Q.where('subscription_id', rid), Q.where('id', Q.oneOf(messagesIds)))
				.fetch();

			update = update.map(m => buildMessage(m));

			// filter messages
			let msgsToCreate = update.filter(i1 => !allMessagesRecords.find(i2 => i1._id === i2.id));
			let msgsToUpdate = allMessagesRecords.filter(i1 => update.find(i2 => i1.id === i2._id));

			// filter threads
			const allThreads = update.filter(m => m.tlm);
			let threadsToCreate = allThreads.filter(i1 => !allThreadsRecords.find(i2 => i1._id === i2.id));
			let threadsToUpdate = allThreadsRecords.filter(i1 => allThreads.find(i2 => i1.id === i2._id));
github status-im / liquid-funding / src / actions / lpEvents.js View on Github external
export const getLatestProfileEvents = async eventIds => {
  const events = await lpCollection.query(
    Q.where(
      'id',
      Q.notIn(eventIds)
    ),
    Q.where(
      'event',
      Q.oneOf([GIVER_ADDED, DELEGATE_ADDED, PROJECT_ADDED])
    )
  ).fetch()
  return events
}
github status-im / liquid-funding / src / actions / profiles.js View on Github external
export const getProfilesById = async ids => {
  const event = await profilesCollection.query(
    Q.where(
      'id_profile',
      Q.oneOf(ids)
    )
  ).fetch()
  return event
}