base con autenticacion, registro, modulo encuestas
This commit is contained in:
19
apps/web/feactures/users/schemas/account-plan-options.ts
Normal file
19
apps/web/feactures/users/schemas/account-plan-options.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
export const ACCOUNT_TYPES = {
|
||||
activo: 'Activo',
|
||||
pasivo: 'Pasivo',
|
||||
patrimonio: 'Patrimonio',
|
||||
ingreso: 'Ingreso',
|
||||
gasto: 'Gasto',
|
||||
costo: 'Costo',
|
||||
cuenta_orden: 'Cuenta de Orden',
|
||||
} as const;
|
||||
|
||||
export const ACCOUNT_LEVELS = {
|
||||
1: 'Nivel 1 - Cuenta Principal',
|
||||
2: 'Nivel 2 - Subcuenta',
|
||||
3: 'Nivel 3 - Cuenta Detallada',
|
||||
4: 'Nivel 4 - Cuenta Auxiliar',
|
||||
} as const;
|
||||
|
||||
export type AccountType = keyof typeof ACCOUNT_TYPES;
|
||||
export type AccountLevel = keyof typeof ACCOUNT_LEVELS;
|
||||
83
apps/web/feactures/users/schemas/account-plan.schema.ts
Normal file
83
apps/web/feactures/users/schemas/account-plan.schema.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export const accountPlanSchema = z
|
||||
.object({
|
||||
id: z.number().optional(),
|
||||
savingBankId: z.number(),
|
||||
code: z
|
||||
.string()
|
||||
.min(1, 'El código es requerido')
|
||||
.max(50, 'El código no puede tener más de 50 caracteres')
|
||||
.regex(/^[\d.]+$/, 'El código debe contener solo números y puntos'),
|
||||
name: z
|
||||
.string()
|
||||
.min(1, 'El nombre es requerido')
|
||||
.max(100, 'El nombre no puede tener más de 100 caracteres'),
|
||||
type: z.enum(
|
||||
[
|
||||
'activo',
|
||||
'pasivo',
|
||||
'patrimonio',
|
||||
'ingreso',
|
||||
'gasto',
|
||||
'costo',
|
||||
'cuenta_orden',
|
||||
],
|
||||
{
|
||||
required_error: 'El tipo de cuenta es requerido',
|
||||
invalid_type_error: 'Tipo de cuenta inválido',
|
||||
},
|
||||
),
|
||||
description: z.string().optional().nullable(),
|
||||
level: z
|
||||
.number()
|
||||
.min(1, 'El nivel debe ser mayor a 0')
|
||||
.max(4, 'El nivel no puede ser mayor a 4'),
|
||||
parent_account_id: z.number().nullable(),
|
||||
created_at: z.string().optional(),
|
||||
updated_at: z.string().optional(),
|
||||
})
|
||||
.refine(
|
||||
(data) => {
|
||||
if (data.level > 1 && !data.parent_account_id) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
{
|
||||
message: 'Las cuentas de nivel superior a 1 requieren una cuenta padre',
|
||||
path: ['parent_account_id'],
|
||||
},
|
||||
);
|
||||
|
||||
export type AccountPlan = z.infer<typeof accountPlanSchema>;
|
||||
|
||||
// Response schemas for the API
|
||||
export const accountPlanResponseSchema = z.object({
|
||||
message: z.string(),
|
||||
data: accountPlanSchema,
|
||||
});
|
||||
|
||||
export const accountPlanDeleteResponseSchema = z.object({
|
||||
message: z.string(),
|
||||
});
|
||||
|
||||
export const accountPlanListResponseSchema = z.object({
|
||||
message: z.string(),
|
||||
data: z.array(accountPlanSchema),
|
||||
});
|
||||
|
||||
export const accountPlanPaginationResponseSchema = z.object({
|
||||
message: z.string(),
|
||||
data: z.array(accountPlanSchema),
|
||||
meta: z.object({
|
||||
page: z.number(),
|
||||
limit: z.number(),
|
||||
totalCount: z.number(),
|
||||
totalPages: z.number(),
|
||||
hasNextPage: z.boolean(),
|
||||
hasPreviousPage: z.boolean(),
|
||||
nextPage: z.number().nullable(),
|
||||
previousPage: z.number().nullable(),
|
||||
}),
|
||||
});
|
||||
6
apps/web/feactures/users/schemas/surveys-options.ts
Normal file
6
apps/web/feactures/users/schemas/surveys-options.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export const PUBLISHED_TYPES = {
|
||||
published: 'Publicada',
|
||||
draft: 'Borrador',
|
||||
} as const;
|
||||
|
||||
export type PublishedType = keyof typeof PUBLISHED_TYPES;
|
||||
67
apps/web/feactures/users/schemas/users.ts
Normal file
67
apps/web/feactures/users/schemas/users.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
export type SurveyTable = z.infer<typeof user>;
|
||||
export type CreateUser = z.infer<typeof createUser>;
|
||||
export type UpdateUser = z.infer<typeof updateUser>;
|
||||
|
||||
export const user = z.object({
|
||||
id: z.number().optional(),
|
||||
username: z.string(),
|
||||
email: z.string(),
|
||||
fullname: z.string(),
|
||||
phone: z.string().nullable(),
|
||||
isActive: z.boolean(),
|
||||
role: z.string(),
|
||||
state: z.string().optional().nullable(),
|
||||
municipality: z.string().optional().nullable(),
|
||||
parish: z.string().optional().nullable(),
|
||||
});
|
||||
|
||||
export const createUser = z.object({
|
||||
id: z.number().optional(),
|
||||
username: z.string().min(5, { message: "Debe de tener 5 o más caracteres" }),
|
||||
password: z.string().min(8, { message: "Debe de tener 8 o más caracteres" }),
|
||||
email: z.string().email({ message: "Correo no válido" }),
|
||||
fullname: z.string(),
|
||||
phone: z.string(),
|
||||
confirmPassword: z.string(),
|
||||
role: z.number()
|
||||
})
|
||||
.refine((data) => data.password === data.confirmPassword, {
|
||||
message: 'La contraseña no coincide',
|
||||
path: ['confirmPassword'],
|
||||
})
|
||||
|
||||
export const updateUser = z.object({
|
||||
id: z.number(),
|
||||
username: z.string().min(5, { message: "Debe de tener 5 o más caracteres" }).or(z.literal('')),
|
||||
password: z.string().min(6, { message: "Debe de tener 6 o más caracteres" }).or(z.literal('')),
|
||||
email: z.string().email({ message: "Correo no válido" }).or(z.literal('')),
|
||||
fullname: z.string().optional(),
|
||||
phone: z.string().optional(),
|
||||
role: z.number().optional(),
|
||||
isActive: z.boolean().optional(),
|
||||
state: z.number().optional().nullable(),
|
||||
municipality: z.number().optional().nullable(),
|
||||
parish: z.number().optional().nullable(),
|
||||
})
|
||||
|
||||
export const surveysApiResponseSchema = z.object({
|
||||
message: z.string(),
|
||||
data: z.array(user),
|
||||
meta: z.object({
|
||||
page: z.number(),
|
||||
limit: z.number(),
|
||||
totalCount: z.number(),
|
||||
totalPages: z.number(),
|
||||
hasNextPage: z.boolean(),
|
||||
hasPreviousPage: z.boolean(),
|
||||
nextPage: z.number().nullable(),
|
||||
previousPage: z.number().nullable(),
|
||||
}),
|
||||
})
|
||||
|
||||
export const UsersMutate = z.object({
|
||||
message: z.string(),
|
||||
data: user,
|
||||
})
|
||||
Reference in New Issue
Block a user