62 lines
No EOL
2.1 KiB
TypeScript
62 lines
No EOL
2.1 KiB
TypeScript
import { usersId, type UsersId } from './Users';
|
|
import { appuntiGroupsId, type AppuntiGroupsId } from './AppuntiGroups';
|
|
import type { ColumnType, Selectable, Insertable, Updateable } from 'kysely';
|
|
import { z } from 'zod';
|
|
|
|
/** Identifier type for public.appunti */
|
|
export type AppuntiId = string & { __brand: 'public.appunti' };
|
|
|
|
/** Represents the table public.appunti */
|
|
export default interface AppuntiTable {
|
|
id: ColumnType<AppuntiId, AppuntiId | undefined, AppuntiId>;
|
|
|
|
name: ColumnType<string, string, string>;
|
|
|
|
descrizione: ColumnType<string | null, string | null, string | null>;
|
|
|
|
created_at: ColumnType<Date, Date | string | undefined, Date | string>;
|
|
|
|
userid: ColumnType<UsersId | null, UsersId | null, UsersId | null>;
|
|
|
|
appunti_group_id: ColumnType<AppuntiGroupsId, AppuntiGroupsId, AppuntiGroupsId>;
|
|
|
|
posizione: ColumnType<number | null, number | null, number | null>;
|
|
}
|
|
|
|
export type Appunti = Selectable<AppuntiTable>;
|
|
|
|
export type NewAppunti = Insertable<AppuntiTable>;
|
|
|
|
export type AppuntiUpdate = Updateable<AppuntiTable>;
|
|
|
|
export const appuntiId = z.uuid().transform(value => value as AppuntiId);
|
|
|
|
export const AppuntiSchema = z.object({
|
|
id: appuntiId,
|
|
name: z.string(),
|
|
descrizione: z.string().nullable(),
|
|
created_at: z.date(),
|
|
userid: usersId.nullable(),
|
|
appunti_group_id: appuntiGroupsId,
|
|
posizione: z.number().nullable(),
|
|
});
|
|
|
|
export const NewAppuntiSchema = z.object({
|
|
id: appuntiId.optional(),
|
|
name: z.string(),
|
|
descrizione: z.string().optional().nullable(),
|
|
created_at: z.union([z.date(), z.string()]).pipe(z.coerce.date()).optional(),
|
|
userid: usersId.optional().nullable(),
|
|
appunti_group_id: appuntiGroupsId,
|
|
posizione: z.number().optional().nullable(),
|
|
});
|
|
|
|
export const AppuntiUpdateSchema = z.object({
|
|
id: appuntiId.optional(),
|
|
name: z.string().optional(),
|
|
descrizione: z.string().optional().nullable(),
|
|
created_at: z.union([z.date(), z.string()]).pipe(z.coerce.date()).optional(),
|
|
userid: usersId.optional().nullable(),
|
|
appunti_group_id: appuntiGroupsId.optional(),
|
|
posizione: z.number().optional().nullable(),
|
|
}); |