The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as Domain from "@alchemy.run/domain"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { Account } from "../Account/Account.aggregate.ts"; |
| 4 | import { mainAccountId } from "../Account/Account.id.ts"; |
| 5 | import { OpenAccount } from "../Account/OpenAccount.command.ts"; |
| 6 | import { CustomerRegistered } from "./ConfirmRegistration.command.ts"; |
| 7 | import { Customer } from "./Customer.aggregate.ts"; |
| 8 | |
| 9 | /** Whenever a customer registers, open their main account. */ |
| 10 | export class MainAccountProvisioning extends Domain.Policy("MainAccountProvisioning", { |
| 11 | from: Customer, |
| 12 | on: [CustomerRegistered], |
| 13 | }) {} |
| 14 | |
| 15 | export const MainAccountProvisioningLive = MainAccountProvisioning.toLayer( |
| 16 | Effect.gen(function* () { |
| 17 | const accounts = yield* Account; |
| 18 | return Effect.fn(function* ({ source, event }) { |
| 19 | yield* accounts |
| 20 | .send( |
| 21 | mainAccountId(source.id), |
| 22 | new OpenAccount({ customerId: source.id, owner: event.name }), |
| 23 | ) |
| 24 | .pipe(Effect.catchTag("AlreadyOpen", () => Effect.void)); |
| 25 | }); |
| 26 | }), |
| 27 | ); |