Skip to content

Commit

Permalink
some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
virgilchiriac committed Oct 13, 2023
1 parent 0152043 commit 43e97b7
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class ElementController {
bodyParams.completed
);
const mapper = SubmissionItemResponseMapper.getInstance();
const response = mapper.mapSubmissionsToResponse(submissionItem);
const response = mapper.mapSubmissionItemToResponse(submissionItem);

return response;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
FileElement,
isContent,
isFileElement,
isRichTextElement,
isSubmissionItemContent,
RichTextElement,
SubmissionItem,
UserBoardRoles,
Expand All @@ -26,7 +26,7 @@ export class SubmissionItemResponseMapper {

public mapToResponse(submissionItems: SubmissionItem[], users: UserBoardRoles[]): SubmissionsResponse {
const submissionItemsResponse: SubmissionItemResponse[] = submissionItems.map((item) =>
this.mapSubmissionsToResponse(item)
this.mapSubmissionItemToResponse(item)
);
const usersResponse: UserDataResponse[] = users.map((user) => this.mapUsersToResponse(user));

Expand All @@ -35,8 +35,8 @@ export class SubmissionItemResponseMapper {
return response;
}

public mapSubmissionsToResponse(submissionItem: SubmissionItem): SubmissionItemResponse {
const children: (FileElement | RichTextElement)[] = submissionItem.children.filter(isContent);
public mapSubmissionItemToResponse(submissionItem: SubmissionItem): SubmissionItemResponse {
const children: (FileElement | RichTextElement)[] = submissionItem.children.filter(isSubmissionItemContent);
const result = new SubmissionItemResponse({
completed: submissionItem.completed,
id: submissionItem.id,
Expand Down
11 changes: 0 additions & 11 deletions apps/server/src/modules/board/service/content-element.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
ContentElementType,
EntityId,
isAnyContentElement,
SubmissionContainerElement,
SubmissionItem,
} from '@shared/domain';
import { AnyElementContentBody } from '../controller/dto';
Expand Down Expand Up @@ -43,16 +42,6 @@ export class ContentElementService {
return parent;
}

async findSubmissionContainerElement(elementId: EntityId): Promise<SubmissionContainerElement> {
const element = await this.boardDoRepo.findById(elementId);

if (!(element instanceof SubmissionContainerElement)) {
throw new NotFoundException(`There is no '${element.constructor.name}' with this id`);
}

return element;
}

async create(parent: Card | SubmissionItem, type: ContentElementType): Promise<AnyContentElementDo> {
const element = this.contentElementFactory.build(type);
parent.addChild(element);
Expand Down
10 changes: 8 additions & 2 deletions apps/server/src/modules/board/uc/submission-item.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {
ContentElementType,
EntityId,
FileElement,
isFileElement,
isRichTextElement,
isSubmissionContainerElement,
isSubmissionItem,
RichTextElement,
Expand Down Expand Up @@ -91,8 +93,12 @@ export class SubmissionItemUc {
// await this.checkPermission(userId, submissionItem, Action.write);

const element = await this.elementService.create(submissionItem, type);
// TODO
return element as FileElement | RichTextElement;

if (!isFileElement(element) && !isRichTextElement(element)) {
throw new UnprocessableEntityException();
}

return element;
}

private async isAuthorizedStudent(userId: EntityId, boardDo: AnyBoardDo): Promise<boolean> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import {
EntityId,
FileElement,
isFileElement,
isRichTextElement,
isSumbmissionItem,
RichTextElement,
} from '@shared/domain';
import { EntityId, FileElement, isFileElement, isRichTextElement, RichTextElement } from '@shared/domain';
import { BoardComposite, BoardCompositeProps } from './board-composite.do';
import type { AnyBoardDo, BoardCompositeVisitor, BoardCompositeVisitorAsync } from './types';

export class SubmissionItem extends BoardComposite<SubmissionItemProps> {
/* get children(): (RichTextElement | FileElement)[] {
const { children } = this.props;
if (!children) return [];
const filteredChildren = children.filter(isFileElement || isRichTextElement);
return filteredChildren;
} */

get completed(): boolean {
return this.props.completed;
}
Expand All @@ -35,10 +19,8 @@ export class SubmissionItem extends BoardComposite<SubmissionItemProps> {
this.props.userId = value;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
isAllowedAsChild(child: AnyBoardDo): boolean {
// Currently submission-item rejects any children, will open in the future
const allowed = child instanceof FileElement || child instanceof RichTextElement;
const allowed = isFileElement(child) || isRichTextElement(child);

return allowed;
}
Expand All @@ -60,3 +42,6 @@ export interface SubmissionItemProps extends BoardCompositeProps {
export function isSubmissionItem(reference: unknown): reference is SubmissionItem {
return reference instanceof SubmissionItem;
}

export const isSubmissionItemContent = (element: AnyBoardDo): element is RichTextElement | FileElement =>
isRichTextElement(element) || isFileElement(element);
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ import { SubmissionItem } from '../submission-item.do';
import { AnyContentElementDo } from './any-content-element-do';

export type AnyBoardDo = ColumnBoard | Column | Card | AnyContentElementDo | SubmissionItem;

export const isSumbmissionItem = (element: AnyBoardDo): element is SubmissionItem => element instanceof SubmissionItem;
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,3 @@ export const isAnyContentElement = (element: AnyBoardDo): element is AnyContentE

return result;
};

export const isContent = (element: AnyBoardDo): element is RichTextElement | FileElement =>
element instanceof RichTextElement || element instanceof FileElement;
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ import {
CardNode,
ColumnBoardNode,
ColumnNode,
ExternalToolElement,
FileElementNode,
LinkElementNode,
RichTextElementNode,
SubmissionContainerElementNode,
SubmissionItemNode,
} from '@shared/domain';

export type AnyElementNode = FileElementNode | RichTextElementNode | SubmissionContainerElementNode;
export type AnyElementNode =
| FileElementNode
| RichTextElementNode
| SubmissionContainerElementNode
| ExternalToolElement
| LinkElementNode;

export type AnyBoardNode = ColumnBoardNode | ColumnNode | CardNode | AnyElementNode | SubmissionItemNode;

0 comments on commit 43e97b7

Please sign in to comment.