Skip to content

Commit db2b9d9

Browse files
committed
fix review
1 parent 67ff605 commit db2b9d9

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

packages/rocketchat-api/server/v1/groups.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -348,26 +348,24 @@ RocketChat.API.v1.addRoute('groups.info', { authRequired: true }, {
348348

349349
RocketChat.API.v1.addRoute('groups.invite', { authRequired: true }, {
350350
post() {
351-
let findResult;
352-
const params = this.requestParams();
353-
if ((params.roomId && params.roomId.trim()) || (params.roomName && params.roomName.trim())) {
354-
const idOrName = params.roomId || params.roomName;
355-
findResult = RocketChat.models.Rooms.findOneByIdOrName(idOrName);
356-
} else {
351+
const { roomId = '', roomName = '' } = this.requestParams();
352+
const idOrName = roomId || roomName;
353+
if (!idOrName.trim()) {
357354
throw new Meteor.Error('error-room-param-not-provided', 'The parameter "roomId" or "roomName" is required');
358355
}
359-
if (!findResult || findResult.t !== 'p') {
356+
357+
const { _id: rid, t: type } = RocketChat.models.Rooms.findOneByIdOrName(idOrName) || {};
358+
359+
if (!rid || type !== 'p') {
360360
throw new Meteor.Error('error-room-not-found', 'The required "roomId" or "roomName" param provided does not match any group');
361361
}
362362

363-
const user = this.getUserFromParams();
363+
const { username } = this.getUserFromParams();
364364

365-
Meteor.runAsUser(this.userId, () => {
366-
Meteor.call('addUserToRoom', { rid: findResult._id, username: user.username });
367-
});
365+
Meteor.runAsUser(this.userId, () => Meteor.call('addUserToRoom', { rid, username }));
368366

369367
return RocketChat.API.v1.success({
370-
group: RocketChat.models.Rooms.findOneById(findResult._id, { fields: RocketChat.API.v1.defaultFieldsToExclude })
368+
group: RocketChat.models.Rooms.findOneById(rid, { fields: RocketChat.API.v1.defaultFieldsToExclude })
371369
});
372370
}
373371
});

0 commit comments

Comments
 (0)