Skip to content

Commit

Permalink
feat: New endpoint for listing rooms & discussions from teams #33177
Browse files Browse the repository at this point in the history
…- type plural
  • Loading branch information
juliajforesti committed Sep 3, 2024
1 parent 92fcca8 commit 5f3d321
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
6 changes: 3 additions & 3 deletions apps/meteor/server/models/raw/Rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,7 @@ export class RoomsRaw extends BaseRaw<IRoom> implements IRoomsModel {
teamRoomId: string,
userId: string,
filter?: string,
type?: 'channel' | 'discussion',
type?: 'channels' | 'discussions',
options?: FindOptions<IRoom>,
): AggregationCursor<{ totalCount: { count: number }[]; paginatedResults: IRoom[] }> {
const nameFilter = filter ? new RegExp(escapeRegExp(filter), 'i') : undefined;
Expand All @@ -2075,8 +2075,8 @@ export class RoomsRaw extends BaseRaw<IRoom> implements IRoomsModel {
$and: [
{
$or: [
...(!type || type === 'channel' ? [{ teamId }] : []),
...(!type || type === 'discussion' ? [{ prid: teamRoomId }] : []),
...(!type || type === 'channels' ? [{ teamId }] : []),
...(!type || type === 'discussions' ? [{ prid: teamRoomId }] : []),
],
},
...(nameFilter ? [{ $or: [{ fname: nameFilter }, { name: nameFilter }] }] : []),
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/services/team/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ export class TeamService extends ServiceClassInternal implements ITeamService {
userId: string,
team: ITeam,
filter?: string,
type?: 'channel' | 'discussion',
type?: 'channels' | 'discussions',
sort?: Record<string, 1 | -1>,
skip = 0,
limit = 10,
Expand Down
24 changes: 8 additions & 16 deletions apps/meteor/tests/end-to-end/api/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe('[Teams]', () => {
name: `test-team-with-sidepanel-error-${Date.now()}`,
type: 0,
sidepanel: {
items: ['channels', 'discussion', 'other'],
items: ['channels', 'discussions', 'other'],
},
})
.expect('Content-Type', 'application/json')
Expand Down Expand Up @@ -451,7 +451,7 @@ describe('[Teams]', () => {
.expect(200)
.expect((response) => {
expect(response.body).to.have.property('success', true);
expect(response.body).to.have.property('channel');
expect(response.body).to.have.property('channels');
expect(response.body.channel).to.have.property('_id', channelToKeepId);
expect(response.body.channel).to.not.have.property('teamId');
});
Expand All @@ -467,7 +467,7 @@ describe('[Teams]', () => {
.expect(200)
.expect((response) => {
expect(response.body).to.have.property('success', true);
expect(response.body).to.have.property('channel');
expect(response.body).to.have.property('channels');
expect(response.body.channel).to.have.property('_id', testTeam.roomId);
expect(response.body.channel).to.not.have.property('teamId');
expect(response.body.channel).to.not.have.property('teamMain');
Expand Down Expand Up @@ -1403,7 +1403,7 @@ describe('[Teams]', () => {
.expect(200)
.expect((response) => {
expect(response.body).to.have.property('success', true);
expect(response.body).to.have.property('channel');
expect(response.body).to.have.property('channels');
expect(response.body.channel).to.have.property('_id', channel1Id);
expect(response.body.channel).to.not.have.property('teamId');
})
Expand Down Expand Up @@ -2478,7 +2478,7 @@ describe('[Teams]', () => {
it('should return only items of type channel', async () => {
const res = await request
.get(api('teams.listChildren'))
.query({ teamId: testTeam._id, type: 'channel' })
.query({ teamId: testTeam._id, type: 'channels' })
.set(credentials)
.expect(200);

Expand All @@ -2491,7 +2491,7 @@ describe('[Teams]', () => {
it('should return only items of type discussion', async () => {
const res = await request
.get(api('teams.listChildren'))
.query({ teamId: testTeam._id, type: 'discussion' })
.query({ teamId: testTeam._id, type: 'discussions' })
.set(credentials)
.expect(200);

Expand All @@ -2502,11 +2502,7 @@ describe('[Teams]', () => {
});

it('should return both when type is not passed', async () => {
const res = await request
.get(api('teams.listChildren'))
.query({ teamId: testTeam._id })
.set(credentials)
.expect(200);
const res = await request.get(api('teams.listChildren')).query({ teamId: testTeam._id }).set(credentials).expect(200);

expect(res.body).to.have.property('total').to.be.equal(5);
expect(res.body).to.have.property('data').to.be.an('array');
Expand All @@ -2516,11 +2512,7 @@ describe('[Teams]', () => {
});

it('should fail if type is other than channel or discussion', async () => {
await request
.get(api('teams.listChildren'))
.query({ teamId: testTeam._id, type: 'other' })
.set(credentials)
.expect(400);
await request.get(api('teams.listChildren')).query({ teamId: testTeam._id, type: 'other' }).set(credentials).expect(400);
});
});
});
2 changes: 1 addition & 1 deletion packages/core-services/src/types/ITeamService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export interface ITeamService {
userId: string,
team: ITeam,
filter?: string,
type?: 'channel' | 'discussion',
type?: 'channels' | 'discussions',
sort?: Record<string, 1 | -1>,
skip?: number,
limit?: number,
Expand Down
2 changes: 1 addition & 1 deletion packages/model-typings/src/models/IRoomsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export interface IRoomsModel extends IBaseModel<IRoom> {
teamRoomId: string,
userId: string,
filter?: string,
type?: 'channel' | 'discussion',
type?: 'channels' | 'discussions',
options?: FindOptions<IRoom>,
): AggregationCursor<{ totalCount: { count: number }[]; paginatedResults: IRoom[] }>;
}
4 changes: 2 additions & 2 deletions packages/rest-typings/src/v1/teams/TeamsListChildren.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ajv } from '../Ajv';

type GeneralProps = {
filter?: string;
type?: 'channel' | 'discussion';
type?: 'channels' | 'discussions';
};

export type TeamsListChildrenProps =
Expand All @@ -22,7 +22,7 @@ const TeamsListChildrenPropsSchema = {
properties: {
teamId: { type: 'string' },
teamName: { type: 'string' },
type: { type: 'string', enum: ['channel', 'discussion'] },
type: { type: 'string', enum: ['channels', 'discussions'] },
roomId: { type: 'string' },
filter: { type: 'string' },
offset: { type: 'number' },
Expand Down

0 comments on commit 5f3d321

Please sign in to comment.