53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import { createInsertSchema, createSelectSchema } from 'drizzle-typebox';
|
|
import Elysia, { t } from 'elysia';
|
|
import { mapTable } from '../db/schema';
|
|
import { getByCity } from '../services/map/getByCity';
|
|
import { authMiddleware } from '../middlewares/auth';
|
|
import { createMapPoint } from '../services/map/createMapPoint';
|
|
import { updateMapPoint } from '../services/map/updateMapPoint';
|
|
import { deleteMapPoint } from '../services/map/deleteMapPoint';
|
|
|
|
const getMapPointsSchema = createSelectSchema(mapTable);
|
|
|
|
const createMapPointSchema = createInsertSchema(mapTable);
|
|
|
|
export const mapController = new Elysia({
|
|
prefix: '/map',
|
|
})
|
|
.get('/', async ({ query: { city } }) => await getByCity(city), {
|
|
response: {
|
|
200: t.Array(getMapPointsSchema),
|
|
404: t.ObjectString({}),
|
|
500: t.ObjectString({}),
|
|
},
|
|
query: t.Object({
|
|
city: t.String(),
|
|
}),
|
|
})
|
|
.use(authMiddleware)
|
|
.post('/', async ({ body }) => await createMapPoint(body), {
|
|
response: { 200: getMapPointsSchema, 500: t.ObjectString({}) },
|
|
body: createMapPointSchema,
|
|
})
|
|
.put(
|
|
'/:id',
|
|
async ({ body, params: { id } }) => await updateMapPoint(id, body),
|
|
{
|
|
response: {
|
|
200: getMapPointsSchema,
|
|
404: t.ObjectString({}),
|
|
500: t.ObjectString({}),
|
|
},
|
|
params: t.Object({ id: t.String({ format: 'uuid' }) }),
|
|
body: createMapPointSchema,
|
|
}
|
|
)
|
|
.delete('/:id', async ({ params: { id } }) => await deleteMapPoint(id), {
|
|
response: {
|
|
200: getMapPointsSchema,
|
|
404: t.ObjectString({}),
|
|
500: t.ObjectString({}),
|
|
},
|
|
params: t.Object({ id: t.String({ format: 'uuid' }) }),
|
|
});
|