-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth-local-server.ts
30 lines (29 loc) · 973 Bytes
/
auth-local-server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import flatten from 'immuton/flatten';
import order from 'immuton/order';
import { toArray } from './async';
import * as localApi from './auth-local-api';
import { create } from './db';
import { Created } from './http';
import { implementAll } from './server';
import { users } from './users';
import { uuid4 } from './uuid';
export default implementAll(localApi).using({
// eslint-disable-next-line @typescript-eslint/no-shadow
_listUsers: async ({ direction, ordering, since }, { users }) => ({
results: order(flatten(await toArray(users.scan())), ordering, direction, since),
next: null,
}),
_createUser: async (props, { db }) => {
const id = uuid4();
const now = new Date();
const user = await db.run(
create(users, {
id,
...props,
updatedAt: now,
createdAt: now,
}),
);
return new Created(user);
},
});