MCPcopy
hub / github.com/kysely-org/kysely / userController

Function userController

example/src/user/user.controller.ts:9–49  ·  view source on GitHub ↗
(router: Router)

Source from the content-addressed store, hash-verified

7import { ControllerError } from '../util/errors'
8
9export function userController(router: Router): void {
10 router.post('/api/v1/user', async (ctx) => {
11 const { body } = ctx.request
12
13 if (!validateCreateAnonymousUserRequest(body)) {
14 throw new ControllerError(400, 'InvalidUser', 'invalid user')
15 }
16
17 const result = await ctx.db.transaction().execute(async (trx) => {
18 return userService.createAnonymousUser(trx, body)
19 })
20
21 ctx.status = 201
22 ctx.body = {
23 user: result.user,
24 authToken: result.authToken.authToken,
25 refreshToken: result.refreshToken.refreshToken,
26 }
27 })
28
29 router.get(
30 '/api/v1/user/:userId',
31 authenticationService.authenticateUser,
32 async (ctx) => {
33 const { userId } = ctx.params
34 const user = await userService.findUserById(ctx.db, userId)
35
36 if (!user) {
37 throw new ControllerError(
38 404,
39 'UserNotFound',
40 `user with id ${userId} was not found`,
41 )
42 }
43
44 ctx.body = { user }
45 },
46 )
47
48 signInMethodController(router)
49}

Callers 1

constructorMethod · 0.90

Calls 3

signInMethodControllerFunction · 0.90
executeMethod · 0.65
transactionMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…