wishlist-app/src/api/routes/wishlist/read.ts
Benny Samir Hierl 82ac242d96 #1 JSON Schemas centralized
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
2022-02-05 14:03:29 +01:00

43 lines
939 B
TypeScript

import { FastifyRequest, FastifyReply, RouteOptions } from 'fastify'
import { wishlist } from '../../models'
import { wishlistResponseSchema } from '../../config/schemas'
export const getAll = <RouteOptions>{
method: 'GET',
url: '/',
schema: {
response: {
200: {
type: 'array',
items: wishlistResponseSchema,
},
},
},
handler: async () => {
return await wishlist.getAll()
},
}
interface GetBySlugUrlTextRequest extends FastifyRequest {
params: {
slugText: string
}
}
export const getBySlugUrl = <RouteOptions>{
method: 'GET',
url: '/:slugText',
schema: {
response: {
200: wishlistResponseSchema,
},
},
handler: async (request: GetBySlugUrlTextRequest, reply: FastifyReply) => {
const list = await wishlist.getBySlugUrlText(request.params.slugText, true)
if (list) {
return list
} else {
return reply.callNotFound()
}
},
}