diff --git a/db/migrations/905-add_report_city.sql b/db/migrations/905-add_report_city.sql new file mode 100644 index 00000000..6c65c7e4 --- /dev/null +++ b/db/migrations/905-add_report_city.sql @@ -0,0 +1 @@ +ALTER TABLE "report" ADD COLUMN "city" TEXT; \ No newline at end of file diff --git a/packages/electric-client/src/generated/client/index.ts b/packages/electric-client/src/generated/client/index.ts index f7eeb38c..3a118115 100644 --- a/packages/electric-client/src/generated/client/index.ts +++ b/packages/electric-client/src/generated/client/index.ts @@ -23,7 +23,7 @@ export const Pdf_snapshotScalarFieldEnumSchema = z.enum(['id','report_id','html' export const QueryModeSchema = z.enum(['default','insensitive']); -export const ReportScalarFieldEnumSchema = z.enum(['id','title','projectDescription','redactedBy','meetDate','applicantName','applicantAddress','projectCadastralRef','projectSpaceType','decision','precisions','contacts','furtherInformation','createdBy','createdAt','serviceInstructeur','pdf','disabled','udap_id','redactedById','applicantEmail']); +export const ReportScalarFieldEnumSchema = z.enum(['id','title','projectDescription','redactedBy','meetDate','applicantName','applicantAddress','projectCadastralRef','projectSpaceType','decision','precisions','contacts','furtherInformation','createdBy','createdAt','serviceInstructeur','pdf','disabled','udap_id','redactedById','applicantEmail','city']); export const Service_instructeursScalarFieldEnumSchema = z.enum(['id','full_name','short_name','email','tel','udap_id']); @@ -118,6 +118,7 @@ export const ReportSchema = z.object({ udap_id: z.string().nullable(), redactedById: z.string().nullable(), applicantEmail: z.string().nullable(), + city: z.string().nullable(), }) export type Report = z.infer @@ -263,6 +264,7 @@ export const ReportSelectSchema: z.ZodType = z.object({ udap_id: z.boolean().optional(), redactedById: z.boolean().optional(), applicantEmail: z.boolean().optional(), + city: z.boolean().optional(), user: z.union([z.boolean(),z.lazy(() => UserArgsSchema)]).optional(), }).strict() @@ -562,6 +564,7 @@ export const ReportWhereInputSchema: z.ZodType = z.obje udap_id: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), redactedById: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), applicantEmail: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), + city: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), user: z.union([ z.lazy(() => UserRelationFilterSchema),z.lazy(() => UserWhereInputSchema) ]).optional(), }).strict(); @@ -587,6 +590,7 @@ export const ReportOrderByWithRelationInputSchema: z.ZodType SortOrderSchema).optional(), redactedById: z.lazy(() => SortOrderSchema).optional(), applicantEmail: z.lazy(() => SortOrderSchema).optional(), + city: z.lazy(() => SortOrderSchema).optional(), user: z.lazy(() => UserOrderByWithRelationInputSchema).optional() }).strict(); @@ -616,6 +620,7 @@ export const ReportOrderByWithAggregationInputSchema: z.ZodType SortOrderSchema).optional(), redactedById: z.lazy(() => SortOrderSchema).optional(), applicantEmail: z.lazy(() => SortOrderSchema).optional(), + city: z.lazy(() => SortOrderSchema).optional(), _count: z.lazy(() => ReportCountOrderByAggregateInputSchema).optional(), _avg: z.lazy(() => ReportAvgOrderByAggregateInputSchema).optional(), _max: z.lazy(() => ReportMaxOrderByAggregateInputSchema).optional(), @@ -648,6 +653,7 @@ export const ReportScalarWhereWithAggregatesInputSchema: z.ZodType StringNullableWithAggregatesFilterSchema),z.string() ]).optional().nullable(), redactedById: z.union([ z.lazy(() => StringNullableWithAggregatesFilterSchema),z.string() ]).optional().nullable(), applicantEmail: z.union([ z.lazy(() => StringNullableWithAggregatesFilterSchema),z.string() ]).optional().nullable(), + city: z.union([ z.lazy(() => StringNullableWithAggregatesFilterSchema),z.string() ]).optional().nullable(), }).strict(); export const Service_instructeursWhereInputSchema: z.ZodType = z.object({ @@ -1054,6 +1060,7 @@ export const ReportCreateInputSchema: z.ZodType = z.ob udap_id: z.string().optional().nullable(), redactedById: z.string().optional().nullable(), applicantEmail: z.string().optional().nullable(), + city: z.string().optional().nullable(), user: z.lazy(() => UserCreateNestedOneWithoutReportInputSchema) }).strict(); @@ -1078,7 +1085,8 @@ export const ReportUncheckedCreateInputSchema: z.ZodType = z.object({ @@ -1102,6 +1110,7 @@ export const ReportUpdateInputSchema: z.ZodType = z.ob udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), applicantEmail: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + city: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), user: z.lazy(() => UserUpdateOneRequiredWithoutReportNestedInputSchema).optional() }).strict(); @@ -1127,6 +1136,7 @@ export const ReportUncheckedUpdateInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), applicantEmail: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + city: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); export const ReportCreateManyInputSchema: z.ZodType = z.object({ @@ -1150,7 +1160,8 @@ export const ReportCreateManyInputSchema: z.ZodType = z.object({ @@ -1174,6 +1185,7 @@ export const ReportUpdateManyMutationInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), applicantEmail: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + city: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); export const ReportUncheckedUpdateManyInputSchema: z.ZodType = z.object({ @@ -1198,6 +1210,7 @@ export const ReportUncheckedUpdateManyInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), applicantEmail: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + city: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); export const Service_instructeursCreateInputSchema: z.ZodType = z.object({ @@ -1695,7 +1708,8 @@ export const ReportCountOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional(), udap_id: z.lazy(() => SortOrderSchema).optional(), redactedById: z.lazy(() => SortOrderSchema).optional(), - applicantEmail: z.lazy(() => SortOrderSchema).optional() + applicantEmail: z.lazy(() => SortOrderSchema).optional(), + city: z.lazy(() => SortOrderSchema).optional() }).strict(); export const ReportAvgOrderByAggregateInputSchema: z.ZodType = z.object({ @@ -1723,7 +1737,8 @@ export const ReportMaxOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional(), udap_id: z.lazy(() => SortOrderSchema).optional(), redactedById: z.lazy(() => SortOrderSchema).optional(), - applicantEmail: z.lazy(() => SortOrderSchema).optional() + applicantEmail: z.lazy(() => SortOrderSchema).optional(), + city: z.lazy(() => SortOrderSchema).optional() }).strict(); export const ReportMinOrderByAggregateInputSchema: z.ZodType = z.object({ @@ -1747,7 +1762,8 @@ export const ReportMinOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional(), udap_id: z.lazy(() => SortOrderSchema).optional(), redactedById: z.lazy(() => SortOrderSchema).optional(), - applicantEmail: z.lazy(() => SortOrderSchema).optional() + applicantEmail: z.lazy(() => SortOrderSchema).optional(), + city: z.lazy(() => SortOrderSchema).optional() }).strict(); export const ReportSumOrderByAggregateInputSchema: z.ZodType = z.object({ @@ -2639,7 +2655,8 @@ export const ReportCreateWithoutUserInputSchema: z.ZodType = z.object({ @@ -2662,7 +2679,8 @@ export const ReportUncheckedCreateWithoutUserInputSchema: z.ZodType = z.object({ @@ -2793,6 +2811,7 @@ export const ReportScalarWhereInputSchema: z.ZodType StringNullableFilterSchema),z.string() ]).optional().nullable(), redactedById: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), applicantEmail: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), + city: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), }).strict(); export const UdapUpsertWithoutUserInputSchema: z.ZodType = z.object({ @@ -2886,7 +2905,8 @@ export const ReportCreateManyUserInputSchema: z.ZodType = z.object({ @@ -2934,6 +2954,7 @@ export const ReportUpdateWithoutUserInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), applicantEmail: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + city: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); export const ReportUncheckedUpdateWithoutUserInputSchema: z.ZodType = z.object({ @@ -2957,6 +2978,7 @@ export const ReportUncheckedUpdateWithoutUserInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), applicantEmail: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + city: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); export const ReportUncheckedUpdateManyWithoutReportInputSchema: z.ZodType = z.object({ @@ -2980,6 +3002,7 @@ export const ReportUncheckedUpdateManyWithoutReportInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), applicantEmail: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + city: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); ///////////////////////////////////////// @@ -4090,6 +4113,10 @@ export const tableSchemas = { [ "applicantEmail", "TEXT" + ], + [ + "city", + "TEXT" ] ]), relations: [ diff --git a/packages/electric-client/src/generated/client/migrations.ts b/packages/electric-client/src/generated/client/migrations.ts index f08dcb6a..499a34d3 100644 --- a/packages/electric-client/src/generated/client/migrations.ts +++ b/packages/electric-client/src/generated/client/migrations.ts @@ -177,5 +177,24 @@ export default [ "CREATE TRIGGER delete_main_pdf_snapshot_into_oplog\n AFTER DELETE ON \"main\".\"pdf_snapshot\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'pdf_snapshot')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'pdf_snapshot', 'DELETE', json_patch('{}', json_object('id', old.\"id\")), NULL, json_object('html', old.\"html\", 'id', old.\"id\", 'report', old.\"report\", 'report_id', old.\"report_id\", 'user_id', old.\"user_id\"), NULL);\nEND;" ], "version": "904" + }, + { + "statements": [ + "ALTER TABLE \"report\" ADD COLUMN \"city\" TEXT;\n", + "INSERT OR IGNORE INTO _electric_trigger_settings (namespace, tablename, flag) VALUES ('main', 'report', 1);", + "DROP TRIGGER IF EXISTS update_ensure_main_report_primarykey;", + "CREATE TRIGGER update_ensure_main_report_primarykey\n BEFORE UPDATE ON \"main\".\"report\"\nBEGIN\n SELECT\n CASE\n WHEN old.\"id\" != new.\"id\" THEN\n \t\tRAISE (ABORT, 'cannot change the value of column id as it belongs to the primary key')\n END;\nEND;", + "DROP TRIGGER IF EXISTS insert_main_report_into_oplog;", + "CREATE TRIGGER insert_main_report_into_oplog\n AFTER INSERT ON \"main\".\"report\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'report')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'report', 'INSERT', json_patch('{}', json_object('id', new.\"id\")), json_object('applicantAddress', new.\"applicantAddress\", 'applicantEmail', new.\"applicantEmail\", 'applicantName', new.\"applicantName\", 'city', new.\"city\", 'contacts', new.\"contacts\", 'createdAt', new.\"createdAt\", 'createdBy', new.\"createdBy\", 'decision', new.\"decision\", 'disabled', new.\"disabled\", 'furtherInformation', new.\"furtherInformation\", 'id', new.\"id\", 'meetDate', new.\"meetDate\", 'pdf', new.\"pdf\", 'precisions', new.\"precisions\", 'projectCadastralRef', new.\"projectCadastralRef\", 'projectDescription', new.\"projectDescription\", 'projectSpaceType', new.\"projectSpaceType\", 'redactedBy', new.\"redactedBy\", 'redactedById', new.\"redactedById\", 'serviceInstructeur', new.\"serviceInstructeur\", 'title', new.\"title\", 'udap_id', new.\"udap_id\"), NULL, NULL);\nEND;", + "DROP TRIGGER IF EXISTS update_main_report_into_oplog;", + "CREATE TRIGGER update_main_report_into_oplog\n AFTER UPDATE ON \"main\".\"report\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'report')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'report', 'UPDATE', json_patch('{}', json_object('id', new.\"id\")), json_object('applicantAddress', new.\"applicantAddress\", 'applicantEmail', new.\"applicantEmail\", 'applicantName', new.\"applicantName\", 'city', new.\"city\", 'contacts', new.\"contacts\", 'createdAt', new.\"createdAt\", 'createdBy', new.\"createdBy\", 'decision', new.\"decision\", 'disabled', new.\"disabled\", 'furtherInformation', new.\"furtherInformation\", 'id', new.\"id\", 'meetDate', new.\"meetDate\", 'pdf', new.\"pdf\", 'precisions', new.\"precisions\", 'projectCadastralRef', new.\"projectCadastralRef\", 'projectDescription', new.\"projectDescription\", 'projectSpaceType', new.\"projectSpaceType\", 'redactedBy', new.\"redactedBy\", 'redactedById', new.\"redactedById\", 'serviceInstructeur', new.\"serviceInstructeur\", 'title', new.\"title\", 'udap_id', new.\"udap_id\"), json_object('applicantAddress', old.\"applicantAddress\", 'applicantEmail', old.\"applicantEmail\", 'applicantName', old.\"applicantName\", 'city', old.\"city\", 'contacts', old.\"contacts\", 'createdAt', old.\"createdAt\", 'createdBy', old.\"createdBy\", 'decision', old.\"decision\", 'disabled', old.\"disabled\", 'furtherInformation', old.\"furtherInformation\", 'id', old.\"id\", 'meetDate', old.\"meetDate\", 'pdf', old.\"pdf\", 'precisions', old.\"precisions\", 'projectCadastralRef', old.\"projectCadastralRef\", 'projectDescription', old.\"projectDescription\", 'projectSpaceType', old.\"projectSpaceType\", 'redactedBy', old.\"redactedBy\", 'redactedById', old.\"redactedById\", 'serviceInstructeur', old.\"serviceInstructeur\", 'title', old.\"title\", 'udap_id', old.\"udap_id\"), NULL);\nEND;", + "DROP TRIGGER IF EXISTS delete_main_report_into_oplog;", + "CREATE TRIGGER delete_main_report_into_oplog\n AFTER DELETE ON \"main\".\"report\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'report')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'report', 'DELETE', json_patch('{}', json_object('id', old.\"id\")), NULL, json_object('applicantAddress', old.\"applicantAddress\", 'applicantEmail', old.\"applicantEmail\", 'applicantName', old.\"applicantName\", 'city', old.\"city\", 'contacts', old.\"contacts\", 'createdAt', old.\"createdAt\", 'createdBy', old.\"createdBy\", 'decision', old.\"decision\", 'disabled', old.\"disabled\", 'furtherInformation', old.\"furtherInformation\", 'id', old.\"id\", 'meetDate', old.\"meetDate\", 'pdf', old.\"pdf\", 'precisions', old.\"precisions\", 'projectCadastralRef', old.\"projectCadastralRef\", 'projectDescription', old.\"projectDescription\", 'projectSpaceType', old.\"projectSpaceType\", 'redactedBy', old.\"redactedBy\", 'redactedById', old.\"redactedById\", 'serviceInstructeur', old.\"serviceInstructeur\", 'title', old.\"title\", 'udap_id', old.\"udap_id\"), NULL);\nEND;", + "DROP TRIGGER IF EXISTS compensation_insert_main_report_createdBy_into_oplog;", + "CREATE TRIGGER compensation_insert_main_report_createdBy_into_oplog\n AFTER INSERT ON \"main\".\"report\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'report') AND\n 1 = (SELECT value from _electric_meta WHERE key = 'compensations')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n SELECT 'main', 'user', 'COMPENSATION', json_patch('{}', json_object('id', \"id\")), json_object('id', \"id\"), NULL, NULL\n FROM \"main\".\"user\" WHERE \"id\" = new.\"createdBy\";\nEND;", + "DROP TRIGGER IF EXISTS compensation_update_main_report_createdBy_into_oplog;", + "CREATE TRIGGER compensation_update_main_report_createdBy_into_oplog\n AFTER UPDATE ON \"main\".\"report\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'report') AND\n 1 = (SELECT value from _electric_meta WHERE key = 'compensations')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n SELECT 'main', 'user', 'COMPENSATION', json_patch('{}', json_object('id', \"id\")), json_object('id', \"id\"), NULL, NULL\n FROM \"main\".\"user\" WHERE \"id\" = new.\"createdBy\";\nEND;" + ], + "version": "905" } ] \ No newline at end of file diff --git a/packages/electric-client/src/generated/client/pg-migrations.ts b/packages/electric-client/src/generated/client/pg-migrations.ts index 54b5e1ee..a6486df7 100644 --- a/packages/electric-client/src/generated/client/pg-migrations.ts +++ b/packages/electric-client/src/generated/client/pg-migrations.ts @@ -233,5 +233,30 @@ export default [ "CREATE TRIGGER delete_public_pdf_snapshot_into_oplog\n AFTER DELETE ON \"public\".\"pdf_snapshot\"\n FOR EACH ROW\n EXECUTE FUNCTION delete_public_pdf_snapshot_into_oplog_function();" ], "version": "904" + }, + { + "statements": [ + "ALTER TABLE \"report\" ADD COLUMN \"city\" TEXT", + "INSERT INTO \"public\".\"_electric_trigger_settings\" (\"namespace\", \"tablename\", \"flag\")\n VALUES ('public', 'report', 1)\n ON CONFLICT DO NOTHING;", + "DROP TRIGGER IF EXISTS update_ensure_public_report_primarykey ON \"public\".\"report\";", + "CREATE OR REPLACE FUNCTION update_ensure_public_report_primarykey_function()\nRETURNS TRIGGER AS $$\nBEGIN\n IF OLD.\"id\" IS DISTINCT FROM NEW.\"id\" THEN\n RAISE EXCEPTION 'Cannot change the value of column id as it belongs to the primary key';\n END IF;\n RETURN NEW;\nEND;\n$$ LANGUAGE plpgsql;", + "CREATE TRIGGER update_ensure_public_report_primarykey\n BEFORE UPDATE ON \"public\".\"report\"\n FOR EACH ROW\n EXECUTE FUNCTION update_ensure_public_report_primarykey_function();", + "DROP TRIGGER IF EXISTS insert_public_report_into_oplog ON \"public\".\"report\";", + " CREATE OR REPLACE FUNCTION insert_public_report_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n BEGIN\n -- Get the flag value from _electric_trigger_settings\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'report';\n\n IF flag_value = 1 THEN\n -- Insert into _electric_oplog\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n VALUES (\n 'public',\n 'report',\n 'INSERT',\n json_strip_nulls(json_build_object('id', new.\"id\")),\n jsonb_build_object('applicantAddress', new.\"applicantAddress\", 'applicantEmail', new.\"applicantEmail\", 'applicantName', new.\"applicantName\", 'city', new.\"city\", 'contacts', new.\"contacts\", 'createdAt', new.\"createdAt\", 'createdBy', new.\"createdBy\", 'decision', new.\"decision\", 'disabled', new.\"disabled\", 'furtherInformation', new.\"furtherInformation\", 'id', new.\"id\", 'meetDate', new.\"meetDate\", 'pdf', new.\"pdf\", 'precisions', new.\"precisions\", 'projectCadastralRef', new.\"projectCadastralRef\", 'projectDescription', new.\"projectDescription\", 'projectSpaceType', new.\"projectSpaceType\", 'redactedBy', new.\"redactedBy\", 'redactedById', new.\"redactedById\", 'serviceInstructeur', new.\"serviceInstructeur\", 'title', new.\"title\", 'udap_id', new.\"udap_id\"),\n NULL,\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + "CREATE TRIGGER insert_public_report_into_oplog\n AFTER INSERT ON \"public\".\"report\"\n FOR EACH ROW\n EXECUTE FUNCTION insert_public_report_into_oplog_function();", + "DROP TRIGGER IF EXISTS update_public_report_into_oplog ON \"public\".\"report\";", + " CREATE OR REPLACE FUNCTION update_public_report_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n BEGIN\n -- Get the flag value from _electric_trigger_settings\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'report';\n\n IF flag_value = 1 THEN\n -- Insert into _electric_oplog\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n VALUES (\n 'public',\n 'report',\n 'UPDATE',\n json_strip_nulls(json_build_object('id', new.\"id\")),\n jsonb_build_object('applicantAddress', new.\"applicantAddress\", 'applicantEmail', new.\"applicantEmail\", 'applicantName', new.\"applicantName\", 'city', new.\"city\", 'contacts', new.\"contacts\", 'createdAt', new.\"createdAt\", 'createdBy', new.\"createdBy\", 'decision', new.\"decision\", 'disabled', new.\"disabled\", 'furtherInformation', new.\"furtherInformation\", 'id', new.\"id\", 'meetDate', new.\"meetDate\", 'pdf', new.\"pdf\", 'precisions', new.\"precisions\", 'projectCadastralRef', new.\"projectCadastralRef\", 'projectDescription', new.\"projectDescription\", 'projectSpaceType', new.\"projectSpaceType\", 'redactedBy', new.\"redactedBy\", 'redactedById', new.\"redactedById\", 'serviceInstructeur', new.\"serviceInstructeur\", 'title', new.\"title\", 'udap_id', new.\"udap_id\"),\n jsonb_build_object('applicantAddress', old.\"applicantAddress\", 'applicantEmail', old.\"applicantEmail\", 'applicantName', old.\"applicantName\", 'city', old.\"city\", 'contacts', old.\"contacts\", 'createdAt', old.\"createdAt\", 'createdBy', old.\"createdBy\", 'decision', old.\"decision\", 'disabled', old.\"disabled\", 'furtherInformation', old.\"furtherInformation\", 'id', old.\"id\", 'meetDate', old.\"meetDate\", 'pdf', old.\"pdf\", 'precisions', old.\"precisions\", 'projectCadastralRef', old.\"projectCadastralRef\", 'projectDescription', old.\"projectDescription\", 'projectSpaceType', old.\"projectSpaceType\", 'redactedBy', old.\"redactedBy\", 'redactedById', old.\"redactedById\", 'serviceInstructeur', old.\"serviceInstructeur\", 'title', old.\"title\", 'udap_id', old.\"udap_id\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + "CREATE TRIGGER update_public_report_into_oplog\n AFTER UPDATE ON \"public\".\"report\"\n FOR EACH ROW\n EXECUTE FUNCTION update_public_report_into_oplog_function();", + "DROP TRIGGER IF EXISTS delete_public_report_into_oplog ON \"public\".\"report\";", + " CREATE OR REPLACE FUNCTION delete_public_report_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n BEGIN\n -- Get the flag value from _electric_trigger_settings\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'report';\n\n IF flag_value = 1 THEN\n -- Insert into _electric_oplog\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n VALUES (\n 'public',\n 'report',\n 'DELETE',\n json_strip_nulls(json_build_object('id', old.\"id\")),\n NULL,\n jsonb_build_object('applicantAddress', old.\"applicantAddress\", 'applicantEmail', old.\"applicantEmail\", 'applicantName', old.\"applicantName\", 'city', old.\"city\", 'contacts', old.\"contacts\", 'createdAt', old.\"createdAt\", 'createdBy', old.\"createdBy\", 'decision', old.\"decision\", 'disabled', old.\"disabled\", 'furtherInformation', old.\"furtherInformation\", 'id', old.\"id\", 'meetDate', old.\"meetDate\", 'pdf', old.\"pdf\", 'precisions', old.\"precisions\", 'projectCadastralRef', old.\"projectCadastralRef\", 'projectDescription', old.\"projectDescription\", 'projectSpaceType', old.\"projectSpaceType\", 'redactedBy', old.\"redactedBy\", 'redactedById', old.\"redactedById\", 'serviceInstructeur', old.\"serviceInstructeur\", 'title', old.\"title\", 'udap_id', old.\"udap_id\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + "CREATE TRIGGER delete_public_report_into_oplog\n AFTER DELETE ON \"public\".\"report\"\n FOR EACH ROW\n EXECUTE FUNCTION delete_public_report_into_oplog_function();", + "DROP TRIGGER IF EXISTS compensation_insert_public_report_createdBy_into_oplog ON \"public\".\"report\";", + " CREATE OR REPLACE FUNCTION compensation_insert_public_report_createdBy_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n meta_value INTEGER;\n BEGIN\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'report';\n\n SELECT value INTO meta_value FROM \"public\"._electric_meta WHERE key = 'compensations';\n\n IF flag_value = 1 AND meta_value = 1 THEN\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n SELECT\n 'public',\n 'user',\n 'COMPENSATION',\n json_strip_nulls(json_strip_nulls(json_build_object('id', \"id\"))),\n jsonb_build_object('id', \"id\"),\n NULL,\n NULL\n FROM \"public\".\"user\"\n WHERE \"id\" = NEW.\"createdBy\";\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + "CREATE TRIGGER compensation_insert_public_report_createdBy_into_oplog\n AFTER INSERT ON \"public\".\"report\"\n FOR EACH ROW\n EXECUTE FUNCTION compensation_insert_public_report_createdBy_into_oplog_function();", + "DROP TRIGGER IF EXISTS compensation_update_public_report_createdBy_into_oplog ON \"public\".\"report\";", + " CREATE OR REPLACE FUNCTION compensation_update_public_report_createdBy_into_oplog_function()\n RETURNS TRIGGER AS $$\n BEGIN\n DECLARE\n flag_value INTEGER;\n meta_value INTEGER;\n BEGIN\n SELECT flag INTO flag_value FROM \"public\"._electric_trigger_settings WHERE namespace = 'public' AND tablename = 'report';\n\n SELECT value INTO meta_value FROM \"public\"._electric_meta WHERE key = 'compensations';\n\n IF flag_value = 1 AND meta_value = 1 THEN\n INSERT INTO \"public\"._electric_oplog (namespace, tablename, optype, \"primaryKey\", \"newRow\", \"oldRow\", timestamp)\n SELECT\n 'public',\n 'user',\n 'COMPENSATION',\n json_strip_nulls(json_strip_nulls(json_build_object('id', \"id\"))),\n jsonb_build_object('id', \"id\"),\n NULL,\n NULL\n FROM \"public\".\"user\"\n WHERE \"id\" = NEW.\"createdBy\";\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + "CREATE TRIGGER compensation_update_public_report_createdBy_into_oplog\n AFTER UPDATE ON \"public\".\"report\"\n FOR EACH ROW\n EXECUTE FUNCTION compensation_update_public_report_createdBy_into_oplog_function();" + ], + "version": "905" } ] \ No newline at end of file diff --git a/packages/electric-client/src/generated/client/prismaClient.d.ts b/packages/electric-client/src/generated/client/prismaClient.d.ts index e0f85536..38acaf24 100644 --- a/packages/electric-client/src/generated/client/prismaClient.d.ts +++ b/packages/electric-client/src/generated/client/prismaClient.d.ts @@ -118,6 +118,7 @@ export type ReportPayload composites: {} } @@ -5325,6 +5326,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id: string | null redactedById: string | null applicantEmail: string | null + city: string | null } export type ReportMaxAggregateOutputType = { @@ -5349,6 +5351,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id: string | null redactedById: string | null applicantEmail: string | null + city: string | null } export type ReportCountAggregateOutputType = { @@ -5373,6 +5376,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id: number redactedById: number applicantEmail: number + city: number _all: number } @@ -5407,6 +5411,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: true redactedById?: true applicantEmail?: true + city?: true } export type ReportMaxAggregateInputType = { @@ -5431,6 +5436,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: true redactedById?: true applicantEmail?: true + city?: true } export type ReportCountAggregateInputType = { @@ -5455,6 +5461,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: true redactedById?: true applicantEmail?: true + city?: true _all?: true } @@ -5567,6 +5574,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id: string | null redactedById: string | null applicantEmail: string | null + city: string | null _count: ReportCountAggregateOutputType | null _avg: ReportAvgAggregateOutputType | null _sum: ReportSumAggregateOutputType | null @@ -5610,6 +5618,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: boolean redactedById?: boolean applicantEmail?: boolean + city?: boolean user?: boolean | UserArgs }, ExtArgs["result"]["report"]> @@ -5635,6 +5644,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: boolean redactedById?: boolean applicantEmail?: boolean + city?: boolean } export type ReportInclude = { @@ -9384,7 +9394,8 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject disabled: 'disabled', udap_id: 'udap_id', redactedById: 'redactedById', - applicantEmail: 'applicantEmail' + applicantEmail: 'applicantEmail', + city: 'city' }; export type ReportScalarFieldEnum = (typeof ReportScalarFieldEnum)[keyof typeof ReportScalarFieldEnum] @@ -9662,6 +9673,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: StringNullableFilter | string | null redactedById?: StringNullableFilter | string | null applicantEmail?: StringNullableFilter | string | null + city?: StringNullableFilter | string | null user?: XOR } @@ -9687,6 +9699,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: SortOrderInput | SortOrder redactedById?: SortOrderInput | SortOrder applicantEmail?: SortOrderInput | SortOrder + city?: SortOrderInput | SortOrder user?: UserOrderByWithRelationInput } @@ -9716,6 +9729,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: SortOrderInput | SortOrder redactedById?: SortOrderInput | SortOrder applicantEmail?: SortOrderInput | SortOrder + city?: SortOrderInput | SortOrder _count?: ReportCountOrderByAggregateInput _avg?: ReportAvgOrderByAggregateInput _max?: ReportMaxOrderByAggregateInput @@ -9748,6 +9762,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: StringNullableWithAggregatesFilter | string | null redactedById?: StringNullableWithAggregatesFilter | string | null applicantEmail?: StringNullableWithAggregatesFilter | string | null + city?: StringNullableWithAggregatesFilter | string | null } export type Service_instructeursWhereInput = { @@ -10155,6 +10170,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: string | null redactedById?: string | null applicantEmail?: string | null + city?: string | null user: UserCreateNestedOneWithoutReportInput } @@ -10180,6 +10196,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: string | null redactedById?: string | null applicantEmail?: string | null + city?: string | null } export type ReportUpdateInput = { @@ -10203,6 +10220,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: NullableStringFieldUpdateOperationsInput | string | null redactedById?: NullableStringFieldUpdateOperationsInput | string | null applicantEmail?: NullableStringFieldUpdateOperationsInput | string | null + city?: NullableStringFieldUpdateOperationsInput | string | null user?: UserUpdateOneRequiredWithoutReportNestedInput } @@ -10228,6 +10246,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: NullableStringFieldUpdateOperationsInput | string | null redactedById?: NullableStringFieldUpdateOperationsInput | string | null applicantEmail?: NullableStringFieldUpdateOperationsInput | string | null + city?: NullableStringFieldUpdateOperationsInput | string | null } export type ReportCreateManyInput = { @@ -10252,6 +10271,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: string | null redactedById?: string | null applicantEmail?: string | null + city?: string | null } export type ReportUpdateManyMutationInput = { @@ -10275,6 +10295,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: NullableStringFieldUpdateOperationsInput | string | null redactedById?: NullableStringFieldUpdateOperationsInput | string | null applicantEmail?: NullableStringFieldUpdateOperationsInput | string | null + city?: NullableStringFieldUpdateOperationsInput | string | null } export type ReportUncheckedUpdateManyInput = { @@ -10299,6 +10320,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: NullableStringFieldUpdateOperationsInput | string | null redactedById?: NullableStringFieldUpdateOperationsInput | string | null applicantEmail?: NullableStringFieldUpdateOperationsInput | string | null + city?: NullableStringFieldUpdateOperationsInput | string | null } export type Service_instructeursCreateInput = { @@ -10802,6 +10824,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: SortOrder redactedById?: SortOrder applicantEmail?: SortOrder + city?: SortOrder } export type ReportAvgOrderByAggregateInput = { @@ -10830,6 +10853,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: SortOrder redactedById?: SortOrder applicantEmail?: SortOrder + city?: SortOrder } export type ReportMinOrderByAggregateInput = { @@ -10854,6 +10878,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: SortOrder redactedById?: SortOrder applicantEmail?: SortOrder + city?: SortOrder } export type ReportSumOrderByAggregateInput = { @@ -11746,6 +11771,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: string | null redactedById?: string | null applicantEmail?: string | null + city?: string | null } export type ReportUncheckedCreateWithoutUserInput = { @@ -11769,6 +11795,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: string | null redactedById?: string | null applicantEmail?: string | null + city?: string | null } export type ReportCreateOrConnectWithoutUserInput = { @@ -11899,6 +11926,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: StringNullableFilter | string | null redactedById?: StringNullableFilter | string | null applicantEmail?: StringNullableFilter | string | null + city?: StringNullableFilter | string | null } export type UdapUpsertWithoutUserInput = { @@ -11993,6 +12021,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: string | null redactedById?: string | null applicantEmail?: string | null + city?: string | null } export type DelegationUpdateWithoutUser_delegation_createdByTouserInput = { @@ -12040,6 +12069,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: NullableStringFieldUpdateOperationsInput | string | null redactedById?: NullableStringFieldUpdateOperationsInput | string | null applicantEmail?: NullableStringFieldUpdateOperationsInput | string | null + city?: NullableStringFieldUpdateOperationsInput | string | null } export type ReportUncheckedUpdateWithoutUserInput = { @@ -12063,6 +12093,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: NullableStringFieldUpdateOperationsInput | string | null redactedById?: NullableStringFieldUpdateOperationsInput | string | null applicantEmail?: NullableStringFieldUpdateOperationsInput | string | null + city?: NullableStringFieldUpdateOperationsInput | string | null } export type ReportUncheckedUpdateManyWithoutReportInput = { @@ -12086,6 +12117,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject udap_id?: NullableStringFieldUpdateOperationsInput | string | null redactedById?: NullableStringFieldUpdateOperationsInput | string | null applicantEmail?: NullableStringFieldUpdateOperationsInput | string | null + city?: NullableStringFieldUpdateOperationsInput | string | null } diff --git a/packages/electric-client/src/generated/typebox/index.ts b/packages/electric-client/src/generated/typebox/index.ts index bef68661..1b8d5910 100644 --- a/packages/electric-client/src/generated/typebox/index.ts +++ b/packages/electric-client/src/generated/typebox/index.ts @@ -18,5 +18,5 @@ export * from './internal_user'; export * from './internal_userInput'; export * from './service_instructeurs'; export * from './service_instructeursInput'; -export * from './clause_v2'; export * from './clause_v2Input'; +export * from './clause_v2'; diff --git a/packages/frontend/src/features/InfoForm.tsx b/packages/frontend/src/features/InfoForm.tsx index ccb1a60d..454ea949 100644 --- a/packages/frontend/src/features/InfoForm.tsx +++ b/packages/frontend/src/features/InfoForm.tsx @@ -142,9 +142,18 @@ export const InfoForm = () => { + + + { > - {/* */} - - {report.title ?? "Sans titre"} - {report.createdAt.toLocaleDateString()} + {report.meetDate ? ( + {new Date(report.meetDate).toLocaleDateString()} + ) : null} - {report.applicantName ? <>Pour {report.applicantName} : null} - - {report.applicantName ? "p" : "P"}ar {report.redactedBy ?? report.user?.name ?? ""} - + + {description} + @@ -264,6 +271,10 @@ const ReportListItem = ({ ); }; +const uppercaseFirstLetterIf = (str: string, condition: boolean) => { + return condition ? str.charAt(0).toUpperCase() + str.slice(1) : str; +}; + const MenuDesktopPopover = ({ onClose, report }: MenuProps) => { const isDesktop = useIsDesktop(); const ref = useRef(null); diff --git a/packages/frontend/src/routes/edit.$reportId.tsx b/packages/frontend/src/routes/edit.$reportId.tsx index c5274703..4ac237ae 100644 --- a/packages/frontend/src/routes/edit.$reportId.tsx +++ b/packages/frontend/src/routes/edit.$reportId.tsx @@ -73,7 +73,7 @@ const WithReport = ({ report }: { report: Report }) => { }); const user = useUser()!; - const isOwner = report.createdBy === user.id; + const isOwner = report.redactedById === user.id; const userDelegations = useLiveQuery( db.delegation.liveFirst({ where: { createdBy: report.createdBy, delegatedTo: user.id } }), diff --git a/packages/pdf/src/report.tsx b/packages/pdf/src/report.tsx index d7b0dce1..465dca21 100644 --- a/packages/pdf/src/report.tsx +++ b/packages/pdf/src/report.tsx @@ -158,6 +158,8 @@ export const getReportHtmlString = ( const meetDate = report.meetDate ? new Date(report.meetDate) : null; + const address = [report.applicantAddress, report.city].filter(Boolean).join(" "); + return minifyHtml(`

@@ -174,7 +176,7 @@ export const getReportHtmlString = ( } Votre interlocuteur : ${report.redactedBy ?? report.user?.name ?? ""}
Demandeur : ${report.applicantName ?? ""}
- Adresse du projet : ${report.applicantAddress ?? ""}
+ Adresse du projet : ${address ?? ""}
Ref cadastrale : ${report.projectCadastralRef ?? ""}