Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW] Create Team with a member list of usernames #25868

Merged
merged 2 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/meteor/app/models/server/raw/Users.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@ export class UsersRaw extends BaseRaw {
return this.find(query, options);
}

findActiveByIdsOrUsernames(userIds, options = {}) {
const query = {
$or: [{ _id: { $in: userIds } }, { username: { $in: userIds } }],
active: true,
};

return this.find(query, options);
}

findByIds(userIds, options = {}) {
const query = {
_id: { $in: userIds },
Expand Down
7 changes: 4 additions & 3 deletions apps/meteor/server/services/team/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,11 @@ export class TeamService extends ServiceClassInternal implements ITeamService {

// TODO add validations to `data` and `members`

const membersResult = await this.Users.findActiveByIds(members, {
projection: { username: 1, _id: 0 },
const membersResult = await this.Users.findActiveByIdsOrUsernames(members, {
projection: { username: 1, _id: 1 },
}).toArray();
const memberUsernames = membersResult.map(({ username }) => username);
const memberIds = membersResult.map(({ _id }) => _id);

const teamData = {
...team,
Expand All @@ -96,7 +97,7 @@ export class TeamService extends ServiceClassInternal implements ITeamService {

// filter empty strings and falsy values from members list
const membersList: Array<InsertionModel<ITeamMember>> =
members
memberIds
?.filter(Boolean)
.filter((memberId) => !excludeFromMembers.includes(memberId))
.map((memberId) => ({
Expand Down
35 changes: 35 additions & 0 deletions apps/meteor/tests/end-to-end/api/25-teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,41 @@ describe('[Teams]', () => {
.end(done);
});

it('should create a public team with a member', (done) => {
request
.post(api('teams.create'))
.set(credentials)
.send({
name: `test-team-${Date.now()}`,
type: 0,
members: [testUser.username],
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
expect(res.body).to.have.property('team');
expect(res.body).to.have.nested.property('team._id');
publicTeam = res.body.team;
})
.then((response) => {
const teamId = response.body.team._id;
return request
.get(api('teams.members'))
.set(credentials)
.query({ teamId })
.expect(200)
.expect((response) => {
expect(response.body).to.have.property('success', true);
expect(response.body).to.have.property('members');
const member = response.body.members[0];
expect(member.user.username).to.be.equal(testUser.username);
});
})
.then(() => done())
.catch(done);
});

it('should create private team with a defined owner', (done) => {
request
.post(api('teams.create'))
Expand Down