-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
N21-1464 extends provisioning of group types
- Loading branch information
Showing
17 changed files
with
331 additions
and
61 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
apps/server/src/modules/group/controller/dto/response/group-type.response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export enum GroupTypeResponse { | ||
CLASS = 'class', | ||
COURSE = 'course', | ||
OTHER = 'other', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export enum GroupTypes { | ||
CLASS = 'class', | ||
COURSE = 'course', | ||
OTHER = 'other', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { ObjectId } from '@mikro-orm/mongodb'; | ||
import { GroupEntityTypes } from '../entity'; | ||
import { GroupScope } from './group.scope'; | ||
|
||
describe(GroupScope.name, () => { | ||
let scope: GroupScope; | ||
|
||
beforeEach(() => { | ||
scope = new GroupScope(); | ||
scope.allowEmptyQuery(true); | ||
}); | ||
|
||
describe('byTypes', () => { | ||
describe('when types is undefined', () => { | ||
it('should not add query', () => { | ||
scope.byTypes(undefined); | ||
|
||
expect(scope.query).toEqual({}); | ||
}); | ||
}); | ||
|
||
describe('when types is defined', () => { | ||
it('should add query', () => { | ||
scope.byTypes([GroupEntityTypes.COURSE, GroupEntityTypes.CLASS]); | ||
|
||
expect(scope.query).toEqual({ type: { $in: [GroupEntityTypes.COURSE, GroupEntityTypes.CLASS] } }); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('byOrganizationId', () => { | ||
describe('when id is undefined', () => { | ||
it('should not add query', () => { | ||
scope.byOrganizationId(undefined); | ||
|
||
expect(scope.query).toEqual({}); | ||
}); | ||
}); | ||
|
||
describe('when id is defined', () => { | ||
const setup = () => { | ||
return { | ||
id: new ObjectId().toHexString(), | ||
}; | ||
}; | ||
|
||
it('should add query', () => { | ||
const { id } = setup(); | ||
|
||
scope.byOrganizationId(id); | ||
|
||
expect(scope.query).toEqual({ organization: id }); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('byUserId', () => { | ||
describe('when id is undefined', () => { | ||
it('should not add query', () => { | ||
scope.byUserId(undefined); | ||
|
||
expect(scope.query).toEqual({}); | ||
}); | ||
}); | ||
|
||
describe('when id is defined', () => { | ||
const setup = () => { | ||
return { | ||
id: new ObjectId().toHexString(), | ||
}; | ||
}; | ||
|
||
it('should add query', () => { | ||
const { id } = setup(); | ||
|
||
scope.byUserId(id); | ||
|
||
expect(scope.query).toEqual({ users: { user: new ObjectId(id) } }); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ObjectId } from '@mikro-orm/mongodb'; | ||
import { EntityId } from '@shared/domain/types'; | ||
import { Scope } from '@shared/repo'; | ||
import { GroupEntity, GroupEntityTypes } from '../entity'; | ||
|
||
export class GroupScope extends Scope<GroupEntity> { | ||
byTypes(types: GroupEntityTypes[] | undefined): this { | ||
if (types) { | ||
this.addQuery({ type: { $in: types } }); | ||
} | ||
return this; | ||
} | ||
|
||
byOrganizationId(id: EntityId | undefined): this { | ||
if (id) { | ||
this.addQuery({ organization: id }); | ||
} | ||
return this; | ||
} | ||
|
||
byUserId(id: EntityId | undefined): this { | ||
if (id) { | ||
this.addQuery({ users: { user: new ObjectId(id) } }); | ||
} | ||
return this; | ||
} | ||
} |
Oops, something went wrong.