146 lines
2.8 KiB
TypeScript
146 lines
2.8 KiB
TypeScript
import { FastifyInstance } from "fastify";
|
|
import { $task } from "./task.schema";
|
|
import {
|
|
createTaskHandler,
|
|
deleteTaskHandler,
|
|
getTaskHandler,
|
|
listTaskHandler,
|
|
newFilesHandler,
|
|
searchTaskHandler,
|
|
updateTaskHandler,
|
|
} from "./task.controller";
|
|
import { noteRoutes } from "../note/note.route";
|
|
import { getUniqueValuesTasks } from "./task.service";
|
|
|
|
export async function taskRoutes(fastify: FastifyInstance) {
|
|
fastify.post(
|
|
"/",
|
|
{
|
|
schema: {
|
|
body: $task("createTaskInput"),
|
|
},
|
|
config: { requiredClaims: ["task:write"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
createTaskHandler
|
|
);
|
|
|
|
fastify.get(
|
|
"/:taskId",
|
|
{
|
|
schema: {
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
taskId: { type: "string" },
|
|
},
|
|
},
|
|
},
|
|
config: { requiredClaims: ["task:read"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
getTaskHandler
|
|
);
|
|
|
|
fastify.get(
|
|
"/",
|
|
{
|
|
schema: {
|
|
querystring: $task("pageQueryParams"),
|
|
},
|
|
|
|
config: { requiredClaims: ["task:read"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
listTaskHandler
|
|
);
|
|
|
|
fastify.patch(
|
|
"/:taskId",
|
|
{
|
|
schema: {
|
|
params: {
|
|
type: "object",
|
|
properties: { taskId: { type: "string" } },
|
|
},
|
|
body: $task("updateTaskInput"),
|
|
},
|
|
},
|
|
updateTaskHandler
|
|
);
|
|
|
|
fastify.delete(
|
|
"/:taskId",
|
|
{
|
|
schema: {
|
|
params: {
|
|
type: "object",
|
|
properties: { taskId: { type: "string" } },
|
|
},
|
|
},
|
|
config: { requiredClaims: ["task:delete"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
deleteTaskHandler
|
|
);
|
|
|
|
fastify.get(
|
|
"/search",
|
|
{
|
|
schema: {
|
|
querystring: $task("pageQueryParams"),
|
|
},
|
|
config: { requiredClaims: ["task:read"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
searchTaskHandler
|
|
);
|
|
|
|
fastify.post(
|
|
"/:taskId/files",
|
|
{
|
|
schema: {
|
|
body: $task("uploadTaskInput"),
|
|
},
|
|
config: { requiredClaims: ["rts:write"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
newFilesHandler
|
|
);
|
|
|
|
fastify.get(
|
|
"/fields/:field",
|
|
{
|
|
schema: {
|
|
params: {
|
|
type: "object",
|
|
properties: {
|
|
field: { type: "string" },
|
|
},
|
|
},
|
|
},
|
|
config: { requiredClaims: ["rts:read"] },
|
|
preHandler: [fastify.authorize],
|
|
},
|
|
async (req, res) => {
|
|
const { field } = req.params as { field: string };
|
|
|
|
try {
|
|
const uniqueValues = await getUniqueValuesTasks(
|
|
field,
|
|
req.user.tenantId
|
|
);
|
|
return res.code(200).send(uniqueValues);
|
|
} catch (err) {
|
|
return err;
|
|
}
|
|
}
|
|
);
|
|
|
|
await noteRoutes(fastify, {
|
|
read: "task:read",
|
|
write: "task:write",
|
|
delete: "task:delete",
|
|
});
|
|
}
|