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

N21-2197 Course sync - Update existing course immediately after sync begin #5287

Merged
merged 13 commits into from
Oct 16, 2024
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
8 changes: 8 additions & 0 deletions apps/server/src/modules/learnroom/domain/do/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ export class Course extends DomainObject<CourseProps> {
return this.props.substitutionTeacherIds;
}

set classes(value: EntityId[]) {
this.props.classIds = value;
}

get classes(): EntityId[] {
return this.props.classIds;
}

set groups(value: EntityId[]) {
this.props.groupIds = value;
}

get groups(): EntityId[] {
return this.props.groupIds;
}
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/modules/learnroom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export {
CourseGroupService,
CourseService,
CourseDoService,
CourseSyncService,
DashboardService,
CourseRoomsService,
} from './service';
5 changes: 5 additions & 0 deletions apps/server/src/modules/learnroom/learnroom.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ClassModule } from '@modules/class';
import { CopyHelperModule } from '@modules/copy-helper';
import { GroupModule } from '@modules/group';
import { LessonModule } from '@modules/lesson';
import { RoleModule } from '@modules/role';
import { SchoolModule } from '@modules/school';
import { TaskModule } from '@modules/task';
import { ContextExternalToolModule } from '@modules/tool/context-external-tool';
Expand Down Expand Up @@ -34,6 +35,7 @@ import {
CourseGroupService,
CourseRoomsService,
CourseService,
CourseSyncService,
DashboardService,
GroupDeletedHandlerService,
} from './service';
Expand All @@ -56,6 +58,7 @@ import { CommonCartridgeFileValidatorPipe } from './utils';
ClassModule,
SchoolModule,
GroupModule,
RoleModule,
],
providers: [
{
Expand All @@ -79,6 +82,7 @@ import { CommonCartridgeFileValidatorPipe } from './utils';
},
CourseService,
CourseDoService,
CourseSyncService,
DashboardElementRepo,
DashboardModelMapper,
DashboardService,
Expand All @@ -92,6 +96,7 @@ import { CommonCartridgeFileValidatorPipe } from './utils';
CourseCopyService,
CourseService,
CourseDoService,
CourseSyncService,
CourseRoomsService,
CommonCartridgeExportService,
CommonCartridgeImportService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ import { Page } from '@shared/domain/domainobject';
import { IFindOptions, SortOrder } from '@shared/domain/interface';
import { EntityId } from '@shared/domain/types';
import { groupFactory } from '@shared/testing';
import {
Course,
COURSE_REPO,
CourseAlreadySynchronizedLoggableException,
CourseFilter,
CourseNotSynchronizedLoggableException,
CourseRepo,
} from '../domain';
import { Course, COURSE_REPO, CourseFilter, CourseRepo } from '../domain';
import { courseFactory } from '../testing';
import { CourseDoService } from './course-do.service';

Expand Down Expand Up @@ -139,93 +132,6 @@ describe(CourseDoService.name, () => {
});
});

describe('stopSynchronization', () => {
describe('when a course is synchronized with a group', () => {
const setup = () => {
const course: Course = courseFactory.build({ syncedWithGroup: new ObjectId().toHexString() });

return {
course,
};
};

it('should save a course without a synchronized group', async () => {
const { course } = setup();

await service.stopSynchronization(course);

expect(courseRepo.save).toHaveBeenCalledWith(
new Course({
...course.getProps(),
syncedWithGroup: undefined,
})
);
});
});

describe('when a course is not synchronized with a group', () => {
const setup = () => {
const course: Course = courseFactory.build();

return {
course,
};
};

it('should throw an unprocessable entity exception', async () => {
const { course } = setup();

await expect(service.stopSynchronization(course)).rejects.toThrow(CourseNotSynchronizedLoggableException);
});
});
});

describe('startSynchronization', () => {
describe('when a course is not synchronized with a group', () => {
const setup = () => {
const course: Course = courseFactory.build();
const group: Group = groupFactory.build();

return {
course,
group,
};
};

it('should save a course with a synchronized group', async () => {
const { course, group } = setup();

await service.startSynchronization(course, group);

expect(courseRepo.save).toHaveBeenCalledWith(
new Course({
...course.getProps(),
syncedWithGroup: group.id,
})
);
});
});

describe('when a course is synchronized with a group', () => {
const setup = () => {
const course: Course = courseFactory.build({ syncedWithGroup: new ObjectId().toHexString() });
const group: Group = groupFactory.build();

return {
course,
group,
};
};
it('should throw an unprocessable entity exception', async () => {
const { course, group } = setup();

await expect(service.startSynchronization(course, group)).rejects.toThrow(
CourseAlreadySynchronizedLoggableException
);
});
});
});

describe('findCourses', () => {
describe('when course are found', () => {
const setup = () => {
Expand Down
29 changes: 1 addition & 28 deletions apps/server/src/modules/learnroom/service/course-do.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { Page } from '@shared/domain/domainobject';
import { IFindOptions } from '@shared/domain/interface';
import { EntityId } from '@shared/domain/types';
import {
type Course,
COURSE_REPO,
CourseAlreadySynchronizedLoggableException,
CourseFilter,
CourseNotSynchronizedLoggableException,
CourseRepo,
} from '../domain';
import { COURSE_REPO, CourseFilter, CourseRepo, type Course } from '../domain';

@Injectable()
export class CourseDoService implements AuthorizationLoaderServiceGeneric<Course> {
Expand All @@ -35,26 +28,6 @@ export class CourseDoService implements AuthorizationLoaderServiceGeneric<Course
return courses;
}

public async stopSynchronization(course: Course): Promise<void> {
if (!course.syncedWithGroup) {
throw new CourseNotSynchronizedLoggableException(course.id);
}

course.syncedWithGroup = undefined;

await this.courseRepo.save(course);
}

public async startSynchronization(course: Course, group: Group): Promise<void> {
if (course.syncedWithGroup) {
throw new CourseAlreadySynchronizedLoggableException(course.id);
}

course.syncedWithGroup = group.id;

await this.courseRepo.save(course);
}

public async getCourseInfo(filter: CourseFilter, options?: IFindOptions<Course>): Promise<Page<Course>> {
const courses = await this.courseRepo.getCourseInfo(filter, options);

Expand Down
Loading
Loading