Skip to content

Commit

Permalink
add minor changes and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
uidp committed Jan 15, 2024
1 parent fb8bca5 commit 7fab721
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 11 deletions.
10 changes: 5 additions & 5 deletions apps/server/src/modules/board/poc/board-node.do.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { boardNodeFactory } from './board-node.factory';
import { INITIAL_PATH, joinPath } from './path-utils';
import { ROOT_PATH, joinPath } from './path-utils';

describe('BoardNode', () => {
describe('a new instance', () => {
Expand All @@ -25,9 +25,9 @@ describe('BoardNode', () => {
expect(boardNode.level).toBe(0);
});

it('should have initial path', () => {
it('should have root path', () => {
const { boardNode } = setup();
expect(boardNode.path).toBe(INITIAL_PATH);
expect(boardNode.path).toBe(ROOT_PATH);
});
});

Expand Down Expand Up @@ -151,7 +151,7 @@ describe('BoardNode', () => {

child.removeFromParent(parent);

expect(child.path).toEqual(INITIAL_PATH);
expect(child.path).toEqual(ROOT_PATH);
});
});

Expand Down Expand Up @@ -193,7 +193,7 @@ describe('BoardNode', () => {

parent.removeChild(child);

expect(child.path).toEqual(INITIAL_PATH);
expect(child.path).toEqual(ROOT_PATH);
});
});
});
5 changes: 3 additions & 2 deletions apps/server/src/modules/board/poc/board-node.do.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DomainObject } from '@shared/domain/domain-object';
import { EntityId } from '@shared/domain/types';
import { INITIAL_PATH, PATH_SEPARATOR, joinPath } from './path-utils';
import { ROOT_PATH, PATH_SEPARATOR, joinPath } from './path-utils';

export interface BoardNodeProps {
id: EntityId;
Expand Down Expand Up @@ -43,6 +43,7 @@ export class BoardNode extends DomainObject<BoardNodeProps> {
}

addToParent(parent: BoardNode, position?: { index1: string; index2: string }): void {
// TODO remove from potential previous parent (and its children)?
if (this.parentId !== parent.id) {
this.props.path = joinPath(parent.path, parent.id);
// TODO set index (position)
Expand All @@ -55,7 +56,7 @@ export class BoardNode extends DomainObject<BoardNodeProps> {

removeFromParent(parent: BoardNode): void {
if (this.parentId === parent.id) {
this.props.path = INITIAL_PATH;
this.props.path = ROOT_PATH;
// TODO set index (position)
this.props.level = 0;
}
Expand Down
6 changes: 3 additions & 3 deletions apps/server/src/modules/board/poc/board-node.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
import { BaseFactory } from '@shared/testing';
import { ObjectId } from 'bson';
import { BoardNode, BoardNodeProps } from './board-node.do';
import { INITIAL_PATH } from './path-utils';
import { ROOT_PATH } from './path-utils';

export const boardNodeFactory = BaseFactory.define<BoardNode, BoardNodeProps>(BoardNode, ({ sequence }) => {
return {
id: new ObjectId().toHexString(),
path: INITIAL_PATH,
path: ROOT_PATH,
level: 0,
title: `column board #${sequence}`,
title: `board node #${sequence}`,
position: 0,
children: [],
createdAt: new Date(),
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/modules/board/poc/board-node.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export class BoardNodeRepo {
return boardNode;
}

// TODO findByIds()

persist(boardNode: BoardNode | BoardNode[]): BoardNodeRepo {
const boardNodes = Utils.asArray(boardNode);

Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/board/poc/path-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { EntityId } from '@shared/domain/types';

export const PATH_SEPARATOR = ',';

export const INITIAL_PATH = PATH_SEPARATOR;
export const ROOT_PATH = PATH_SEPARATOR;

export const joinPath = (path: string, id: EntityId): string => `${path}${id}${PATH_SEPARATOR}`;

0 comments on commit 7fab721

Please sign in to comment.