- Introduced a new page for managing appunti in the admin area. - Created AppuntiProvider to manage appunti state and API interactions. - Added schemas for appunti and appunti groups. - Implemented CRUD operations for appunti and appunti groups in the API. - Removed potenziali related files and services as part of the refactor. - Updated the public schema to include appunti and appunti groups. - Improved error handling in the appunti service. Co-authored-by: Copilot <copilot@github.com>
76 lines
1.7 KiB
TypeScript
76 lines
1.7 KiB
TypeScript
import z from "zod";
|
|
import {
|
|
AppuntiUpdateSchema,
|
|
appuntiId,
|
|
NewAppuntiSchema,
|
|
} from "~/schemas/public/Appunti";
|
|
import { appuntiGroupsId } from "~/schemas/public/AppuntiGroups";
|
|
|
|
import { adminProcedure, createTRPCRouter } from "~/server/api/trpc";
|
|
import {
|
|
type AppuntiData,
|
|
addAppunti,
|
|
addAppuntiGroup,
|
|
deleteAppunti,
|
|
deleteAppuntiGroup,
|
|
getAppunti,
|
|
getAppuntiGroups,
|
|
updateAppunti,
|
|
updateAppunto,
|
|
} from "~/server/services/appunti.service";
|
|
|
|
export const appuntiRouter = createTRPCRouter({
|
|
getAppunti: adminProcedure.query(async () => {
|
|
return await getAppunti();
|
|
}),
|
|
getAppuntiGroups: adminProcedure.query(async () => {
|
|
return await getAppuntiGroups();
|
|
}),
|
|
addAppunti: adminProcedure
|
|
.input(
|
|
z.object({
|
|
data: NewAppuntiSchema,
|
|
}),
|
|
)
|
|
.mutation(async ({ input }) => {
|
|
return await addAppunti(input.data);
|
|
}),
|
|
updateAppunti: adminProcedure
|
|
.input(
|
|
z.object({
|
|
data: z.custom<AppuntiData[]>(),
|
|
}),
|
|
)
|
|
.mutation(async ({ input }) => {
|
|
return await updateAppunti(input.data);
|
|
}),
|
|
updateAppunto: adminProcedure
|
|
.input(
|
|
z.object({
|
|
appuntiId: appuntiId,
|
|
data: AppuntiUpdateSchema,
|
|
}),
|
|
)
|
|
.mutation(async ({ input }) => {
|
|
return await updateAppunto(input.appuntiId, input.data);
|
|
}),
|
|
deleteAppunti: adminProcedure.input(appuntiId).mutation(async ({ input }) => {
|
|
return await deleteAppunti(input);
|
|
}),
|
|
|
|
addAppuntiGroup: adminProcedure
|
|
.input(
|
|
z.object({
|
|
name: z.string().min(1).max(255),
|
|
}),
|
|
)
|
|
.mutation(async ({ input }) => {
|
|
return await addAppuntiGroup({ name: input.name });
|
|
}),
|
|
|
|
deleteAppuntiGroup: adminProcedure
|
|
.input(appuntiGroupsId)
|
|
.mutation(async ({ input }) => {
|
|
return await deleteAppuntiGroup(input);
|
|
}),
|
|
});
|