diff --git a/db/migrations/09-add_redacted_id.sql b/db/migrations/09-add_redacted_id.sql new file mode 100644 index 00000000..0f921f8d --- /dev/null +++ b/db/migrations/09-add_redacted_id.sql @@ -0,0 +1 @@ +ALTER TABLE "report" ADD COLUMN "redactedById" 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 a1d72853..83dfa100 100644 --- a/packages/electric-client/src/generated/client/index.ts +++ b/packages/electric-client/src/generated/client/index.ts @@ -19,7 +19,7 @@ export const DelegationScalarFieldEnumSchema = z.enum(['createdBy','delegatedTo' 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']); +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']); export const Service_instructeursScalarFieldEnumSchema = z.enum(['id','full_name','short_name','email','tel','udap_id']); @@ -82,6 +82,7 @@ export const ReportSchema = z.object({ pdf: z.string().nullable(), disabled: z.boolean().nullable(), udap_id: z.string().nullable(), + redactedById: z.string().nullable(), }) export type Report = z.infer @@ -201,6 +202,7 @@ export const ReportSelectSchema: z.ZodType = z.object({ pdf: z.boolean().optional(), disabled: z.boolean().optional(), udap_id: z.boolean().optional(), + redactedById: z.boolean().optional(), user: z.union([z.boolean(),z.lazy(() => UserArgsSchema)]).optional(), }).strict() @@ -398,6 +400,7 @@ export const ReportWhereInputSchema: z.ZodType = z.obje pdf: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), disabled: z.union([ z.lazy(() => BoolNullableFilterSchema),z.boolean() ]).optional().nullable(), udap_id: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), + redactedById: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), user: z.union([ z.lazy(() => UserRelationFilterSchema),z.lazy(() => UserWhereInputSchema) ]).optional(), }).strict(); @@ -421,6 +424,7 @@ export const ReportOrderByWithRelationInputSchema: z.ZodType SortOrderSchema).optional(), disabled: z.lazy(() => SortOrderSchema).optional(), udap_id: z.lazy(() => SortOrderSchema).optional(), + redactedById: z.lazy(() => SortOrderSchema).optional(), user: z.lazy(() => UserOrderByWithRelationInputSchema).optional() }).strict(); @@ -448,6 +452,7 @@ export const ReportOrderByWithAggregationInputSchema: z.ZodType SortOrderSchema).optional(), disabled: z.lazy(() => SortOrderSchema).optional(), udap_id: z.lazy(() => SortOrderSchema).optional(), + redactedById: z.lazy(() => SortOrderSchema).optional(), _count: z.lazy(() => ReportCountOrderByAggregateInputSchema).optional(), _avg: z.lazy(() => ReportAvgOrderByAggregateInputSchema).optional(), _max: z.lazy(() => ReportMaxOrderByAggregateInputSchema).optional(), @@ -478,6 +483,7 @@ export const ReportScalarWhereWithAggregatesInputSchema: z.ZodType StringNullableWithAggregatesFilterSchema),z.string() ]).optional().nullable(), disabled: z.union([ z.lazy(() => BoolNullableWithAggregatesFilterSchema),z.boolean() ]).optional().nullable(), udap_id: z.union([ z.lazy(() => StringNullableWithAggregatesFilterSchema),z.string() ]).optional().nullable(), + redactedById: z.union([ z.lazy(() => StringNullableWithAggregatesFilterSchema),z.string() ]).optional().nullable(), }).strict(); export const Service_instructeursWhereInputSchema: z.ZodType = z.object({ @@ -756,6 +762,7 @@ export const ReportCreateInputSchema: z.ZodType = z.ob pdf: z.string().optional().nullable(), disabled: z.boolean().optional().nullable(), udap_id: z.string().optional().nullable(), + redactedById: z.string().optional().nullable(), user: z.lazy(() => UserCreateNestedOneWithoutReportInputSchema) }).strict(); @@ -778,7 +785,8 @@ export const ReportUncheckedCreateInputSchema: z.ZodType = z.object({ @@ -800,6 +808,7 @@ export const ReportUpdateInputSchema: z.ZodType = z.ob pdf: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), user: z.lazy(() => UserUpdateOneRequiredWithoutReportNestedInputSchema).optional() }).strict(); @@ -823,6 +832,7 @@ export const ReportUncheckedUpdateInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); export const ReportCreateManyInputSchema: z.ZodType = z.object({ @@ -844,7 +854,8 @@ export const ReportCreateManyInputSchema: z.ZodType = z.object({ @@ -866,6 +877,7 @@ export const ReportUpdateManyMutationInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); export const ReportUncheckedUpdateManyInputSchema: z.ZodType = z.object({ @@ -888,6 +900,7 @@ export const ReportUncheckedUpdateManyInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); export const Service_instructeursCreateInputSchema: z.ZodType = z.object({ @@ -1279,7 +1292,8 @@ export const ReportCountOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional(), pdf: z.lazy(() => SortOrderSchema).optional(), disabled: z.lazy(() => SortOrderSchema).optional(), - udap_id: z.lazy(() => SortOrderSchema).optional() + udap_id: z.lazy(() => SortOrderSchema).optional(), + redactedById: z.lazy(() => SortOrderSchema).optional() }).strict(); export const ReportAvgOrderByAggregateInputSchema: z.ZodType = z.object({ @@ -1305,7 +1319,8 @@ export const ReportMaxOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional(), pdf: z.lazy(() => SortOrderSchema).optional(), disabled: z.lazy(() => SortOrderSchema).optional(), - udap_id: z.lazy(() => SortOrderSchema).optional() + udap_id: z.lazy(() => SortOrderSchema).optional(), + redactedById: z.lazy(() => SortOrderSchema).optional() }).strict(); export const ReportMinOrderByAggregateInputSchema: z.ZodType = z.object({ @@ -1327,7 +1342,8 @@ export const ReportMinOrderByAggregateInputSchema: z.ZodType SortOrderSchema).optional(), pdf: z.lazy(() => SortOrderSchema).optional(), disabled: z.lazy(() => SortOrderSchema).optional(), - udap_id: z.lazy(() => SortOrderSchema).optional() + udap_id: z.lazy(() => SortOrderSchema).optional(), + redactedById: z.lazy(() => SortOrderSchema).optional() }).strict(); export const ReportSumOrderByAggregateInputSchema: z.ZodType = z.object({ @@ -2259,7 +2275,8 @@ export const ReportCreateWithoutUserInputSchema: z.ZodType = z.object({ @@ -2280,7 +2297,8 @@ export const ReportUncheckedCreateWithoutUserInputSchema: z.ZodType = z.object({ @@ -2409,6 +2427,7 @@ export const ReportScalarWhereInputSchema: z.ZodType StringNullableFilterSchema),z.string() ]).optional().nullable(), disabled: z.union([ z.lazy(() => BoolNullableFilterSchema),z.boolean() ]).optional().nullable(), udap_id: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), + redactedById: z.union([ z.lazy(() => StringNullableFilterSchema),z.string() ]).optional().nullable(), }).strict(); export const UdapUpsertWithoutUserInputSchema: z.ZodType = z.object({ @@ -2500,7 +2519,8 @@ export const ReportCreateManyUserInputSchema: z.ZodType = z.object({ @@ -2546,6 +2566,7 @@ export const ReportUpdateWithoutUserInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); export const ReportUncheckedUpdateWithoutUserInputSchema: z.ZodType = z.object({ @@ -2567,6 +2588,7 @@ export const ReportUncheckedUpdateWithoutUserInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); export const ReportUncheckedUpdateManyWithoutReportInputSchema: z.ZodType = z.object({ @@ -2588,6 +2610,7 @@ export const ReportUncheckedUpdateManyWithoutReportInputSchema: z.ZodType NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), disabled: z.union([ z.boolean(),z.lazy(() => NullableBoolFieldUpdateOperationsInputSchema) ]).optional().nullable(), udap_id: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), + redactedById: z.union([ z.string(),z.lazy(() => NullableStringFieldUpdateOperationsInputSchema) ]).optional().nullable(), }).strict(); ///////////////////////////////////////// @@ -3386,6 +3409,10 @@ export const tableSchemas = { [ "udap_id", "TEXT" + ], + [ + "redactedById", + "TEXT" ] ]), relations: [ diff --git a/packages/electric-client/src/generated/client/migrations.ts b/packages/electric-client/src/generated/client/migrations.ts index a7aa51eb..977ed691 100644 --- a/packages/electric-client/src/generated/client/migrations.ts +++ b/packages/electric-client/src/generated/client/migrations.ts @@ -94,5 +94,24 @@ export default [ "CREATE TRIGGER delete_main_service_instructeurs_into_oplog\n AFTER DELETE ON \"main\".\"service_instructeurs\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'service_instructeurs')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'service_instructeurs', 'DELETE', json_patch('{}', json_object('id', old.\"id\")), NULL, json_object('email', old.\"email\", 'full_name', old.\"full_name\", 'id', old.\"id\", 'short_name', old.\"short_name\", 'tel', old.\"tel\", 'udap_id', old.\"udap_id\"), NULL);\nEND;" ], "version": "7" + }, + { + "statements": [ + "ALTER TABLE \"report\" ADD COLUMN \"redactedById\" 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\", 'applicantName', new.\"applicantName\", '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\", 'applicantName', new.\"applicantName\", '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\", 'applicantName', old.\"applicantName\", '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\", 'applicantName', old.\"applicantName\", '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": "9" } ] \ 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 405fd627..5674f940 100644 --- a/packages/electric-client/src/generated/client/pg-migrations.ts +++ b/packages/electric-client/src/generated/client/pg-migrations.ts @@ -126,5 +126,30 @@ export default [ "CREATE TRIGGER delete_public_service_instructeurs_into_oplog\n AFTER DELETE ON \"public\".\"service_instructeurs\"\n FOR EACH ROW\n EXECUTE FUNCTION delete_public_service_instructeurs_into_oplog_function();" ], "version": "7" + }, + { + "statements": [ + "ALTER TABLE \"report\" ADD COLUMN \"redactedById\" 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\", 'applicantName', new.\"applicantName\", '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\", 'applicantName', new.\"applicantName\", '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\", 'applicantName', old.\"applicantName\", '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\", 'applicantName', old.\"applicantName\", '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": "9" } ] \ 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 6924cc2f..0b2ee181 100644 --- a/packages/electric-client/src/generated/client/prismaClient.d.ts +++ b/packages/electric-client/src/generated/client/prismaClient.d.ts @@ -75,6 +75,7 @@ export type ReportPayload composites: {} } @@ -3320,6 +3321,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf: string | null disabled: boolean | null udap_id: string | null + redactedById: string | null } export type ReportMaxAggregateOutputType = { @@ -3342,6 +3344,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf: string | null disabled: boolean | null udap_id: string | null + redactedById: string | null } export type ReportCountAggregateOutputType = { @@ -3364,6 +3367,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf: number disabled: number udap_id: number + redactedById: number _all: number } @@ -3396,6 +3400,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: true disabled?: true udap_id?: true + redactedById?: true } export type ReportMaxAggregateInputType = { @@ -3418,6 +3423,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: true disabled?: true udap_id?: true + redactedById?: true } export type ReportCountAggregateInputType = { @@ -3440,6 +3446,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: true disabled?: true udap_id?: true + redactedById?: true _all?: true } @@ -3550,6 +3557,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf: string | null disabled: boolean | null udap_id: string | null + redactedById: string | null _count: ReportCountAggregateOutputType | null _avg: ReportAvgAggregateOutputType | null _sum: ReportSumAggregateOutputType | null @@ -3591,6 +3599,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: boolean disabled?: boolean udap_id?: boolean + redactedById?: boolean user?: boolean | UserArgs }, ExtArgs["result"]["report"]> @@ -3614,6 +3623,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: boolean disabled?: boolean udap_id?: boolean + redactedById?: boolean } export type ReportInclude = { @@ -7337,7 +7347,8 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject serviceInstructeur: 'serviceInstructeur', pdf: 'pdf', disabled: 'disabled', - udap_id: 'udap_id' + udap_id: 'udap_id', + redactedById: 'redactedById' }; export type ReportScalarFieldEnum = (typeof ReportScalarFieldEnum)[keyof typeof ReportScalarFieldEnum] @@ -7513,6 +7524,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: StringNullableFilter | string | null disabled?: BoolNullableFilter | boolean | null udap_id?: StringNullableFilter | string | null + redactedById?: StringNullableFilter | string | null user?: XOR } @@ -7536,6 +7548,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: SortOrderInput | SortOrder disabled?: SortOrderInput | SortOrder udap_id?: SortOrderInput | SortOrder + redactedById?: SortOrderInput | SortOrder user?: UserOrderByWithRelationInput } @@ -7563,6 +7576,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: SortOrderInput | SortOrder disabled?: SortOrderInput | SortOrder udap_id?: SortOrderInput | SortOrder + redactedById?: SortOrderInput | SortOrder _count?: ReportCountOrderByAggregateInput _avg?: ReportAvgOrderByAggregateInput _max?: ReportMaxOrderByAggregateInput @@ -7593,6 +7607,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: StringNullableWithAggregatesFilter | string | null disabled?: BoolNullableWithAggregatesFilter | boolean | null udap_id?: StringNullableWithAggregatesFilter | string | null + redactedById?: StringNullableWithAggregatesFilter | string | null } export type Service_instructeursWhereInput = { @@ -7872,6 +7887,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: string | null disabled?: boolean | null udap_id?: string | null + redactedById?: string | null user: UserCreateNestedOneWithoutReportInput } @@ -7895,6 +7911,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: string | null disabled?: boolean | null udap_id?: string | null + redactedById?: string | null } export type ReportUpdateInput = { @@ -7916,6 +7933,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: NullableStringFieldUpdateOperationsInput | string | null disabled?: NullableBoolFieldUpdateOperationsInput | boolean | null udap_id?: NullableStringFieldUpdateOperationsInput | string | null + redactedById?: NullableStringFieldUpdateOperationsInput | string | null user?: UserUpdateOneRequiredWithoutReportNestedInput } @@ -7939,6 +7957,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: NullableStringFieldUpdateOperationsInput | string | null disabled?: NullableBoolFieldUpdateOperationsInput | boolean | null udap_id?: NullableStringFieldUpdateOperationsInput | string | null + redactedById?: NullableStringFieldUpdateOperationsInput | string | null } export type ReportCreateManyInput = { @@ -7961,6 +7980,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: string | null disabled?: boolean | null udap_id?: string | null + redactedById?: string | null } export type ReportUpdateManyMutationInput = { @@ -7982,6 +8002,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: NullableStringFieldUpdateOperationsInput | string | null disabled?: NullableBoolFieldUpdateOperationsInput | boolean | null udap_id?: NullableStringFieldUpdateOperationsInput | string | null + redactedById?: NullableStringFieldUpdateOperationsInput | string | null } export type ReportUncheckedUpdateManyInput = { @@ -8004,6 +8025,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: NullableStringFieldUpdateOperationsInput | string | null disabled?: NullableBoolFieldUpdateOperationsInput | boolean | null udap_id?: NullableStringFieldUpdateOperationsInput | string | null + redactedById?: NullableStringFieldUpdateOperationsInput | string | null } export type Service_instructeursCreateInput = { @@ -8401,6 +8423,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: SortOrder disabled?: SortOrder udap_id?: SortOrder + redactedById?: SortOrder } export type ReportAvgOrderByAggregateInput = { @@ -8427,6 +8450,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: SortOrder disabled?: SortOrder udap_id?: SortOrder + redactedById?: SortOrder } export type ReportMinOrderByAggregateInput = { @@ -8449,6 +8473,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: SortOrder disabled?: SortOrder udap_id?: SortOrder + redactedById?: SortOrder } export type ReportSumOrderByAggregateInput = { @@ -9381,6 +9406,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: string | null disabled?: boolean | null udap_id?: string | null + redactedById?: string | null } export type ReportUncheckedCreateWithoutUserInput = { @@ -9402,6 +9428,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: string | null disabled?: boolean | null udap_id?: string | null + redactedById?: string | null } export type ReportCreateOrConnectWithoutUserInput = { @@ -9530,6 +9557,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: StringNullableFilter | string | null disabled?: BoolNullableFilter | boolean | null udap_id?: StringNullableFilter | string | null + redactedById?: StringNullableFilter | string | null } export type UdapUpsertWithoutUserInput = { @@ -9622,6 +9650,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: string | null disabled?: boolean | null udap_id?: string | null + redactedById?: string | null } export type DelegationUpdateWithoutUser_delegation_createdByTouserInput = { @@ -9667,6 +9696,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: NullableStringFieldUpdateOperationsInput | string | null disabled?: NullableBoolFieldUpdateOperationsInput | boolean | null udap_id?: NullableStringFieldUpdateOperationsInput | string | null + redactedById?: NullableStringFieldUpdateOperationsInput | string | null } export type ReportUncheckedUpdateWithoutUserInput = { @@ -9688,6 +9718,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: NullableStringFieldUpdateOperationsInput | string | null disabled?: NullableBoolFieldUpdateOperationsInput | boolean | null udap_id?: NullableStringFieldUpdateOperationsInput | string | null + redactedById?: NullableStringFieldUpdateOperationsInput | string | null } export type ReportUncheckedUpdateManyWithoutReportInput = { @@ -9709,6 +9740,7 @@ export type InputJsonValue = null | string | number | boolean | InputJsonObject pdf?: NullableStringFieldUpdateOperationsInput | string | null disabled?: NullableBoolFieldUpdateOperationsInput | boolean | null udap_id?: NullableStringFieldUpdateOperationsInput | string | null + redactedById?: NullableStringFieldUpdateOperationsInput | string | null } diff --git a/packages/frontend/src/features/InfoForm.tsx b/packages/frontend/src/features/InfoForm.tsx index a3de06e2..24924684 100644 --- a/packages/frontend/src/features/InfoForm.tsx +++ b/packages/frontend/src/features/InfoForm.tsx @@ -54,6 +54,9 @@ export const InfoForm = () => { const redactedByQuery = useLiveQuery( db.delegation.liveMany({ where: { delegatedTo: user.id }, include: { user_delegation_createdByTouser: true } }), ); + + console.log(redactedByQuery); + const redactedByOptions = redactedByQuery.results?.map((delegation) => ({ value: (delegation as any).user_delegation_createdByTouser?.name, label: (delegation as any).user_delegation_createdByTouser?.name, diff --git a/packages/frontend/src/routes/edit.$reportId.tsx b/packages/frontend/src/routes/edit.$reportId.tsx index b8de4363..fdcb20d7 100644 --- a/packages/frontend/src/routes/edit.$reportId.tsx +++ b/packages/frontend/src/routes/edit.$reportId.tsx @@ -78,6 +78,7 @@ const WithReport = ({ report }: { report: Report }) => { const userDelegations = useLiveQuery( db.delegation.liveFirst({ where: { createdBy: report.createdBy, delegatedTo: user.id } }), ); + const hasDelegation = !!userDelegations.results; const canEdit = isOwner || hasDelegation; console.log({ hasDelegation, canEdit });