app/api/server/v1/groups.js
// Returns the private group subscription IF found otherwise it will return the failure of why it didn't. Check the `statusCode` property
Returns the private group subscription IF found otherwise it will return the failure of why it didn't. Check the `statusCode` property
Returns the private group subscription IF found otherwise it will return the failure of why it didn ' t . Check the ` statusCode ` property
function findPrivateGroupByIdOrName({ params, userId, checkedArchived = true }) {
	if ((!params.roomId || !params.roomId.trim()) && (!params.roomName || !params.roomName.trim())) {
		throw new Meteor.Error('error-room-param-not-provided', 'The parameter "roomId" or "roomName" is required');
	}
	const roomOptions = {
		fields: {
			t: 1,
			ro: 1,
			name: 1,
			fname: 1,
			prid: 1,
			archived: 1,
			broadcast: 1,
		},
	};
	const room = params.roomId
		? Rooms.findOneById(params.roomId, roomOptions)
		: Rooms.findOneByName(params.roomName, roomOptions);
	if (!room || room.t !== 'p') {
		throw new Meteor.Error('error-room-not-found', 'The required "roomId" or "roomName" param provided does not match any group');
	}
	const user = Users.findOneById(userId, { fields: { username: 1 } });
	if (!canAccessRoom(room, user)) {
		throw new Meteor.Error('error-room-not-found', 'The required "roomId" or "roomName" param provided does not match any group');
	}
	const roomName = room.prid ? room.fname : room.name;
	if (checkedArchived && room.archived) {
		throw new Meteor.Error('error-room-archived', `The private group, ${ roomName }, is archived`);
	}
	const sub = Subscriptions.findOneByRoomIdAndUserId(room._id, userId, { fields: { open: 1 } });
	return {
		rid: room._id,
		open: sub && sub.open,
		ro: room.ro,
		t: room.t,
		name: roomName,
		broadcast: room.broadcast,
	};
}
function findPrivateGroupByIdOrName ( { params , userId , checkedArchived = true } ) { if ( ( ! params . roomId || ! params . roomId . trim ( ) ) && ( ! params . roomName || ! params . roomName . trim ( ) ) ) { throw new Meteor . Error ( 'error-room-param-not-provided' , 'The parameter "roomId" or "roomName" is required' ) ; } const roomOptions = { fields : { t : 1 , ro : 1 , name : 1 , fname : 1 , prid : 1 , archived : 1 , broadcast : 1 , } , } ; const room = params . roomId ? Rooms . findOneById ( params . roomId , roomOptions ) : Rooms . findOneByName ( params . roomName , roomOptions ) ; if ( ! room || room . t !== 'p' ) { throw new Meteor . Error ( 'error-room-not-found' , 'The required "roomId" or "roomName" param provided does not match any group' ) ; } const user = Users . findOneById ( userId , { fields : { username : 1 } } ) ; if ( ! canAccessRoom ( room , user ) ) { throw new Meteor . Error ( 'error-room-not-found' , 'The required "roomId" or "roomName" param provided does not match any group' ) ; } const roomName = room . prid ? room . fname : room . name ; if ( checkedArchived && room . archived ) { throw new Meteor . Error ( 'error-room-archived' , ` ${ roomName } ` ) ; } const sub = Subscriptions . findOneByRoomIdAndUserId ( room . _id , userId , { fields : { open : 1 } } ) ; return { rid : room . _id , open : sub && sub . open , ro : room . ro , t : room . t , name : roomName , broadcast : room . broadcast , } ; }
Returns the private group subscription IF found otherwise it will return the failure of why it didn't.
Returns the private group subscription IF found otherwise it will return the failure of why it didn ' t .
// discussions have their names saved on `fname` property