infoalloggi-monorepo/apps/infoalloggi/src/server/api/routers/chat.ts

94 lines
2.2 KiB
TypeScript
Raw Normal View History

import { z } from "zod/v4";
2025-08-04 17:45:44 +02:00
import {
2025-08-28 18:27:07 +02:00
adminProcedure,
createTRPCRouter,
protectedProcedure,
2025-08-04 17:45:44 +02:00
} from "~/server/api/trpc";
import {
2025-08-28 18:27:07 +02:00
deleteChatHandler,
getActiveInfos,
getChatByUser,
getChatByUserIdHandler,
getChatInfo,
getUserByChatHandler,
2025-08-04 17:45:44 +02:00
} from "~/server/controllers/chat.controller";
import {
2025-08-28 18:27:07 +02:00
addChatEtichette,
getChatEtichette,
removeChatEtichette,
2025-08-04 17:45:44 +02:00
} from "~/server/controllers/etichette.controller";
import { db } from "~/server/db";
2025-08-28 18:27:07 +02:00
import { zChatId, zEtichettaId, zUserId } from "~/server/utils/zod_types";
2025-08-04 17:45:44 +02:00
export const chatRouter = createTRPCRouter({
2025-08-29 16:18:32 +02:00
addEtichettaToChat: protectedProcedure
.input(z.object({ chatId: zChatId, etichettaId: zEtichettaId }))
.mutation(async ({ input }) => {
return await addChatEtichette({
chatid: input.chatId,
db,
etichettaid: input.etichettaId,
});
}),
deleteChat: adminProcedure
2025-08-28 18:27:07 +02:00
.input(
z.object({
chatId: zChatId,
}),
)
2025-08-29 16:18:32 +02:00
.mutation(async ({ input }) => {
return await deleteChatHandler({ chatId: input.chatId });
2025-08-28 18:27:07 +02:00
}),
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
getActiveChats: adminProcedure.query(async ({ ctx }) => {
return await getActiveInfos({ userId: ctx.session.id });
}),
2025-08-29 16:18:32 +02:00
getChatEtichette: protectedProcedure
.input(z.object({ chatId: zChatId }))
.query(async ({ input }) => {
return await getChatEtichette({
chatid: input.chatId,
db,
});
}),
getChatIdByUser: adminProcedure
.input(z.object({ userId: zUserId }))
.query(async ({ input }) => {
return await getChatByUserIdHandler({ userId: input.userId });
}),
getChatInfobyId: protectedProcedure
2025-08-28 18:27:07 +02:00
.input(
z.object({
chatId: zChatId,
}),
)
2025-08-29 16:18:32 +02:00
.query(async ({ input }) => {
return await getChatInfo({ chatId: input.chatId });
2025-08-28 18:27:07 +02:00
}),
2025-08-29 16:18:32 +02:00
getSessionChats: protectedProcedure.query(async ({ ctx }) => {
return await getChatByUser({
userId: ctx.session.id,
});
}),
2025-08-04 17:45:44 +02:00
2025-08-28 18:27:07 +02:00
getUserInfosByChat: protectedProcedure
.input(
z.object({
chatId: zChatId,
}),
)
.query(async ({ input }) => {
return await getUserByChatHandler({ chatId: input.chatId });
}),
removeEtichettaFromChat: protectedProcedure
.input(z.object({ chatId: zChatId, etichettaId: zEtichettaId }))
.mutation(async ({ input }) => {
return await removeChatEtichette({
chatid: input.chatId,
2025-08-29 16:18:32 +02:00
db,
2025-08-28 18:27:07 +02:00
etichettaid: input.etichettaId,
});
}),
2025-08-04 17:45:44 +02:00
});