infoalloggi-monorepo/apps/infoalloggi/src/schemas/public/Messages.ts
Marco Pedone 60e4b187bf Refactor: Update Zod schemas and replace custom types with imported schemas across various files
- 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>
2026-04-28 20:32:19 +02:00

67 lines
No EOL
2.2 KiB
TypeScript

import { chatsChatid, type ChatsChatid } from './Chats';
import { usersId, type UsersId } from './Users';
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
import { z } from 'zod';
/** Identifier type for public.messages */
export type MessagesMessageid = string & { __brand: 'public.messages' };
/** Represents the table public.messages */
export default interface MessagesTable {
messageid: ColumnType<MessagesMessageid, MessagesMessageid | undefined, MessagesMessageid>;
chatid: ColumnType<ChatsChatid, ChatsChatid, ChatsChatid>;
message: ColumnType<string, string, string>;
time: ColumnType<Date, Date | string, Date | string>;
isread: ColumnType<boolean, boolean | undefined, boolean>;
sender: ColumnType<UsersId, UsersId, UsersId>;
reply_to_id: ColumnType<MessagesMessageid | null, MessagesMessageid | null, MessagesMessageid | null>;
is_forwarded: ColumnType<boolean, boolean | undefined, boolean>;
}
export type Messages = Selectable<MessagesTable>;
export type NewMessages = Insertable<MessagesTable>;
export type MessagesUpdate = Updateable<MessagesTable>;
export const messagesMessageid = z.uuid().transform(value => value as MessagesMessageid);
export const MessagesSchema = z.object({
messageid: messagesMessageid,
chatid: chatsChatid,
message: z.string(),
time: z.date(),
isread: z.boolean(),
sender: usersId,
reply_to_id: messagesMessageid.nullable(),
is_forwarded: z.boolean(),
});
export const NewMessagesSchema = z.object({
messageid: messagesMessageid.optional(),
chatid: chatsChatid,
message: z.string(),
time: z.union([z.date(), z.string()]).pipe(z.coerce.date()),
isread: z.boolean().optional(),
sender: usersId,
reply_to_id: messagesMessageid.optional().nullable(),
is_forwarded: z.boolean().optional(),
});
export const MessagesUpdateSchema = z.object({
messageid: messagesMessageid.optional(),
chatid: chatsChatid.optional(),
message: z.string().optional(),
time: z.union([z.date(), z.string()]).pipe(z.coerce.date()).optional(),
isread: z.boolean().optional(),
sender: usersId.optional(),
reply_to_id: messagesMessageid.optional().nullable(),
is_forwarded: z.boolean().optional(),
});