- Replaced custom Zod types with imported schemas in stripe router and user router. - Updated payment controller to use new enum imports for order types and payment statuses. - Refactored payment tests to utilize the new enum structure. - Removed deprecated zod_types file and created new zod_chat_types file for chat-related schemas. - Adjusted service files to align with the new order type enums and schemas. - Enhanced the Caratteristiche type definition using Zod for better validation. Co-authored-by: Copilot <copilot@github.com>
114 lines
2.5 KiB
TypeScript
114 lines
2.5 KiB
TypeScript
import { z } from "zod/v4";
|
|
import { UsersUpdateSchema, usersId } from "~/schemas/public/Users";
|
|
import { UsersAnagraficaUpdateSchema } from "~/schemas/public/UsersAnagrafica";
|
|
import {
|
|
adminProcedure,
|
|
createTRPCRouter,
|
|
protectedProcedure,
|
|
} from "~/server/api/trpc";
|
|
import {
|
|
blockUserHandler,
|
|
deleteUserHandler,
|
|
editAccountHandler,
|
|
editAnagraficaHandler,
|
|
genUserIntestazione,
|
|
getActiveUserWithoutChatHandler,
|
|
getUserHandler,
|
|
getUsersWithChatInfoHandler,
|
|
} from "~/server/controllers/user.controller";
|
|
import { db } from "~/server/db";
|
|
import { getClientProfilo } from "~/server/services/user.service";
|
|
|
|
export const usersRouter = createTRPCRouter({
|
|
getUser: protectedProcedure
|
|
.input(
|
|
z.object({
|
|
id: usersId,
|
|
}),
|
|
)
|
|
.query(async ({ input }) => {
|
|
return await getUserHandler({ db, id: input.id });
|
|
}),
|
|
|
|
getUsers: adminProcedure.query(async () => {
|
|
return await db
|
|
.selectFrom("users")
|
|
.selectAll()
|
|
.orderBy("id", "desc")
|
|
.execute();
|
|
}),
|
|
getAdmins: adminProcedure.query(async () => {
|
|
return await db
|
|
.selectFrom("users")
|
|
.selectAll()
|
|
.where("isAdmin", "=", true)
|
|
.orderBy("id", "desc")
|
|
.execute();
|
|
}),
|
|
getClientProfilo: protectedProcedure
|
|
.input(
|
|
z.object({
|
|
userId: usersId,
|
|
}),
|
|
)
|
|
.query(async ({ input }) => {
|
|
return getClientProfilo({
|
|
db,
|
|
userId: input.userId,
|
|
});
|
|
}),
|
|
blockUser: adminProcedure
|
|
.input(
|
|
z.object({
|
|
id: usersId,
|
|
}),
|
|
)
|
|
.mutation(async ({ input }) => {
|
|
return await blockUserHandler(input.id);
|
|
}),
|
|
deleteUser: adminProcedure
|
|
.input(
|
|
z.object({
|
|
id: usersId,
|
|
}),
|
|
)
|
|
.mutation(async ({ input }) => {
|
|
return await deleteUserHandler(input.id);
|
|
}),
|
|
editUser: protectedProcedure
|
|
.input(
|
|
z.object({
|
|
id: usersId,
|
|
data: UsersUpdateSchema,
|
|
}),
|
|
)
|
|
.mutation(async ({ input }) => {
|
|
return await editAccountHandler({ ...input });
|
|
}),
|
|
editUserAnagrafica: protectedProcedure
|
|
.input(
|
|
z.object({
|
|
userId: usersId,
|
|
data: UsersAnagraficaUpdateSchema,
|
|
}),
|
|
)
|
|
.mutation(async ({ input }) => {
|
|
return await editAnagraficaHandler({ ...input });
|
|
}),
|
|
getActiveUsersWithoutChat: adminProcedure.query(async () => {
|
|
return await getActiveUserWithoutChatHandler({ db });
|
|
}),
|
|
|
|
getUsersWChatInfo: adminProcedure.query(async () => {
|
|
return await getUsersWithChatInfoHandler();
|
|
}),
|
|
genIntestazione: adminProcedure
|
|
.input(
|
|
z.object({
|
|
userId: usersId,
|
|
}),
|
|
)
|
|
.mutation(async ({ input }) => {
|
|
return await genUserIntestazione(input.userId);
|
|
}),
|
|
});
|