Skip to content

Commit

Permalink
Get ready to use the query
Browse files Browse the repository at this point in the history
Refs #2089
  • Loading branch information
thewilkybarkid committed Nov 18, 2024
1 parent c3e8fd8 commit db7a8a4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Comments/Context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ export class CommentEvents extends Context.Tag('CommentEvents')<
PubSub.PubSub<{ readonly commentId: Uuid.Uuid; readonly event: CommentEvent }>
>() {}

export class GetNextExpectedCommandForUserOnAComment extends Context.Tag('GetNextExpectedCommandForUserOnAComment')<
GetNextExpectedCommandForUserOnAComment,
(
...params: Parameters<ReturnType<ReturnType<typeof Queries.GetNextExpectedCommandForUserOnAComment>>>
) => Effect.Effect<
ReturnType<ReturnType<ReturnType<typeof Queries.GetNextExpectedCommandForUserOnAComment>>>,
UnableToQuery
>
>() {}

export class GetNextExpectedCommandForUser extends Context.Tag('GetNextExpectedCommandForUser')<
GetNextExpectedCommandForUser,
(
Expand Down
17 changes: 17 additions & 0 deletions src/Comments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
CommentEvents,
type GetComment,
type GetNextExpectedCommandForUser,
type GetNextExpectedCommandForUserOnAComment,
type HandleCommentCommand,
type PublishCommentWithADoi,
UnableToHandleCommand,
Expand Down Expand Up @@ -98,6 +99,22 @@ export const makeGetNextExpectedCommandForUser: Effect.Effect<
}).pipe(Effect.catchTag('FailedToGetEvents', cause => new UnableToQuery({ cause })))
})

export const makeGetNextExpectedCommandForUserOnAComment: Effect.Effect<
typeof GetNextExpectedCommandForUserOnAComment.Service,
never,
EventStore | RequiresAVerifiedEmailAddress
> = Effect.gen(function* () {
const eventStore = yield* EventStore
const requiresAVerifiedEmailAddress = yield* RequiresAVerifiedEmailAddress

return commentId =>
Effect.gen(function* () {
const events = yield* eventStore.getAllEvents

return Queries.GetNextExpectedCommandForUserOnAComment(requiresAVerifiedEmailAddress)(events)(commentId)
}).pipe(Effect.catchTag('FailedToGetEvents', cause => new UnableToQuery({ cause })))
})

export const ReactToCommentEvents: Layer.Layer<
never,
never,
Expand Down
6 changes: 6 additions & 0 deletions src/Program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,12 @@ export const Program = pipe(
Layer.provide(getPreprint),
Layer.provide(Layer.effect(Comments.HandleCommentCommand, Comments.makeHandleCommentCommand)),
Layer.provide(Layer.effect(Comments.GetNextExpectedCommandForUser, Comments.makeGetNextExpectedCommandForUser)),
Layer.provide(
Layer.effect(
Comments.GetNextExpectedCommandForUserOnAComment,
Comments.makeGetNextExpectedCommandForUserOnAComment,
),
),
Layer.provide(Layer.effect(Comments.GetComment, Comments.makeGetComment)),
Layer.provide(
Layer.scoped(
Expand Down

0 comments on commit db7a8a4

Please sign in to comment.