Skip to content

Commit

Permalink
N21-2180 Fix date for synchronized courses (#5233)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvinOehlerkingCap authored Sep 12, 2024
1 parent 0938186 commit ca17bee
Show file tree
Hide file tree
Showing 16 changed files with 96 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ describe('Group (API)', () => {
role: teacherUser.roles[0].name,
},
],
validPeriod: {
from: group.validPeriod?.from.toISOString(),
until: group.validPeriod?.until.toISOString(),
},
externalSource: {
externalId: group.externalSource?.externalId,
systemId: group.externalSource?.system.id,
Expand Down Expand Up @@ -319,6 +323,10 @@ describe('Group (API)', () => {
role: adminUser.roles[0].name,
},
],
validPeriod: {
from: availableGroupInSchool.validPeriod?.from.toISOString(),
until: availableGroupInSchool.validPeriod?.until.toISOString(),
},
externalSource: {
externalId: availableGroupInSchool.externalSource?.externalId,
systemId: availableGroupInSchool.externalSource?.system.id,
Expand Down Expand Up @@ -372,6 +380,10 @@ describe('Group (API)', () => {
role: adminUser.roles[0].name,
},
],
validPeriod: {
from: groupInSchool.validPeriod?.from.toISOString(),
until: groupInSchool.validPeriod?.until.toISOString(),
},
externalSource: {
externalId: groupInSchool.externalSource?.externalId,
systemId: groupInSchool.externalSource?.system.id,
Expand Down Expand Up @@ -492,6 +504,10 @@ describe('Group (API)', () => {
role: teacherUser.roles[0].name,
},
],
validPeriod: {
from: availableTeachersGroup.validPeriod?.from.toISOString(),
until: availableTeachersGroup.validPeriod?.until.toISOString(),
},
externalSource: {
externalId: availableTeachersGroup.externalSource?.externalId,
systemId: availableTeachersGroup.externalSource?.system.id,
Expand Down Expand Up @@ -544,6 +560,10 @@ describe('Group (API)', () => {
role: teacherUser.roles[0].name,
},
],
validPeriod: {
from: teachersGroup.validPeriod?.from.toISOString(),
until: teachersGroup.validPeriod?.until.toISOString(),
},
externalSource: {
externalId: teachersGroup.externalSource?.externalId,
systemId: teachersGroup.externalSource?.system.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ExternalSourceResponse } from './external-source.response';
import { GroupTypeResponse } from './group-type.response';
import { GroupUserResponse } from './group-user.response';
import { PeriodResponse } from './period.response';

export class GroupResponse {
@ApiProperty()
Expand All @@ -19,6 +20,9 @@ export class GroupResponse {
@ApiPropertyOptional()
externalSource?: ExternalSourceResponse;

@ApiPropertyOptional()
validPeriod?: PeriodResponse;

@ApiPropertyOptional()
organizationId?: string;

Expand All @@ -28,6 +32,7 @@ export class GroupResponse {
this.type = group.type;
this.users = group.users;
this.externalSource = group.externalSource;
this.validPeriod = group.validPeriod;
this.organizationId = group.organizationId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ApiProperty } from '@nestjs/swagger';

export class PeriodResponse {
@ApiProperty()
from: Date;

@ApiProperty()
until: Date;

constructor(props: PeriodResponse) {
this.from = props.from;
this.until = props.until;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
GroupUserResponse,
} from '../dto';
import { CourseInfoResponse } from '../dto/response/course-info.response';
import { PeriodResponse } from '../dto/response/period.response';

const typeMapping: Record<GroupTypes, GroupTypeResponse> = {
[GroupTypes.CLASS]: GroupTypeResponse.CLASS,
Expand Down Expand Up @@ -81,6 +82,9 @@ export class GroupResponseMapper {
type: typeMapping[resolvedGroup.type],
externalSource,
users,
validPeriod: resolvedGroup.validPeriod
? new PeriodResponse({ from: resolvedGroup.validPeriod.from, until: resolvedGroup.validPeriod.until })
: undefined,
organizationId: resolvedGroup.organizationId,
});

Expand Down
10 changes: 10 additions & 0 deletions apps/server/src/modules/group/domain/group-period.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export class GroupPeriod {
from: Date;

until: Date;

constructor(props: GroupPeriod) {
this.from = props.from;
this.until = props.until;
}
}
13 changes: 4 additions & 9 deletions apps/server/src/modules/group/domain/group.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AuthorizableObject, DomainObject } from '@shared/domain/domain-object';
import { ExternalSource, type UserDO } from '@shared/domain/domainobject';
import { EntityId } from '@shared/domain/types';
import { GroupPeriod } from './group-period';
import { GroupTypes } from './group-types';
import { GroupUser } from './group-user';

Expand All @@ -11,9 +12,7 @@ export interface GroupProps extends AuthorizableObject {

type: GroupTypes;

validFrom?: Date;

validUntil?: Date;
validPeriod?: GroupPeriod;

externalSource?: ExternalSource;

Expand Down Expand Up @@ -47,12 +46,8 @@ export class Group extends DomainObject<GroupProps> {
return this.props.type;
}

get validFrom(): Date | undefined {
return this.props.validFrom;
}

get validUntil(): Date | undefined {
return this.props.validUntil;
get validPeriod(): GroupPeriod | undefined {
return this.props.validPeriod;
}

removeUser(user: UserDO): void {
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/group/domain/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './group';
export * from './group-user';
export { GroupPeriod } from './group-period';
export * from './group-types';
export { GroupDeletedEvent } from './event';
export { GroupFilter } from './interface';
13 changes: 7 additions & 6 deletions apps/server/src/modules/group/repo/group-domain.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EntityManager } from '@mikro-orm/mongodb';
import { ExternalSourceEmbeddable, SystemEntity } from '@modules/system/entity';
import { ExternalSource } from '@shared/domain/domainobject';
import { Role, SchoolEntity, User } from '@shared/domain/entity';
import { Group, GroupProps, GroupTypes, GroupUser } from '../domain';
import { Group, GroupPeriod, GroupProps, GroupTypes, GroupUser } from '../domain';
import { GroupEntity, GroupEntityTypes, GroupUserEmbeddable, GroupValidPeriodEmbeddable } from '../entity';

const GroupEntityTypesToGroupTypesMapping: Record<GroupEntityTypes, GroupTypes> = {
Expand All @@ -23,10 +23,10 @@ export class GroupDomainMapper {
const props: GroupProps = group.getProps();

let validPeriod: GroupValidPeriodEmbeddable | undefined;
if (props.validFrom && props.validUntil) {
if (props.validPeriod) {
validPeriod = new GroupValidPeriodEmbeddable({
from: props.validFrom,
until: props.validUntil,
from: props.validPeriod.from,
until: props.validPeriod.until,
});
}

Expand All @@ -50,8 +50,9 @@ export class GroupDomainMapper {
const group: Group = new Group({
id: entity.id,
users: entity.users.map((groupUser): GroupUser => this.mapGroupUserEntityToGroupUser(groupUser)),
validFrom: entity.validPeriod ? entity.validPeriod.from : undefined,
validUntil: entity.validPeriod ? entity.validPeriod.until : undefined,
validPeriod: entity.validPeriod
? new GroupPeriod({ from: entity.validPeriod.from, until: entity.validPeriod.until })
: undefined,
externalSource: entity.externalSource
? this.mapExternalSourceEntityToExternalSource(entity.externalSource)
: undefined,
Expand Down
6 changes: 2 additions & 4 deletions apps/server/src/modules/group/repo/group.repo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ describe('GroupRepo', () => {
}),
],
organizationId: group.organization?.id,
validFrom: group.validPeriod?.from,
validUntil: group.validPeriod?.until,
validPeriod: group.validPeriod,
});
});
});
Expand Down Expand Up @@ -690,8 +689,7 @@ describe('GroupRepo', () => {
}),
],
organizationId: groupEntity.organization?.id,
validFrom: groupEntity.validPeriod?.from,
validUntil: groupEntity.validPeriod?.until,
validPeriod: groupEntity.validPeriod,
});
});
});
Expand Down
5 changes: 4 additions & 1 deletion apps/server/src/modules/group/uc/dto/resolved-group.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExternalSource } from '@shared/domain/domainobject';
import { GroupTypes } from '../../domain';
import { GroupPeriod, GroupTypes } from '../../domain';
import { ResolvedGroupUser } from './resolved-group-user';

export class ResolvedGroupDto {
Expand All @@ -15,12 +15,15 @@ export class ResolvedGroupDto {

organizationId?: string;

validPeriod?: GroupPeriod;

constructor(group: ResolvedGroupDto) {
this.id = group.id;
this.name = group.name;
this.type = group.type;
this.users = group.users;
this.externalSource = group.externalSource;
this.organizationId = group.organizationId;
this.validPeriod = group.validPeriod;
}
}
1 change: 1 addition & 0 deletions apps/server/src/modules/group/uc/mapper/group-uc.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class GroupUcMapper {
externalSource: group.externalSource,
users: resolvedGroupUsers,
organizationId: group.organizationId,
validPeriod: group.validPeriod,
});

return mapped;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ describe(SchulconnexCourseSyncService.name, () => {
new Course({
...course.getProps(),
name: newGroup.name,
startDate: newGroup.validFrom,
untilDate: newGroup.validUntil,
startDate: newGroup.validPeriod?.from,
untilDate: newGroup.validPeriod?.until,
studentIds: [studentId],
teacherIds: [teacherId],
}),
Expand Down Expand Up @@ -128,8 +128,8 @@ describe(SchulconnexCourseSyncService.name, () => {
new Course({
...course.getProps(),
name: newGroup.name,
startDate: newGroup.validFrom,
untilDate: newGroup.validUntil,
startDate: newGroup.validPeriod?.from,
untilDate: newGroup.validPeriod?.until,
studentIds: [],
teacherIds: [],
}),
Expand Down Expand Up @@ -168,8 +168,8 @@ describe(SchulconnexCourseSyncService.name, () => {
new Course({
...course.getProps(),
name: course.name,
startDate: newGroup.validFrom,
untilDate: newGroup.validUntil,
startDate: newGroup.validPeriod?.from,
untilDate: newGroup.validPeriod?.until,
studentIds: [],
teacherIds: [],
}),
Expand Down Expand Up @@ -218,8 +218,8 @@ describe(SchulconnexCourseSyncService.name, () => {
new Course({
...course.getProps(),
name: course.name,
startDate: newGroup.validFrom,
untilDate: newGroup.validUntil,
startDate: newGroup.validPeriod?.from,
untilDate: newGroup.validPeriod?.until,
studentIds: [],
teacherIds: [teacherUserId],
syncedWithGroup: course.syncedWithGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class SchulconnexCourseSyncService {
course.name = newGroup.name;
}

course.startDate = newGroup.validFrom;
course.untilDate = newGroup.validUntil;
course.startDate = newGroup.validPeriod?.from;
course.untilDate = newGroup.validPeriod?.until;

const students: GroupUser[] = newGroup.users.filter(
(user: GroupUser): boolean => user.roleId === studentRole.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,7 @@ describe(SchulconnexGroupProvisioningService.name, () => {
},
type: externalGroupDto.type,
organizationId: school.id,
validFrom: externalGroupDto.from,
validUntil: externalGroupDto.until,
validPeriod: { from: externalGroupDto.from, until: externalGroupDto.until },
users: [
{
userId: student.id,
Expand Down Expand Up @@ -497,8 +496,7 @@ describe(SchulconnexGroupProvisioningService.name, () => {
},
type: externalGroupDto.type,
organizationId: school.id,
validFrom: externalGroupDto.from,
validUntil: externalGroupDto.until,
validPeriod: { from: externalGroupDto.from, until: externalGroupDto.until },
users: [
{
userId: student.id,
Expand Down Expand Up @@ -566,8 +564,7 @@ describe(SchulconnexGroupProvisioningService.name, () => {
},
type: externalGroupDto.type,
organizationId: undefined,
validFrom: externalGroupDto.from,
validUntil: externalGroupDto.until,
validPeriod: { from: externalGroupDto.from, until: externalGroupDto.until },
users: [
{
userId: teacher.id,
Expand Down Expand Up @@ -636,8 +633,7 @@ describe(SchulconnexGroupProvisioningService.name, () => {
},
type: externalGroupDto.type,
organizationId: undefined,
validFrom: externalGroupDto.from,
validUntil: externalGroupDto.until,
validPeriod: { from: externalGroupDto.from, until: externalGroupDto.until },
users: [
{
userId: student.id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { Group, GroupFilter, GroupService, GroupTypes, GroupUser } from '@modules/group';
import { Group, GroupFilter, GroupPeriod, GroupService, GroupTypes, GroupUser } from '@modules/group';
import { CourseDoService } from '@modules/learnroom';
import { Course } from '@modules/learnroom/domain';
import {
Expand Down Expand Up @@ -110,8 +110,10 @@ export class SchulconnexGroupProvisioningService {
}),
type: externalGroup.type,
organizationId,
validFrom: externalGroup.from,
validUntil: externalGroup.until,
validPeriod:
externalGroup.from && externalGroup.until
? new GroupPeriod({ from: externalGroup.from, until: externalGroup.until })
: undefined,
users: existingGroup?.users ?? [],
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { Group, GroupProps, GroupTypes } from '@modules/group/domain';
import { GroupPeriod } from '@modules/group/domain/group-period';
import { ExternalSource } from '@shared/domain/domainobject';
import { DomainObjectFactory } from '../domain-object.factory';

Expand All @@ -14,8 +15,10 @@ export const groupFactory = DomainObjectFactory.define<Group, GroupProps>(Group,
roleId: new ObjectId().toHexString(),
},
],
validFrom: new Date(2023, 1),
validUntil: new Date(2023, 6),
validPeriod: new GroupPeriod({
from: new Date(2023, 1),
until: new Date(2023, 6),
}),
organizationId: new ObjectId().toHexString(),
externalSource: new ExternalSource({
externalId: `externalId-${sequence}`,
Expand Down

0 comments on commit ca17bee

Please sign in to comment.