Skip to content

Commit

Permalink
Merge branch 'main' into BC-4256-Integration-tldraw
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejpass committed Oct 10, 2023
2 parents 4cdc81c + 2b27ebe commit 418e569
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
SubmissionContainerElementNode,
} from '@shared/domain';
import {
TestApiClient,
UserAndAccountTestFactory,
cardNodeFactory,
cleanupCollections,
columnBoardNodeFactory,
Expand All @@ -19,8 +21,6 @@ import {
fileElementNodeFactory,
richTextElementNodeFactory,
submissionContainerElementNodeFactory,
TestApiClient,
UserAndAccountTestFactory,
} from '@shared/testing';
import { ServerTestModule } from '@src/modules/server/server.module';

Expand Down Expand Up @@ -63,7 +63,10 @@ describe(`content element update content (api)`, () => {
const parentCard = cardNodeFactory.buildWithId({ parent: column });
const richTextElement = richTextElementNodeFactory.buildWithId({ parent: parentCard });
const fileElement = fileElementNodeFactory.buildWithId({ parent: parentCard });
const submissionContainerElement = submissionContainerElementNodeFactory.buildWithId({ parent: parentCard });
const submissionContainerElement = submissionContainerElementNodeFactory.buildWithId({
parent: parentCard,
dueDate: null,
});

const tomorrow = new Date(Date.now() + 86400000);
const submissionContainerElementWithDueDate = submissionContainerElementNodeFactory.buildWithId({
Expand Down Expand Up @@ -166,7 +169,6 @@ describe(`content element update content (api)`, () => {

it('should return status 204 (nothing changed) without dueDate parameter for submission container element', async () => {
const { loggedInClient, submissionContainerElement } = await setup();

const response = await loggedInClient.patch(`${submissionContainerElement.id}/content`, {
data: {
content: {},
Expand All @@ -177,7 +179,7 @@ describe(`content element update content (api)`, () => {
expect(response.statusCode).toEqual(204);
});

it('should not change dueDate value without dueDate parameter for submission container element', async () => {
it('should not change dueDate when not proviced in submission container element without dueDate', async () => {
const { loggedInClient, submissionContainerElement } = await setup();

await loggedInClient.patch(`${submissionContainerElement.id}/content`, {
Expand All @@ -187,11 +189,10 @@ describe(`content element update content (api)`, () => {
},
});
const result = await em.findOneOrFail(SubmissionContainerElementNode, submissionContainerElement.id);

expect(result.dueDate).toBeUndefined();
expect(result.dueDate).toBeNull();
});

it('should set dueDate value when dueDate parameter is provided for submission container element', async () => {
it('should set dueDate value when provided for submission container element', async () => {
const { loggedInClient, submissionContainerElement } = await setup();

const inThreeDays = new Date(Date.now() + 259200000);
Expand All @@ -207,18 +208,20 @@ describe(`content element update content (api)`, () => {
expect(result.dueDate).toEqual(inThreeDays);
});

it('should unset dueDate value when dueDate parameter is not provided for submission container element', async () => {
it('should unset dueDate value when dueDate parameter is null for submission container element', async () => {
const { loggedInClient, submissionContainerElementWithDueDate } = await setup();

await loggedInClient.patch(`${submissionContainerElementWithDueDate.id}/content`, {
data: {
content: {},
content: {
dueDate: null,
},
type: 'submissionContainer',
},
});
const result = await em.findOneOrFail(SubmissionContainerElementNode, submissionContainerElementWithDueDate.id);

expect(result.dueDate).toBeUndefined();
expect(result.dueDate).toBeNull();
});

it('should return status 400 for wrong date format for submission container element', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class SubmissionContainerContentBody {
@IsOptional()
@ApiPropertyOptional({
required: false,
nullable: true,
description: 'The point in time until when a submission can be handed in.',
})
dueDate?: Date;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class SubmissionContainerElementResponseMapper implements BaseResponseMap
timestamps: new TimestampsResponse({ lastUpdatedAt: element.updatedAt, createdAt: element.createdAt }),
type: ContentElementType.SUBMISSION_CONTAINER,
content: new SubmissionContainerElementContent({
dueDate: element.dueDate || null,
dueDate: element.dueDate,
}),
});

Expand Down
5 changes: 1 addition & 4 deletions apps/server/src/modules/board/repo/board-do.builder-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,9 @@ export class BoardDoBuilderImpl implements BoardDoBuilder {
children: elements,
createdAt: boardNode.createdAt,
updatedAt: boardNode.updatedAt,
dueDate: boardNode.dueDate,
});

if (boardNode.dueDate) {
element.dueDate = boardNode.dueDate;
}

return element;
}

Expand Down
5 changes: 1 addition & 4 deletions apps/server/src/modules/board/repo/recursive-save.visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,9 @@ export class RecursiveSaveVisitor implements BoardCompositeVisitor {
id: submissionContainerElement.id,
parent: parentData?.boardNode,
position: parentData?.position,
dueDate: submissionContainerElement.dueDate,
});

if (submissionContainerElement.dueDate) {
boardNode.dueDate = submissionContainerElement.dueDate;
}

this.createOrUpdateBoardNode(boardNode);
this.visitChildren(submissionContainerElement, boardNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export class ContentElementUpdateVisitor implements BoardCompositeVisitor {

visitSubmissionContainerElement(submissionContainerElement: SubmissionContainerElement): void {
if (this.content instanceof SubmissionContainerContentBody) {
submissionContainerElement.dueDate = this.content.dueDate ?? undefined;
if (this.content.dueDate === undefined) return;
submissionContainerElement.dueDate = this.content.dueDate;
} else {
this.throwNotHandled(submissionContainerElement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class ContentElementService {

async update(element: AnyContentElementDo, content: AnyElementContentBody): Promise<void> {
const updater = new ContentElementUpdateVisitor(content);

element.accept(updater);

const parent = await this.boardDoRepo.findParentOfId(element.id);
Expand Down
1 change: 0 additions & 1 deletion apps/server/src/modules/board/uc/element.uc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export class ElementUc {
const element = await this.elementService.findById(elementId);

await this.checkPermission(userId, element, Action.write);

await this.elementService.update(element, content);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class ContentElementFactory {
private buildSubmissionContainer() {
const element = new SubmissionContainerElement({
id: new ObjectId().toHexString(),
dueDate: null,
children: [],
createdAt: new Date(),
updatedAt: new Date(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { SubmissionItem } from './submission-item.do';
import type { AnyBoardDo, BoardCompositeVisitor, BoardCompositeVisitorAsync } from './types';

export class SubmissionContainerElement extends BoardComposite<SubmissionContainerElementProps> {
get dueDate(): Date | undefined {
get dueDate(): Date | null {
return this.props.dueDate;
}

set dueDate(value: Date | undefined) {
set dueDate(value: Date | null) {
this.props.dueDate = value;
}

Expand All @@ -26,7 +26,7 @@ export class SubmissionContainerElement extends BoardComposite<SubmissionContain
}

export interface SubmissionContainerElementProps extends BoardCompositeProps {
dueDate?: Date;
dueDate: Date | null;
}

export function isSubmissionContainerElement(reference: unknown): reference is SubmissionContainerElement {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BoardDoBuilder, BoardNodeType } from './types';
@Entity({ discriminatorValue: BoardNodeType.SUBMISSION_CONTAINER_ELEMENT })
export class SubmissionContainerElementNode extends BoardNode {
@Property({ nullable: true })
dueDate?: Date;
dueDate: Date | null;

constructor(props: SubmissionContainerNodeProps) {
super(props);
Expand All @@ -22,5 +22,5 @@ export class SubmissionContainerElementNode extends BoardNode {
}

export interface SubmissionContainerNodeProps extends BoardNodeProps {
dueDate?: Date;
dueDate: Date | null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ export const submissionContainerElementNodeFactory = BaseFactory.define<
SubmissionContainerElementNode,
SubmissionContainerNodeProps
>(SubmissionContainerElementNode, () => {
return {};
return {
dueDate: null,
};
});

0 comments on commit 418e569

Please sign in to comment.