forked from effect-app/boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrollers.ts
More file actions
23 lines (21 loc) · 772 Bytes
/
controllers.ts
File metadata and controls
23 lines (21 loc) · 772 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { matchFor, Router } from "#api/lib/routing"
import { Q } from "@effect-app/infra/Model"
import { Array, Effect, Order } from "effect-app"
import type { UserView } from "./resources.js"
import { AccountsRsc } from "./resources.js"
import { UserRepo } from "./UserRepo.js"
export default Router(AccountsRsc)({
dependencies: [UserRepo.Default],
effect: Effect.gen(function*() {
const userRepo = yield* UserRepo
return matchFor(AccountsRsc)({
GetMe: userRepo.getCurrentUser,
IndexUsers: (req) =>
userRepo
.query(Q.where("id", "in", req.filterByIds))
.pipe(Effect.andThen((users) => ({
users: Array.sort(users, Order.mapInput(Order.string, (_: UserView) => _.displayName))
})))
})
})
})