Skip to content

Commit

Permalink
creating boards via cc import micro service
Browse files Browse the repository at this point in the history
  • Loading branch information
psachmann committed Jan 15, 2025
1 parent d188e16 commit f825469
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { CoursesClientAdapter } from '@infra/courses-client';
import { Injectable } from '@nestjs/common';
import { BoardsClientAdapter } from '@infra/boards-client';
import { CommonCartridgeFileParser } from '../import/common-cartridge-file-parser';
import { DEFAULT_FILE_PARSER_OPTIONS } from '../import/common-cartridge-import.types';

@Injectable()
export class CommonCartridgeImportService {
constructor(private readonly coursesClient: CoursesClientAdapter) {}
constructor(private readonly coursesClient: CoursesClientAdapter, private boardsClient: BoardsClientAdapter) {}

public async importFile(file: Buffer): Promise<void> {
const parser = new CommonCartridgeFileParser(file, DEFAULT_FILE_PARSER_OPTIONS);
Expand All @@ -16,6 +17,30 @@ export class CommonCartridgeImportService {
private async createCourse(parser: CommonCartridgeFileParser): Promise<void> {
const courseName = parser.getTitle() ?? 'Untitled Course';

await this.coursesClient.createCourse({ title: courseName });
const course = await this.coursesClient.createCourse({ title: courseName });

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const boardIds = await this.createBoards(course.courseId, parser);
}

private async createBoards(parentId: string, parser: CommonCartridgeFileParser): Promise<string[]> {
const titles = parser
.getOrganizations()
.filter((organization) => organization.pathDepth === 0)
.map((organization) => organization.title);
const ids = new Array<string>();

for await (const title of titles) {
const response = await this.boardsClient.createBoard({
title,
layout: 'columns',
parentId,
parentType: 'course',
});

ids.push(response.id);
}

return ids;
}
}

0 comments on commit f825469

Please sign in to comment.