diff --git a/packages/common/src/data/Todo.class.ts b/packages/common/src/data/Todo.class.ts index d41a559..8f4ec86 100644 --- a/packages/common/src/data/Todo.class.ts +++ b/packages/common/src/data/Todo.class.ts @@ -10,7 +10,7 @@ export class Todo _tag: Tag("Todo"), id: S.OptionFromSelf(S.String), - title: S.String, + order: S.Number, content: S.String, due: S.OptionFromSelf(S.DateFromSelf), diff --git a/packages/server/src/TodoRepository.ts b/packages/server/src/TodoRepository.ts index c2284bc..8c4d216 100644 --- a/packages/server/src/TodoRepository.ts +++ b/packages/server/src/TodoRepository.ts @@ -15,10 +15,12 @@ export module TodoRepository { export class TodoRepositoryService { + constructor( readonly todos: SubscriptionRef.SubscriptionRef<(Todo & { id: Option.Some })[]> ) {} + getByID(id: string) { return this.todos.get.pipe( Effect.map(Array.findFirst(todo => Equal.equals(todo.id.value, id))) @@ -31,6 +33,7 @@ export class TodoRepositoryService { ) } + add(todo: Todo) { return Effect.gen(this, function*() { if (Option.isSome(todo.id)) @@ -69,6 +72,12 @@ export class TodoRepositoryService { )) }) } + + + sort() { + return Ref.update(this.todos, Array.sort()) + } + } export class TodoHasID extends Data.TaggedError("TodoHasID")<{ todo: Todo }> {} @@ -80,8 +89,8 @@ export const createDefaultTodos = Effect.gen(function*() { yield* todos.add(new Todo({ id: Option.none(), - title: "A test todo", - content: "Lorem ipsum", + order: 1, + content: "Sort the socks", due: Option.none(), completed: false, createdAt: new Date(), @@ -90,8 +99,18 @@ export const createDefaultTodos = Effect.gen(function*() { yield* todos.add(new Todo({ id: Option.none(), - title: "Another one", - content: "Lorem ipsum", + order: 2, + content: "Sort the dog", + due: Option.none(), + completed: false, + createdAt: new Date(), + updatedAt: new Date(), + })) + + yield* todos.add(new Todo({ + id: Option.none(), + order: 2, + content: "Sort the car", due: Option.none(), completed: false, createdAt: new Date(),