-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathrecommendations.ts
More file actions
66 lines (61 loc) · 1.91 KB
/
recommendations.ts
File metadata and controls
66 lines (61 loc) · 1.91 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import type { FastifyInstance } from 'fastify'
import type { ZodTypeProvider } from 'fastify-type-provider-zod'
import {
getReceivedRecommendationsController,
respondRecommendationController,
sendRecommendationController,
} from '../controllers/recommendations-controller'
import { verifyJwt } from '../middlewares/verify-jwt'
import {
getRecommendationsQuerySchema,
respondRecommendationBodySchema,
respondRecommendationParamsSchema,
sendRecommendationBodySchema,
} from '../schemas/recommendations'
const TAGS = ['Recommendations']
export async function userRecommendationsRoutes(app: FastifyInstance) {
app.after(() =>
app.withTypeProvider<ZodTypeProvider>().route({
method: 'POST',
url: '/recommendations',
onRequest: [verifyJwt],
schema: {
description: 'Send a recommendation to a user',
tags: TAGS,
security: [{ bearerAuth: [] }],
body: sendRecommendationBodySchema,
},
handler: sendRecommendationController,
})
)
app.after(() =>
app.withTypeProvider<ZodTypeProvider>().route({
method: 'GET',
url: '/recommendations',
onRequest: [verifyJwt],
schema: {
description: 'Get received recommendations with TMDB data',
tags: TAGS,
security: [{ bearerAuth: [] }],
querystring: getRecommendationsQuerySchema,
},
handler: (request, reply) =>
getReceivedRecommendationsController(request, reply, app.redis),
})
)
app.after(() =>
app.withTypeProvider<ZodTypeProvider>().route({
method: 'PUT',
url: '/recommendations/:id',
onRequest: [verifyJwt],
schema: {
description: 'Accept or decline a recommendation',
tags: TAGS,
security: [{ bearerAuth: [] }],
params: respondRecommendationParamsSchema,
body: respondRecommendationBodySchema,
},
handler: respondRecommendationController,
})
)
}