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

BC-6870 - Create unified board persistence entity #4919

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fb8bca5
add domain object and persistence
uidp Jan 14, 2024
7fab721
add minor changes and comments
uidp Jan 15, 2024
6a49333
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
uidp Apr 11, 2024
dccffe3
add entity, repo and example domain object
uidp Apr 11, 2024
6860b73
add TODO item
uidp Apr 12, 2024
8f19c72
fix orm entity and test
uidp Apr 12, 2024
40d3767
BC-6870 - fixes and add findByIds
virgilchiriac Apr 15, 2024
d12bf40
BC-6870 - add a couple of functions
virgilchiriac Apr 15, 2024
ca33b28
add todo
uidp Apr 16, 2024
8969652
Revert "BC-6870 - add a couple of functions"
uidp Apr 16, 2024
9b106ea
Revert "BC-6870 - fixes and add findByIds"
uidp Apr 16, 2024
7d8e9d6
implement typings
uidp Apr 17, 2024
b880cd4
isAllowedAsChild added
wolfganggreschus Apr 18, 2024
d1c7bfc
add simple column domain object
uidp Apr 19, 2024
024fb6d
improve board node domain object
uidp Apr 19, 2024
4521db9
improve board node repo
uidp Apr 19, 2024
5d9400f
add comments and todos
uidp Apr 19, 2024
a03088b
Merge branch 'BC-6870-board-persistence' of github.com:hpi-schul-clou…
uidp Apr 19, 2024
a40c5c1
use spcific board node type on properties types
uidp Apr 22, 2024
435d3c5
add context embeddable
uidp Apr 22, 2024
059fce1
fix test factories
uidp Apr 22, 2024
713d419
add findByIdAndType to board node repo
uidp Apr 22, 2024
3d444f6
add simple board node service
uidp Apr 22, 2024
70a3b29
implement child position update
uidp Apr 23, 2024
157e269
refactor types and implement repo.findByIds
uidp Apr 24, 2024
d19d187
add repo methods
uidp Apr 25, 2024
7164d18
Merge branch 'main' of github.com:hpi-schul-cloud/schulcloud-server i…
uidp Apr 25, 2024
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
40 changes: 40 additions & 0 deletions apps/server/src/modules/board/poc/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[ ] BoardNodeRepo additional methods
[ ] `findById` - depth
[ ] `findByIds`
[ ] `getTitlesByIds`
[ ] `countBoardUsageForExternalTools`
[ ] (`findParentOfId`)
[ ] refactor unit tests from
`board/repo/board-node.repo.spec.ts` and `board/repo/board-do.repo.spec.ts`
to `board/poc/repo/board-node.repo.spec.ts`
[ ] `BoardNode.isAllowedAsChild()`, see `BoardComposite.isAllowedAsChild()`

[ ] recursive delete
[ ] delete hooks

interface DeleteHandler {
async delete(AnyBoardNode);
}

const node = repo.findById()
node.delete(deleteHandler: DeleteHandler)

Node {
delete(deleteHandler: DeleteHandler) {
this.props.children.forEach((child) => child.delete(deleteHandler));
// TODO remove from domain object
deletHandler.delete(this); // remove from Unit of Work
}
}

Domain Objects

- Card
- title?
- height

ColumnBoard
- title
- context
- visibility

130 changes: 130 additions & 0 deletions apps/server/src/modules/board/poc/domain/_create-board-node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { ObjectId } from '@mikro-orm/mongodb';
import { BoardExternalReferenceType, BoardNodeType } from './types';
import { Card } from './card.do';
import { ColumnBoard } from './colum-board.do';
import { Column } from './column.do';
import { ROOT_PATH } from './path-utils';
import type {
AnyBoardNode,
AnyBoardNodeProps,
BoardNodeProps,
CardProps,
ColumnBoardProps,
ColumnProps,
} from './types';

// This is an exploration how we can build a general board node factory function
// just for inspiration

type AnyBoardNodeType = `${BoardNodeType}`;
type BoardNodeTypeToClass<T extends AnyBoardNodeType> = T extends BoardNodeType.COLUMN_BOARD
? ColumnBoard
: T extends BoardNodeType.COLUMN
? Column
: T extends BoardNodeType.CARD
? Card
: never;

type BaseProps<T extends AnyBoardNodeProps> = Pick<T, keyof BoardNodeProps>;
type StrictOmit<T, K extends keyof T> = Omit<T, K>;
type ExtraProps<T extends AnyBoardNodeProps> = StrictOmit<T, keyof BaseProps<T> | 'type'>;

type InitProps<T extends AnyBoardNodeProps> = Partial<BaseProps<T>> & ExtraProps<T>;
// type InitProps<T extends AnyBoardNodeProps> = Partial<T>;

type BoardNodeTypeToInitProps<T extends AnyBoardNodeType> = T extends BoardNodeType.COLUMN_BOARD
? InitProps<ColumnBoardProps>
: T extends BoardNodeType.COLUMN
? InitProps<ColumnProps>
: T extends BoardNodeType.CARD
? InitProps<CardProps>
: never;

const createBoardNode = <T extends AnyBoardNodeType>(
type: T,
props: BoardNodeTypeToInitProps<T>
): BoardNodeTypeToClass<T> => {
const baseProps = {
id: new ObjectId().toHexString(),
path: ROOT_PATH,
level: 0,
position: 0,
children: [],
createdAt: new Date(),
updatedAt: new Date(),
type: type as BoardNodeType,
};

let node: AnyBoardNode;

switch (type) {
case BoardNodeType.COLUMN_BOARD:
node = new ColumnBoard({
...baseProps,
title: (props as ColumnBoardProps).title,
isVisible: (props as ColumnBoardProps).isVisible,
context: (props as ColumnBoardProps).context,
...props,
type: BoardNodeType.COLUMN_BOARD,
});
break;
case BoardNodeType.COLUMN:
node = new Column({
...baseProps,
...props,
type: BoardNodeType.COLUMN,
});
break;
case BoardNodeType.CARD:
node = new Card({
...baseProps,
height: (props as CardProps).height,
...props,
type: BoardNodeType.CARD,
});
break;
default:
throw Error(`Unknown type '${type}'`);
}

return node as BoardNodeTypeToClass<T>;
};

const createCard = (props: InitProps<CardProps>) => {
const card = new Card({
id: new ObjectId().toHexString(),
path: ROOT_PATH,
level: 0,
position: 0,
children: [],
createdAt: new Date(),
updatedAt: new Date(),
type: BoardNodeType.CARD,
...props,
// height: props.height ?? 0,
});
return card;
};

const board = createBoardNode(BoardNodeType.COLUMN_BOARD, {
title: '',
isVisible: false,
context: {
type: BoardExternalReferenceType.Course,
id: new ObjectId().toHexString(),
},
});

const column = createBoardNode(BoardNodeType.COLUMN, {});

// const card = createBoardNode(BoardNodeType.CARD, {
// height: 0,
// });

const card = createCard({
height: 0,
});

column.addChild(card);
board.addChild(column);
column.addChild(card);
Loading
Loading