diff --git a/apps/api/src/database/migrations/0009_eminent_ares.sql b/apps/api/src/database/migrations/0009_eminent_ares.sql new file mode 100644 index 0000000..c49c875 --- /dev/null +++ b/apps/api/src/database/migrations/0009_eminent_ares.sql @@ -0,0 +1,7 @@ +ALTER TABLE "training_surveys" ADD COLUMN "state" integer;--> statement-breakpoint +ALTER TABLE "training_surveys" ADD COLUMN "municipality" integer;--> statement-breakpoint +ALTER TABLE "training_surveys" ADD COLUMN "parish" integer;--> statement-breakpoint +ALTER TABLE "training_surveys" ADD COLUMN "osp_responsible_email" text NOT NULL;--> statement-breakpoint +ALTER TABLE "training_surveys" ADD CONSTRAINT "training_surveys_state_states_id_fk" FOREIGN KEY ("state") REFERENCES "public"."states"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "training_surveys" ADD CONSTRAINT "training_surveys_municipality_municipalities_id_fk" FOREIGN KEY ("municipality") REFERENCES "public"."municipalities"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "training_surveys" ADD CONSTRAINT "training_surveys_parish_parishes_id_fk" FOREIGN KEY ("parish") REFERENCES "public"."parishes"("id") ON DELETE set null ON UPDATE no action; \ No newline at end of file diff --git a/apps/api/src/database/migrations/meta/0009_snapshot.json b/apps/api/src/database/migrations/meta/0009_snapshot.json new file mode 100644 index 0000000..52cb0e2 --- /dev/null +++ b/apps/api/src/database/migrations/meta/0009_snapshot.json @@ -0,0 +1,1842 @@ +{ + "id": "98995011-7d82-432c-970f-efbb710d1335", + "prevId": "3680a83d-f6d6-408a-bb21-6a54da326385", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.activity_logs": { + "name": "activity_logs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "timestamp": { + "name": "timestamp", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "activityLogs_idx": { + "name": "activityLogs_idx", + "columns": [ + { + "expression": "type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "activity_logs_user_id_users_id_fk": { + "name": "activity_logs_user_id_users_id_fk", + "tableFrom": "activity_logs", + "tableTo": "users", + "schemaTo": "auth", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "auth.roles": { + "name": "roles", + "schema": "auth", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "roles_idx": { + "name": "roles_idx", + "columns": [ + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "auth.sessions": { + "name": "sessions", + "schema": "auth", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "session_token": { + "name": "session_token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "sessions_idx": { + "name": "sessions_idx", + "columns": [ + { + "expression": "session_token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sessions_user_id_users_id_fk": { + "name": "sessions_user_id_users_id_fk", + "tableFrom": "sessions", + "tableTo": "users", + "schemaTo": "auth", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "auth.users": { + "name": "users", + "schema": "auth", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "fullname": { + "name": "fullname", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "municipality": { + "name": "municipality", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "parish": { + "name": "parish", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "is_two_factor_enabled": { + "name": "is_two_factor_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "two_factor_secret": { + "name": "two_factor_secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_email_verified": { + "name": "is_email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "users_idx": { + "name": "users_idx", + "columns": [ + { + "expression": "username", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "users_state_states_id_fk": { + "name": "users_state_states_id_fk", + "tableFrom": "users", + "tableTo": "states", + "columnsFrom": [ + "state" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "users_municipality_municipalities_id_fk": { + "name": "users_municipality_municipalities_id_fk", + "tableFrom": "users", + "tableTo": "municipalities", + "columnsFrom": [ + "municipality" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "users_parish_parishes_id_fk": { + "name": "users_parish_parishes_id_fk", + "tableFrom": "users", + "tableTo": "parishes", + "columnsFrom": [ + "parish" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_username_unique": { + "name": "users_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + }, + "users_email_unique": { + "name": "users_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "auth.user_role": { + "name": "user_role", + "schema": "auth", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "role_id": { + "name": "role_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "user_role_idx": { + "name": "user_role_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "user_role_user_id_users_id_fk": { + "name": "user_role_user_id_users_id_fk", + "tableFrom": "user_role", + "tableTo": "users", + "schemaTo": "auth", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_role_role_id_roles_id_fk": { + "name": "user_role_role_id_roles_id_fk", + "tableFrom": "user_role", + "tableTo": "roles", + "schemaTo": "auth", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "auth.verificationToken": { + "name": "verificationToken", + "schema": "auth", + "columns": { + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "expires": { + "name": "expires", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.category_type": { + "name": "category_type", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "group": { + "name": "group", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "category_typeIx0": { + "name": "category_typeIx0", + "columns": [ + { + "expression": "group", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "category_typeIx1": { + "name": "category_typeIx1", + "columns": [ + { + "expression": "description", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.localities": { + "name": "localities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "state_id": { + "name": "state_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "municipality_id": { + "name": "municipality_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "parish_id": { + "name": "parish_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "localities_index_03": { + "name": "localities_index_03", + "columns": [ + { + "expression": "state_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "municipality_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "parish_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "localities_index_00": { + "name": "localities_index_00", + "columns": [ + { + "expression": "state_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "localities_index_01": { + "name": "localities_index_01", + "columns": [ + { + "expression": "municipality_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "localities_index_02": { + "name": "localities_index_02", + "columns": [ + { + "expression": "parish_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "localities_state_id_states_id_fk": { + "name": "localities_state_id_states_id_fk", + "tableFrom": "localities", + "tableTo": "states", + "columnsFrom": [ + "state_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "localities_municipality_id_municipalities_id_fk": { + "name": "localities_municipality_id_municipalities_id_fk", + "tableFrom": "localities", + "tableTo": "municipalities", + "columnsFrom": [ + "municipality_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "localities_parish_id_parishes_id_fk": { + "name": "localities_parish_id_parishes_id_fk", + "tableFrom": "localities", + "tableTo": "parishes", + "columnsFrom": [ + "parish_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "localities_name_unique": { + "name": "localities_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.municipalities": { + "name": "municipalities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "state_id": { + "name": "state_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "municipalities_index_00": { + "name": "municipalities_index_00", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "state_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "municipalities_state_id_states_id_fk": { + "name": "municipalities_state_id_states_id_fk", + "tableFrom": "municipalities", + "tableTo": "states", + "columnsFrom": [ + "state_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.parishes": { + "name": "parishes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "municipality_id": { + "name": "municipality_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "parishes_index_00": { + "name": "parishes_index_00", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "municipality_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "parishes_municipality_id_municipalities_id_fk": { + "name": "parishes_municipality_id_municipalities_id_fk", + "tableFrom": "parishes", + "tableTo": "municipalities", + "columnsFrom": [ + "municipality_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.states": { + "name": "states", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "states_index_00": { + "name": "states_index_00", + "columns": [ + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "name", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.products": { + "name": "products", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "price": { + "name": "price", + "type": "numeric", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "stock": { + "name": "stock", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url_img": { + "name": "url_img", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "gallery": { + "name": "gallery", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'BORRADOR'" + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "products_user_id_users_id_fk": { + "name": "products_user_id_users_id_fk", + "tableFrom": "products", + "tableTo": "users", + "schemaTo": "auth", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.answers_surveys": { + "name": "answers_surveys", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "survey_id": { + "name": "survey_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "answers": { + "name": "answers", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "answers_index_00": { + "name": "answers_index_00", + "columns": [ + { + "expression": "answers", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "answers_index_01": { + "name": "answers_index_01", + "columns": [ + { + "expression": "survey_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "answers_index_02": { + "name": "answers_index_02", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "answers_surveys_survey_id_surveys_id_fk": { + "name": "answers_surveys_survey_id_surveys_id_fk", + "tableFrom": "answers_surveys", + "tableTo": "surveys", + "columnsFrom": [ + "survey_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "answers_surveys_user_id_users_id_fk": { + "name": "answers_surveys_user_id_users_id_fk", + "tableFrom": "answers_surveys", + "tableTo": "users", + "schemaTo": "auth", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.surveys": { + "name": "surveys", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target_audience": { + "name": "target_audience", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "closing_date": { + "name": "closing_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "published": { + "name": "published", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "questions": { + "name": "questions", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "surveys_index_00": { + "name": "surveys_index_00", + "columns": [ + { + "expression": "title", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.training_surveys": { + "name": "training_surveys", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "firstname": { + "name": "firstname", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "lastname": { + "name": "lastname", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "visit_date": { + "name": "visit_date", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "municipality": { + "name": "municipality", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "parish": { + "name": "parish", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "situr_code_commune": { + "name": "situr_code_commune", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "communal_council": { + "name": "communal_council", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "situr_code_communal_council": { + "name": "situr_code_communal_council", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "osp_name": { + "name": "osp_name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "osp_address": { + "name": "osp_address", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "osp_rif": { + "name": "osp_rif", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "osp_type": { + "name": "osp_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "productive_activity": { + "name": "productive_activity", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "financial_requirement_description": { + "name": "financial_requirement_description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "current_status": { + "name": "current_status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "company_constitution_year": { + "name": "company_constitution_year", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "producer_count": { + "name": "producer_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "product_description": { + "name": "product_description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "installed_capacity": { + "name": "installed_capacity", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "operational_capacity": { + "name": "operational_capacity", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "osp_responsible_fullname": { + "name": "osp_responsible_fullname", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "osp_responsible_cedula": { + "name": "osp_responsible_cedula", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "osp_responsible_rif": { + "name": "osp_responsible_rif", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "osp_responsible_phone": { + "name": "osp_responsible_phone", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "osp_responsible_email": { + "name": "osp_responsible_email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "civil_state": { + "name": "civil_state", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "family_burden": { + "name": "family_burden", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "number_of_children": { + "name": "number_of_children", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "general_observations": { + "name": "general_observations", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "paralysis_reason": { + "name": "paralysis_reason", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "photo1": { + "name": "photo1", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "photo2": { + "name": "photo2", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "photo3": { + "name": "photo3", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp (3)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "training_surveys_index_00": { + "name": "training_surveys_index_00", + "columns": [ + { + "expression": "firstname", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "training_surveys_state_states_id_fk": { + "name": "training_surveys_state_states_id_fk", + "tableFrom": "training_surveys", + "tableTo": "states", + "columnsFrom": [ + "state" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "training_surveys_municipality_municipalities_id_fk": { + "name": "training_surveys_municipality_municipalities_id_fk", + "tableFrom": "training_surveys", + "tableTo": "municipalities", + "columnsFrom": [ + "municipality" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "training_surveys_parish_parishes_id_fk": { + "name": "training_surveys_parish_parishes_id_fk", + "tableFrom": "training_surveys", + "tableTo": "parishes", + "columnsFrom": [ + "parish" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": { + "auth.gender": { + "name": "gender", + "schema": "auth", + "values": [ + "FEMENINO", + "MASCULINO" + ] + }, + "public.nationality": { + "name": "nationality", + "schema": "public", + "values": [ + "VENEZOLANO", + "EXTRANJERO" + ] + }, + "auth.status": { + "name": "status", + "schema": "auth", + "values": [ + "ACTIVE", + "INACTIVE" + ] + } + }, + "schemas": { + "auth": "auth" + }, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": { + "auth.user_access_view": { + "columns": { + "userId": { + "name": "userId", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role_id": { + "name": "role_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "role_name": { + "name": "role_name", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n SELECT\n u.id AS user_id,\n u.username,\n u.email,\n u.fullname,\n r.id AS role_id,\n r.name AS role_name\nFROM\n auth.users u\nLEFT JOIN\n auth.user_role ur ON u.id = ur.user_id \nLEFT JOIN\n auth.roles r ON ur.role_id = r.id", + "name": "user_access_view", + "schema": "auth", + "isExisting": false, + "materialized": false + }, + "public.v_product_store": { + "columns": { + "product_id": { + "name": "product_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "price": { + "name": "price", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "stock": { + "name": "stock", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "url_img": { + "name": "url_img", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "gallery": { + "name": "gallery", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "address": { + "name": "address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "fullname": { + "name": "fullname", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "phone": { + "name": "phone", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "definition": "\n select p.id as product_id, p.title, p.description, p.price, p.stock, p.url_img, p.gallery, p.address, p.status, p.user_id, u.fullname, u.email, u.phone\n from products p\n left join auth.users as u on u.id = p.user_id", + "name": "v_product_store", + "schema": "public", + "isExisting": false, + "materialized": false + }, + "public.v_surveys": { + "columns": { + "survey_id": { + "name": "survey_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "closing_date": { + "name": "closing_date", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "target_audience": { + "name": "target_audience", + "type": "varchar", + "primaryKey": false, + "notNull": false + } + }, + "definition": "select id as survey_id, title, description, created_at, closing_date, target_audience from surveys\nwhere published = true", + "name": "v_surveys", + "schema": "public", + "isExisting": false, + "materialized": false + } + }, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/api/src/database/migrations/meta/_journal.json b/apps/api/src/database/migrations/meta/_journal.json index 5658ebb..5d520e2 100644 --- a/apps/api/src/database/migrations/meta/_journal.json +++ b/apps/api/src/database/migrations/meta/_journal.json @@ -64,6 +64,13 @@ "when": 1764623430844, "tag": "0008_plain_scream", "breakpoints": true + }, + { + "idx": 9, + "version": "7", + "when": 1764883378610, + "tag": "0009_eminent_ares", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/api/src/database/schema/surveys.ts b/apps/api/src/database/schema/surveys.ts index b5eb413..22d55d0 100644 --- a/apps/api/src/database/schema/surveys.ts +++ b/apps/api/src/database/schema/surveys.ts @@ -2,6 +2,7 @@ import * as t from 'drizzle-orm/pg-core'; import { eq, lt, gte, ne, sql } from 'drizzle-orm'; import { timestamps } from '../timestamps'; import { users } from './auth'; +import { states, municipalities, parishes } from './general'; // Tabla surveys @@ -48,37 +49,47 @@ export const answersSurveys = t.pgTable( export const trainingSurveys = t.pgTable( 'training_surveys', { + // Datos basicos id: t.serial('id').primaryKey(), firstname: t.text('firstname').notNull(), lastname: t.text('lastname').notNull(), visitDate: t.timestamp('visit_date').notNull(), - productiveActivity: t.text('productive_activity').notNull(), - financialRequirementDescription: t.text('financial_requirement_description').notNull(), + // ubicacion + state: t.integer('state').references(() => states.id, { onDelete: 'set null' }), + municipality: t.integer('municipality').references(() => municipalities.id, { onDelete: 'set null' }), + parish: t.integer('parish').references(() => parishes.id, { onDelete: 'set null' }), siturCodeCommune: t.text('situr_code_commune').notNull(), communalCouncil: t.text('communal_council').notNull(), siturCodeCommunalCouncil: t.text('situr_code_communal_council').notNull(), + // datos del OSP (ORGANIZACIÓN SOCIOPRODUCTIVA) ospName: t.text('osp_name').notNull(), ospAddress: t.text('osp_address').notNull(), ospRif: t.text('osp_rif').notNull(), ospType: t.text('osp_type').notNull(), + productiveActivity: t.text('productive_activity').notNull(), + financialRequirementDescription: t.text('financial_requirement_description').notNull(), currentStatus: t.text('current_status').notNull(), companyConstitutionYear: t.integer('company_constitution_year').notNull(), producerCount: t.integer('producer_count').notNull(), productDescription: t.text('product_description').notNull(), installedCapacity: t.text('installed_capacity').notNull(), operationalCapacity: t.text('operational_capacity').notNull(), + // datos del responsable ospResponsibleFullname: t.text('osp_responsible_fullname').notNull(), ospResponsibleCedula: t.text('osp_responsible_cedula').notNull(), ospResponsibleRif: t.text('osp_responsible_rif').notNull(), ospResponsiblePhone: t.text('osp_responsible_phone').notNull(), + ospResponsibleEmail: t.text('osp_responsible_email').notNull(), civilState: t.text('civil_state').notNull(), familyBurden: t.integer('family_burden').notNull(), numberOfChildren: t.integer('number_of_children').notNull(), + // datos adicionales generalObservations: t.text('general_observations').notNull(), + paralysisReason: t.text('paralysis_reason').notNull(), + // fotos photo1: t.text('photo1').notNull(), photo2: t.text('photo2').notNull(), photo3: t.text('photo3').notNull(), - paralysisReason: t.text('paralysis_reason').notNull(), ...timestamps, }, (trainingSurveys) => ({ diff --git a/apps/api/src/features/training/dto/create-training.dto.ts b/apps/api/src/features/training/dto/create-training.dto.ts index cf64d27..d6e255d 100644 --- a/apps/api/src/features/training/dto/create-training.dto.ts +++ b/apps/api/src/features/training/dto/create-training.dto.ts @@ -22,6 +22,18 @@ export class CreateTrainingDto { @IsString() financialRequirementDescription: string; + @ApiProperty() + @IsInt() + state: number; + + @ApiProperty() + @IsInt() + municipality: number; + + @ApiProperty() + @IsInt() + parish: number; + @ApiProperty() @IsString() siturCodeCommune: string; @@ -90,6 +102,10 @@ export class CreateTrainingDto { @IsString() ospResponsiblePhone: string; + @ApiProperty() + @IsString() + ospResponsibleEmail: string; + @ApiProperty() @IsString() civilState: string; diff --git a/apps/web/feactures/training/actions/actions.ts b/apps/web/feactures/training/actions/actions.ts deleted file mode 100644 index 4d9f698..0000000 --- a/apps/web/feactures/training/actions/actions.ts +++ /dev/null @@ -1,148 +0,0 @@ -'use server'; -import { safeFetchApi } from '@/lib/fetch.api'; -import { - surveysApiResponseSchema, - CreateUser, - UsersMutate, - UpdateUser -} from '../schemas/users'; - -import { auth } from '@/lib/auth'; - - -export const getProfileAction = async () => { - const session = await auth() - const id = session?.user?.id - - const [error, response] = await safeFetchApi( - UsersMutate, - `/users/${id}`, - 'GET' - ); - if (error) throw new Error(error.message); - return response; -}; - -export const updateProfileAction = async (payload: UpdateUser) => { - const { id, ...payloadWithoutId } = payload; - - const [error, data] = await safeFetchApi( - UsersMutate, - `/users/profile/${id}`, - 'PATCH', - payloadWithoutId, - ); - - console.log(payload); - if (error) { - if (error.message === 'Email already exists') { - throw new Error('Ese correo ya está en uso'); - } - // console.error('Error:', error); - throw new Error('Error al crear el usuario'); - } - return data; -}; - -export const getUsersAction = async (params: { - page?: number; - limit?: number; - search?: string; - sortBy?: string; - sortOrder?: 'asc' | 'desc'; -}) => { - - const searchParams = new URLSearchParams({ - page: (params.page || 1).toString(), - limit: (params.limit || 10).toString(), - ...(params.search && { search: params.search }), - ...(params.sortBy && { sortBy: params.sortBy }), - ...(params.sortOrder && { sortOrder: params.sortOrder }), - }); - - const [error, response] = await safeFetchApi( - surveysApiResponseSchema, - `/users?${searchParams}`, - 'GET', - ); - - if (error) throw new Error(error.message); - - // const transformedData = response?.data ? transformSurvey(response?.data) : undefined; - - return { - data: response?.data || [], - meta: response?.meta || { - page: 1, - limit: 10, - totalCount: 0, - totalPages: 1, - hasNextPage: false, - hasPreviousPage: false, - nextPage: null, - previousPage: null, - }, - }; -} - -export const createUserAction = async (payload: CreateUser) => { - const { id, confirmPassword, ...payloadWithoutId } = payload; - - const [error, data] = await safeFetchApi( - UsersMutate, - '/users', - 'POST', - payloadWithoutId, - ); - - if (error) { - if (error.message === 'Username already exists') { - throw new Error('Ese usuario ya existe'); - } - if (error.message === 'Email already exists') { - throw new Error('Ese correo ya está en uso'); - } - // console.error('Error:', error); - throw new Error('Error al crear el usuario'); - } - - return payloadWithoutId; -}; - -export const updateUserAction = async (payload: UpdateUser) => { - try { - const { id, ...payloadWithoutId } = payload; - - const [error, data] = await safeFetchApi( - UsersMutate, - `/users/${id}`, - 'PATCH', - payloadWithoutId, - ); - - // console.log(data); - if (error) { - console.error(error); - - throw new Error(error?.message || 'Error al actualizar el usuario'); - } - return data; - } catch (error) { - console.error(error); - } -} - -export const deleteUserAction = async (id: Number) => { - const [error] = await safeFetchApi( - UsersMutate, - `/users/${id}`, - 'DELETE' - ) - - console.log(error); - - - // if (error) throw new Error(error.message || 'Error al eliminar el usuario') - - return true; -} \ No newline at end of file diff --git a/apps/web/feactures/training/columnas del excel.sql b/apps/web/feactures/training/columnas del excel.sql new file mode 100644 index 0000000..ed9e793 --- /dev/null +++ b/apps/web/feactures/training/columnas del excel.sql @@ -0,0 +1,41 @@ +-- datos basicos +nombre, +apellido, +fecha de la visita, +-->Falta +hora de la visita, +-- datos de la ubicacion +estado, +municipio, +parroquia, +nombre de la comuna, +CODIGO SITUR COMUNA, +CONSEJO COMUNAL, +CODIGO SITUR CONSEJO COMUNAL, +-- datos de la osp +actividad productiva (agricola,textil,bloquera,carpinteria,unidad de suministro), +realice una breve descripcion del requerimiento financiero, +NOMBRE DE LA ORGANIZACIÓN SOCIOPRODUCTIVA, +DIRECCIÓN DE LA ORGANIZACIÓN SOCIOPRODUCTIVA, +RIF DE LA ORGANIZACIÓN SOCIOPRODUCTIVA, +TIPO DE ORGANIZACIÓN SOCIOPRODUCTIVA, +ESTATUS ACTUAL, +AÑO DE CONSTITUCIÓN DE LA EMPRESA , +CANTIDAD DE PRODUCTORES QUE LA CONFORMAN, +BREVE DESCRIPCIÓN DEL PRODUCTO O SERVICIO QUE OFRECE, +CAPACIDAD INSTALADA, +CAPACIDAD OPERATIVA, +¿EXPLIQUE LAS RAZONES GENERALES POR LAS CUALES LA UNIDAD DE PRODUCCIÓN TUVO QUE PARALIZARSE? +-- datos del responsable +NOMBRE Y APELLIDO DEL RESPONSABLE DE LA OSP, +CÉDULA DEL RESPONSABLE (SIN PUNTOS), +RIF DEL RESPONSABLE (SIN PUNTOS), +TELÉFONOS (COLOQUE 2 NUMEROS DE TELEFONOS), +CORREO ELECTRÓNICO, +ESTADO CIVIL DEL PRODUCTOR, +CARGA FAMILIAR, +NUMERO DE HIJOS, +-- datos adicionales +OBSERVACIONES GENERALES, +-- fotos +COLOCAR TRES (3) REGISTROS FOTOGRÁFICOS VISIBLES DEL ESPACIO Y MAQUINARIAS ACTUALMENTE (OBLIGATORIO), \ No newline at end of file diff --git a/apps/web/feactures/training/components/form.tsx b/apps/web/feactures/training/components/form.tsx index 3c8872b..b02f874 100644 --- a/apps/web/feactures/training/components/form.tsx +++ b/apps/web/feactures/training/components/form.tsx @@ -52,23 +52,23 @@ export function CreateTrainingForm({ } = useCreateTraining(); const [state, setState] = React.useState(0); - const [municipality, setMunicipality] = React.useState(0); - const [disabledMunicipality, setDisabledMunicipality] = React.useState(true); - const [disabledParish, setDisabledParish] = React.useState(true); - - const { data : dataState } = useStateQuery() - const { data : dataMunicipality } = useMunicipalityQuery(state) - const { data : dataParish } = useParishQuery(municipality) - - const stateOptions = dataState?.data || [{id:0,name:'Sin estados'}] - - const municipalityOptions = Array.isArray(dataMunicipality?.data) && dataMunicipality.data.length > 0 - ? dataMunicipality.data - : [{id:0,stateId:0,name:'Sin Municipios'}] - // const parishOptions = dataParish?.data || [{id:0,municipalityId:0,name:'Sin Parroquias'}] - const parishOptions = Array.isArray(dataParish?.data) && dataParish.data.length > 0 - ? dataParish.data - : [{id:0,stateId:0,name:'Sin Parroquias'}] + const [municipality, setMunicipality] = React.useState(0); + const [disabledMunicipality, setDisabledMunicipality] = React.useState(true); + const [disabledParish, setDisabledParish] = React.useState(true); + + const { data: dataState } = useStateQuery() + const { data: dataMunicipality } = useMunicipalityQuery(state) + const { data: dataParish } = useParishQuery(municipality) + + const stateOptions = dataState?.data || [{ id: 0, name: 'Sin estados' }] + + const municipalityOptions = Array.isArray(dataMunicipality?.data) && dataMunicipality.data.length > 0 + ? dataMunicipality.data + : [{ id: 0, stateId: 0, name: 'Sin Municipios' }] + // const parishOptions = dataParish?.data || [{id:0,municipalityId:0,name:'Sin Parroquias'}] + const parishOptions = Array.isArray(dataParish?.data) && dataParish.data.length > 0 + ? dataParish.data + : [{ id: 0, stateId: 0, name: 'Sin Parroquias' }] const form = useForm({ resolver: zodResolver(trainingSchema), @@ -99,6 +99,7 @@ export function CreateTrainingForm({ familyBurden: defaultValues?.familyBurden || 0, numberOfChildren: defaultValues?.numberOfChildren || 0, generalObservations: defaultValues?.generalObservations || '', + ospResponsibleEmail: defaultValues?.ospResponsibleEmail || '', photo1: defaultValues?.photo1 || '', photo2: defaultValues?.photo2 || '', photo3: defaultValues?.photo3 || '', @@ -171,82 +172,80 @@ export function CreateTrainingForm({ ( - - Estado + control={form.control} + name="state" + render={({ field }) => ( + + Estado - ({ value: item.id.toString(), label: item.name, })) || [] - } - onValueChange={(value : any) => - {field.onChange(Number(value)); setState(value); setDisabledMunicipality(false); setDisabledParish(true)} - } - placeholder="Selecciona un estado" - defaultValue={field.value?.toString()} - // disabled={readOnly} - /> - - - )} + } + onValueChange={(value: any) => { field.onChange(Number(value)); setState(value); setDisabledMunicipality(false); setDisabledParish(true) } + } + placeholder="Selecciona un estado" + defaultValue={field.value?.toString()} + // disabled={readOnly} /> + + + )} + /> - ( - - Municipio + ( + + Municipio - ({ value: item.id.toString(), label: item.name, })) || [] - } - onValueChange={(value : any) => - {field.onChange(Number(value)); setMunicipality(value); setDisabledParish(false)} - } - placeholder="Selecciona un Municipio" - defaultValue={field.value?.toString()} - disabled={disabledMunicipality} - /> - - - )} + } + onValueChange={(value: any) => { field.onChange(Number(value)); setMunicipality(value); setDisabledParish(false) } + } + placeholder="Selecciona un Municipio" + defaultValue={field.value?.toString()} + disabled={disabledMunicipality} /> + + + )} + /> - ( - - Parroquia + ( + + Parroquia - ({ value: item.id.toString(), label: item.name, })) || [] - } - onValueChange={(value : any) => + } + onValueChange={(value: any) => field.onChange(Number(value)) - } - placeholder="Selecciona una Parroquia" - defaultValue={field.value?.toString()} - disabled={disabledParish} - /> - - - )} + } + placeholder="Selecciona una Parroquia" + defaultValue={field.value?.toString()} + disabled={disabledParish} /> + + + )} + /> {/* ( @@ -463,6 +462,14 @@ export function CreateTrainingForm({ )} /> + ( + + Correo Electrónico + + + + )} /> + ( Carga Familiar @@ -479,6 +486,11 @@ export function CreateTrainingForm({ )} /> + {/* datos adicionales */} +
+

Datos Adicionales

+
+ ( Observaciones Generales diff --git a/apps/web/feactures/training/schemas/training.ts b/apps/web/feactures/training/schemas/training.ts index ab9ac5f..70cd1bf 100644 --- a/apps/web/feactures/training/schemas/training.ts +++ b/apps/web/feactures/training/schemas/training.ts @@ -27,6 +27,7 @@ export const trainingSchema = z.object({ civilState: z.string().min(1, { message: "Estado civil es requerido" }), familyBurden: z.coerce.number().min(0, { message: "Carga familiar requerida" }), numberOfChildren: z.coerce.number().min(0, { message: "Número de hijos requerido" }), + ospResponsibleEmail: z.string().email({ message: "Correo electrónico inválido" }), generalObservations: z.string().optional().default(''), photo1: z.string().optional().default(''), photo2: z.string().optional().default(''),