diff --git a/db/migrations/01-add_users.sql b/db/migrations/01-add_users.sql index 05d42c09..5edf44cb 100644 --- a/db/migrations/01-add_users.sql +++ b/db/migrations/01-add_users.sql @@ -10,6 +10,9 @@ CREATE TABLE "udap"( ,city TEXT ,phone TEXT ,email TEXT + ,marianne_text TEXT + ,drac_text TEXT + ,udap_text TEXT ); ALTER TABLE "udap" ENABLE ELECTRIC; diff --git a/db/migrations/06-add_udap_drac.sql b/db/migrations/06-add_udap_drac.sql deleted file mode 100644 index 246e3533..00000000 --- a/db/migrations/06-add_udap_drac.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE udap ADD COLUMN marianne_text text; -ALTER TABLE udap ADD COLUMN drac_text text; -ALTER TABLE udap ADD COLUMN udap_text text; \ No newline at end of file diff --git a/db/migrations/06-insert_drac.sql b/db/migrations/06-insert_drac.sql new file mode 100644 index 00000000..bda781ad --- /dev/null +++ b/db/migrations/06-insert_drac.sql @@ -0,0 +1,31 @@ + +UPDATE udap SET marianne_text='Préfet +de la région +Nouvelle-Aquitaine', drac_text='Direction régionale des affaires +culturelles de Nouvelle-Aquitaine', udap_text='Unité départementale de +l''architecture et du patrimone des Landes' WHERE id='udap-landes'; +UPDATE udap SET marianne_text='Préfet +de la région +Nouvelle-Aquitaine', drac_text='Direction régionale des affaires +culturelles de Nouvelle-Aquitaine', udap_text='Unité départementale de +l''architecture et du patrimone des Deux-Sèvres' WHERE id= 'udap-deux-sèvres'; +UPDATE udap SET marianne_text='Préfet +de la région +Nouvelle-Aquitaine', drac_text='Direction régionale des affaires +culturelles de Nouvelle-Aquitaine', udap_text='Unité départementale de +l''architecture et du patrimone de la Vienne' WHERE id= 'udap-vienne'; +UPDATE udap SET marianne_text='Préfet +de la région +Nouvelle-Aquitaine', drac_text='Direction régionale des affaires +culturelles de Nouvelle-Aquitaine', udap_text='Unité départementale de +l''architecture et du patrimone de la Charente-Maritime' WHERE id= 'udap-charente-maritime'; +UPDATE udap SET marianne_text='Préfet +de la région +Nouvelle-Aquitaine', drac_text='Direction régionale des affaires +culturelles de Nouvelle-Aquitaine', udap_text='Unité départementale de +l''architecture et du patrimone du Lot-et-Garonne' WHERE id='udap-lot-et-garonne'; +UPDATE udap SET marianne_text='Préfet +de la région +Nouvelle-Aquitaine', drac_text='Direction régionale des affaires +culturelles de Nouvelle-Aquitaine', udap_text='Unité départementale de +l''architecture et du patrimone de la Dordogne' WHERE id='udap-dordogne'; \ No newline at end of file diff --git a/db/migrations/07-insert_drac.sql b/db/migrations/07-insert_drac.sql deleted file mode 100644 index a3061094..00000000 --- a/db/migrations/07-insert_drac.sql +++ /dev/null @@ -1,7 +0,0 @@ - -UPDATE udap SET marianne_text='Préfet de la région Nouvelle-Aquitaine', drac_text='Direction régionale des affaires culturelles de Nouvelle-Aquitaine', udap_text='Unité départementale de l''architecture et du patrimone des Landes' WHERE id='udap-landes'; -UPDATE udap SET marianne_text='Préfet de la région Nouvelle-Aquitaine', drac_text='Direction régionale des affaires culturelles de Nouvelle-Aquitaine', udap_text='Unité départementale de l''architecture et du patrimone des Deux-Sèvres' WHERE id= 'udap-deux-sèvres'; -UPDATE udap SET marianne_text='Préfet de la région Nouvelle-Aquitaine', drac_text='Direction régionale des affaires culturelles de Nouvelle-Aquitaine', udap_text='Unité départementale de l''architecture et du patrimone de la Vienne' WHERE id= 'udap-vienne'; -UPDATE udap SET marianne_text='Préfet de la région Nouvelle-Aquitaine', drac_text='Direction régionale des affaires culturelles de Nouvelle-Aquitaine', udap_text='Unité départementale de l''architecture et du patrimone de la Charente-Maritime' WHERE id= 'udap-charente-maritime'; -UPDATE udap SET marianne_text='Préfet de la région Nouvelle-Aquitaine', drac_text='Direction régionale des affaires culturelles de Nouvelle-Aquitaine', udap_text='Unité départementale de l''architecture et du patrimone du Lot-et-Garonne' WHERE id='udap-lot-et-garonne'; -UPDATE udap SET marianne_text='Préfet de la région Nouvelle-Aquitaine', drac_text='Direction régionale des affaires culturelles de Nouvelle-Aquitaine', udap_text='Unité départementale de l''architecture et du patrimone de la Dordogne' WHERE id='udap-dordogne'; \ No newline at end of file diff --git a/packages/backend/openapi.json b/packages/backend/openapi.json index 27d8863d..17578ad7 100644 --- a/packages/backend/openapi.json +++ b/packages/backend/openapi.json @@ -1 +1 @@ -{"openapi":"3.1.0","info":{"title":"CR VIF API","description":"CR VIF API Documentation","version":"1.0"},"components":{"schemas":{}},"paths":{"/api/create-user":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"udap_id":{"type":"string"},"email":{"type":"string"},"password":{"type":"string"}},"required":["name","udap_id","email","password"]}}},"required":true},"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","properties":{"user":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"udap_id":{"type":"string"},"udap":{"type":"object","properties":{"id":{"type":"string"},"department":{"type":"string"},"completeCoords":{"type":"string"},"visible":{"type":"boolean"},"name":{"type":"string"},"address":{"type":"string"},"zipCode":{"type":"string"},"city":{"type":"string"},"phone":{"type":"string"},"email":{"type":"string"}},"required":["id","department"]}},"required":["id","name","udap_id","udap"]},"token":{"type":"string"},"refreshToken":{"type":"string"}},"required":["token","refreshToken"]}}}}}}},"/api/login":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"type":"string"},"password":{"type":"string"}},"required":["email","password"]}}},"required":true},"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","properties":{"user":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"udap_id":{"type":"string"},"udap":{"type":"object","properties":{"id":{"type":"string"},"department":{"type":"string"},"completeCoords":{"type":"string"},"visible":{"type":"boolean"},"name":{"type":"string"},"address":{"type":"string"},"zipCode":{"type":"string"},"city":{"type":"string"},"phone":{"type":"string"},"email":{"type":"string"}},"required":["id","department"]}},"required":["id","name","udap_id","udap"]},"token":{"type":"string"},"refreshToken":{"type":"string"}},"required":["token","refreshToken"]}}}}}}},"/api/refresh-token":{"get":{"parameters":[{"schema":{"type":"string"},"in":"query","name":"token","required":true},{"schema":{"type":"string"},"in":"query","name":"refreshToken","required":false}],"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","properties":{"user":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"udap_id":{"type":"string"},"udap":{"type":"object","properties":{"id":{"type":"string"},"department":{"type":"string"},"completeCoords":{"type":"string"},"visible":{"type":"boolean"},"name":{"type":"string"},"address":{"type":"string"},"zipCode":{"type":"string"},"city":{"type":"string"},"phone":{"type":"string"},"email":{"type":"string"}},"required":["id","department"]}},"required":["id","name","udap_id","udap"]},"token":{"type":"string"},"refreshToken":{"type":"string"}},"required":["token","refreshToken"]}}}}}}},"/api/send-reset-password":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"type":"string"}},"required":["email"]}}},"required":true},"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string"}},"required":["message"]}}}}}}},"/api/reset-password":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"temporaryLink":{"type":"string"},"newPassword":{"type":"string"}},"required":["temporaryLink","newPassword"]}}},"required":true},"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string"}},"required":["message"]}}}}}}},"/api/udaps":{"get":{"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"},"department":{"type":"string"},"completeCoords":{"type":"string"},"visible":{"type":"boolean"},"name":{"type":"string"},"address":{"type":"string"},"zipCode":{"type":"string"},"city":{"type":"string"},"phone":{"type":"string"},"email":{"type":"string"}},"required":["id","department"]}}}}}}}},"/api/pdf/report":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"htmlString":{"type":"string"},"reportId":{"type":"string"},"recipients":{"type":"string"}},"required":["htmlString","reportId","recipients"]}}},"required":true},"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"string"}}}}}},"get":{"parameters":[{"schema":{"type":"string"},"in":"query","name":"reportId","required":true}],"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","properties":{}}}}}}}}}} \ No newline at end of file +{"openapi":"3.1.0","info":{"title":"CR VIF API","description":"CR VIF API Documentation","version":"1.0"},"components":{"schemas":{}},"paths":{"/api/create-user":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"name":{"type":"string"},"udap_id":{"type":"string"},"email":{"type":"string"},"password":{"type":"string"}},"required":["name","udap_id","email","password"]}}},"required":true},"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","properties":{"user":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"udap_id":{"type":"string"},"udap":{"type":"object","properties":{"id":{"type":"string"},"department":{"type":"string"},"completeCoords":{"type":"string"},"visible":{"type":"boolean"},"name":{"type":"string"},"address":{"type":"string"},"zipCode":{"type":"string"},"city":{"type":"string"},"phone":{"type":"string"},"email":{"type":"string"},"marianne_text":{"type":"string"},"drac_text":{"type":"string"},"udap_text":{"type":"string"}},"required":["id","department"]}},"required":["id","name","udap_id","udap"]},"token":{"type":"string"},"refreshToken":{"type":"string"}},"required":["token","refreshToken"]}}}}}}},"/api/login":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"type":"string"},"password":{"type":"string"}},"required":["email","password"]}}},"required":true},"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","properties":{"user":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"udap_id":{"type":"string"},"udap":{"type":"object","properties":{"id":{"type":"string"},"department":{"type":"string"},"completeCoords":{"type":"string"},"visible":{"type":"boolean"},"name":{"type":"string"},"address":{"type":"string"},"zipCode":{"type":"string"},"city":{"type":"string"},"phone":{"type":"string"},"email":{"type":"string"},"marianne_text":{"type":"string"},"drac_text":{"type":"string"},"udap_text":{"type":"string"}},"required":["id","department"]}},"required":["id","name","udap_id","udap"]},"token":{"type":"string"},"refreshToken":{"type":"string"}},"required":["token","refreshToken"]}}}}}}},"/api/refresh-token":{"get":{"parameters":[{"schema":{"type":"string"},"in":"query","name":"token","required":true},{"schema":{"type":"string"},"in":"query","name":"refreshToken","required":false}],"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","properties":{"user":{"type":"object","properties":{"id":{"type":"string"},"name":{"type":"string"},"udap_id":{"type":"string"},"udap":{"type":"object","properties":{"id":{"type":"string"},"department":{"type":"string"},"completeCoords":{"type":"string"},"visible":{"type":"boolean"},"name":{"type":"string"},"address":{"type":"string"},"zipCode":{"type":"string"},"city":{"type":"string"},"phone":{"type":"string"},"email":{"type":"string"},"marianne_text":{"type":"string"},"drac_text":{"type":"string"},"udap_text":{"type":"string"}},"required":["id","department"]}},"required":["id","name","udap_id","udap"]},"token":{"type":"string"},"refreshToken":{"type":"string"}},"required":["token","refreshToken"]}}}}}}},"/api/send-reset-password":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"type":"string"}},"required":["email"]}}},"required":true},"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string"}},"required":["message"]}}}}}}},"/api/reset-password":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"temporaryLink":{"type":"string"},"newPassword":{"type":"string"}},"required":["temporaryLink","newPassword"]}}},"required":true},"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","properties":{"message":{"type":"string"}},"required":["message"]}}}}}}},"/api/udaps":{"get":{"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string"},"department":{"type":"string"},"completeCoords":{"type":"string"},"visible":{"type":"boolean"},"name":{"type":"string"},"address":{"type":"string"},"zipCode":{"type":"string"},"city":{"type":"string"},"phone":{"type":"string"},"email":{"type":"string"},"marianne_text":{"type":"string"},"drac_text":{"type":"string"},"udap_text":{"type":"string"}},"required":["id","department"]}}}}}}}},"/api/pdf/report":{"post":{"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"htmlString":{"type":"string"},"reportId":{"type":"string"},"recipients":{"type":"string"}},"required":["htmlString","reportId","recipients"]}}},"required":true},"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"string"}}}}}},"get":{"parameters":[{"schema":{"type":"string"},"in":"query","name":"reportId","required":true}],"responses":{"200":{"description":"Default Response","content":{"application/json":{"schema":{"type":"object","properties":{}}}}}}}}}} \ No newline at end of file diff --git a/packages/backend/public/marianne.png b/packages/backend/public/marianne.png new file mode 100644 index 00000000..b9d39d8c Binary files /dev/null and b/packages/backend/public/marianne.png differ diff --git a/packages/backend/public/marianne_footer.png b/packages/backend/public/marianne_footer.png new file mode 100644 index 00000000..b44d1abd Binary files /dev/null and b/packages/backend/public/marianne_footer.png differ diff --git a/packages/backend/public/pdf_header.png b/packages/backend/public/pdf_header.png deleted file mode 100644 index 83289824..00000000 Binary files a/packages/backend/public/pdf_header.png and /dev/null differ diff --git a/packages/backend/src/routes/pdfRoutes.tsx b/packages/backend/src/routes/pdfRoutes.tsx index ea761797..b7bf1972 100644 --- a/packages/backend/src/routes/pdfRoutes.tsx +++ b/packages/backend/src/routes/pdfRoutes.tsx @@ -57,7 +57,11 @@ export const pdfPlugin: FastifyPluginAsyncTypebox = async (fastify, _) => { const generatePdf = async ({ htmlString, udap }: { htmlString: string; udap: Udap }) => { return renderToBuffer( - , + , ); }; diff --git a/packages/backend/src/services/userService.ts b/packages/backend/src/services/userService.ts index e3454678..db54e953 100644 --- a/packages/backend/src/services/userService.ts +++ b/packages/backend/src/services/userService.ts @@ -83,6 +83,7 @@ export class UserService { }, }, }); + console.log(user?.user); assertUserExists(user); await assertPasswordsMatch(payload.password, user!.password); diff --git a/packages/electric-client/prisma/schema.prisma b/packages/electric-client/prisma/schema.prisma index c6d6b6d5..6bfea15c 100644 --- a/packages/electric-client/prisma/schema.prisma +++ b/packages/electric-client/prisma/schema.prisma @@ -28,18 +28,20 @@ model atdatabases_migrations_version { } model clause { - id String @id - label String - value String - report_to_clause report_to_clause[] + key String + value String + udap_id String + text String + + @@id([key, value, udap_id]) } model report { - id String @id + id String @id title String? projectDescription String? redactedBy String? - meetDate DateTime? @db.Timestamp(6) + meetDate DateTime? @db.Timestamp(6) applicantName String? applicantAddress String? projectCadastralRef String? @@ -49,30 +51,12 @@ model report { contacts String? furtherInformation String? createdBy String - createdAt DateTime @db.Timestamp(6) + createdAt DateTime @db.Timestamp(6) serviceInstructeur Int? pdf String? disabled Boolean? udap_id String? - user user @relation(fields: [createdBy], references: [id], onDelete: SetNull, onUpdate: NoAction) - report_to_clause report_to_clause[] -} - -model report_to_clause { - id String @id - reportId String - clauseId String - clause clause @relation(fields: [clauseId], references: [id], onDelete: Cascade, onUpdate: NoAction) - report report @relation(fields: [reportId], references: [id], onDelete: Cascade, onUpdate: NoAction) -} - -model chip { - key String - value String - udap_id String - text String - - @@id([key, value, udap_id]) + user user @relation(fields: [createdBy], references: [id], onDelete: SetNull, onUpdate: NoAction) } model delegation { @@ -95,6 +79,9 @@ model udap { city String? phone String? email String? + marianne_text String? + drac_text String? + udap_text String? user user[] } diff --git a/packages/electric-client/src/generated/client/migrations.ts b/packages/electric-client/src/generated/client/migrations.ts index 9e794b57..cdd5d644 100644 --- a/packages/electric-client/src/generated/client/migrations.ts +++ b/packages/electric-client/src/generated/client/migrations.ts @@ -1,18 +1,18 @@ export default [ { "statements": [ - "CREATE TABLE \"udap\" (\n \"id\" TEXT NOT NULL,\n \"department\" TEXT NOT NULL,\n \"completeCoords\" TEXT,\n \"visible\" INTEGER,\n \"name\" TEXT,\n \"address\" TEXT,\n \"zipCode\" TEXT,\n \"city\" TEXT,\n \"phone\" TEXT,\n \"email\" TEXT,\n CONSTRAINT \"udap_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n", + "CREATE TABLE \"udap\" (\n \"id\" TEXT NOT NULL,\n \"department\" TEXT NOT NULL,\n \"completeCoords\" TEXT,\n \"visible\" INTEGER,\n \"name\" TEXT,\n \"address\" TEXT,\n \"zipCode\" TEXT,\n \"city\" TEXT,\n \"phone\" TEXT,\n \"email\" TEXT,\n \"marianne_text\" TEXT,\n \"drac_text\" TEXT,\n \"udap_text\" TEXT,\n CONSTRAINT \"udap_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n", "CREATE TABLE \"user\" (\n \"id\" TEXT NOT NULL,\n \"name\" TEXT NOT NULL,\n \"udap_id\" TEXT NOT NULL,\n CONSTRAINT \"user_udap_id_fkey\" FOREIGN KEY (\"udap_id\") REFERENCES \"udap\" (\"id\") ON DELETE SET NULL,\n CONSTRAINT \"user_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n", "CREATE TABLE \"delegation\" (\n \"createdBy\" TEXT NOT NULL,\n \"delegatedTo\" TEXT NOT NULL,\n CONSTRAINT \"delegation_createdBy_fkey\" FOREIGN KEY (\"createdBy\") REFERENCES \"user\" (\"id\") ON DELETE CASCADE,\n CONSTRAINT \"delegation_delegatedTo_fkey\" FOREIGN KEY (\"delegatedTo\") REFERENCES \"user\" (\"id\") ON DELETE CASCADE,\n CONSTRAINT \"delegation_pkey\" PRIMARY KEY (\"createdBy\", \"delegatedTo\")\n) WITHOUT ROWID;\n", "INSERT OR IGNORE INTO _electric_trigger_settings (namespace, tablename, flag) VALUES ('main', 'udap', 1);", "DROP TRIGGER IF EXISTS update_ensure_main_udap_primarykey;", "CREATE TRIGGER update_ensure_main_udap_primarykey\n BEFORE UPDATE ON \"main\".\"udap\"\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_udap_into_oplog;", - "CREATE TRIGGER insert_main_udap_into_oplog\n AFTER INSERT ON \"main\".\"udap\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'udap')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'udap', 'INSERT', json_patch('{}', json_object('id', new.\"id\")), json_object('address', new.\"address\", 'city', new.\"city\", 'completeCoords', new.\"completeCoords\", 'department', new.\"department\", 'email', new.\"email\", 'id', new.\"id\", 'name', new.\"name\", 'phone', new.\"phone\", 'visible', new.\"visible\", 'zipCode', new.\"zipCode\"), NULL, NULL);\nEND;", + "CREATE TRIGGER insert_main_udap_into_oplog\n AFTER INSERT ON \"main\".\"udap\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'udap')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'udap', 'INSERT', json_patch('{}', json_object('id', new.\"id\")), json_object('address', new.\"address\", 'city', new.\"city\", 'completeCoords', new.\"completeCoords\", 'department', new.\"department\", 'drac_text', new.\"drac_text\", 'email', new.\"email\", 'id', new.\"id\", 'marianne_text', new.\"marianne_text\", 'name', new.\"name\", 'phone', new.\"phone\", 'udap_text', new.\"udap_text\", 'visible', new.\"visible\", 'zipCode', new.\"zipCode\"), NULL, NULL);\nEND;", "DROP TRIGGER IF EXISTS update_main_udap_into_oplog;", - "CREATE TRIGGER update_main_udap_into_oplog\n AFTER UPDATE ON \"main\".\"udap\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'udap')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'udap', 'UPDATE', json_patch('{}', json_object('id', new.\"id\")), json_object('address', new.\"address\", 'city', new.\"city\", 'completeCoords', new.\"completeCoords\", 'department', new.\"department\", 'email', new.\"email\", 'id', new.\"id\", 'name', new.\"name\", 'phone', new.\"phone\", 'visible', new.\"visible\", 'zipCode', new.\"zipCode\"), json_object('address', old.\"address\", 'city', old.\"city\", 'completeCoords', old.\"completeCoords\", 'department', old.\"department\", 'email', old.\"email\", 'id', old.\"id\", 'name', old.\"name\", 'phone', old.\"phone\", 'visible', old.\"visible\", 'zipCode', old.\"zipCode\"), NULL);\nEND;", + "CREATE TRIGGER update_main_udap_into_oplog\n AFTER UPDATE ON \"main\".\"udap\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'udap')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'udap', 'UPDATE', json_patch('{}', json_object('id', new.\"id\")), json_object('address', new.\"address\", 'city', new.\"city\", 'completeCoords', new.\"completeCoords\", 'department', new.\"department\", 'drac_text', new.\"drac_text\", 'email', new.\"email\", 'id', new.\"id\", 'marianne_text', new.\"marianne_text\", 'name', new.\"name\", 'phone', new.\"phone\", 'udap_text', new.\"udap_text\", 'visible', new.\"visible\", 'zipCode', new.\"zipCode\"), json_object('address', old.\"address\", 'city', old.\"city\", 'completeCoords', old.\"completeCoords\", 'department', old.\"department\", 'drac_text', old.\"drac_text\", 'email', old.\"email\", 'id', old.\"id\", 'marianne_text', old.\"marianne_text\", 'name', old.\"name\", 'phone', old.\"phone\", 'udap_text', old.\"udap_text\", 'visible', old.\"visible\", 'zipCode', old.\"zipCode\"), NULL);\nEND;", "DROP TRIGGER IF EXISTS delete_main_udap_into_oplog;", - "CREATE TRIGGER delete_main_udap_into_oplog\n AFTER DELETE ON \"main\".\"udap\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'udap')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'udap', 'DELETE', json_patch('{}', json_object('id', old.\"id\")), NULL, json_object('address', old.\"address\", 'city', old.\"city\", 'completeCoords', old.\"completeCoords\", 'department', old.\"department\", 'email', old.\"email\", 'id', old.\"id\", 'name', old.\"name\", 'phone', old.\"phone\", 'visible', old.\"visible\", 'zipCode', old.\"zipCode\"), NULL);\nEND;", + "CREATE TRIGGER delete_main_udap_into_oplog\n AFTER DELETE ON \"main\".\"udap\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'udap')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'udap', 'DELETE', json_patch('{}', json_object('id', old.\"id\")), NULL, json_object('address', old.\"address\", 'city', old.\"city\", 'completeCoords', old.\"completeCoords\", 'department', old.\"department\", 'drac_text', old.\"drac_text\", 'email', old.\"email\", 'id', old.\"id\", 'marianne_text', old.\"marianne_text\", 'name', old.\"name\", 'phone', old.\"phone\", 'udap_text', old.\"udap_text\", 'visible', old.\"visible\", 'zipCode', old.\"zipCode\"), NULL);\nEND;", "INSERT OR IGNORE INTO _electric_trigger_settings (namespace, tablename, flag) VALUES ('main', 'user', 1);", "DROP TRIGGER IF EXISTS update_ensure_main_user_primarykey;", "CREATE TRIGGER update_ensure_main_user_primarykey\n BEFORE UPDATE ON \"main\".\"user\"\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;", @@ -79,22 +79,5 @@ export default [ "CREATE TRIGGER delete_main_clause_into_oplog\n AFTER DELETE ON \"main\".\"clause\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'clause')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'clause', 'DELETE', json_patch('{}', json_object('key', old.\"key\", 'udap_id', old.\"udap_id\", 'value', old.\"value\")), NULL, json_object('key', old.\"key\", 'text', old.\"text\", 'udap_id', old.\"udap_id\", 'value', old.\"value\"), NULL);\nEND;" ], "version": "4" - }, - { - "statements": [ - "ALTER TABLE \"udap\" ADD COLUMN \"marianne_text\" TEXT;\n", - "ALTER TABLE \"udap\" ADD COLUMN \"drac_text\" TEXT;\n", - "ALTER TABLE \"udap\" ADD COLUMN \"udap_text\" TEXT;\n", - "INSERT OR IGNORE INTO _electric_trigger_settings (namespace, tablename, flag) VALUES ('main', 'udap', 1);", - "DROP TRIGGER IF EXISTS update_ensure_main_udap_primarykey;", - "CREATE TRIGGER update_ensure_main_udap_primarykey\n BEFORE UPDATE ON \"main\".\"udap\"\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_udap_into_oplog;", - "CREATE TRIGGER insert_main_udap_into_oplog\n AFTER INSERT ON \"main\".\"udap\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'udap')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'udap', 'INSERT', json_patch('{}', json_object('id', new.\"id\")), json_object('address', new.\"address\", 'city', new.\"city\", 'completeCoords', new.\"completeCoords\", 'department', new.\"department\", 'drac_text', new.\"drac_text\", 'email', new.\"email\", 'id', new.\"id\", 'marianne_text', new.\"marianne_text\", 'name', new.\"name\", 'phone', new.\"phone\", 'udap_text', new.\"udap_text\", 'visible', new.\"visible\", 'zipCode', new.\"zipCode\"), NULL, NULL);\nEND;", - "DROP TRIGGER IF EXISTS update_main_udap_into_oplog;", - "CREATE TRIGGER update_main_udap_into_oplog\n AFTER UPDATE ON \"main\".\"udap\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'udap')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'udap', 'UPDATE', json_patch('{}', json_object('id', new.\"id\")), json_object('address', new.\"address\", 'city', new.\"city\", 'completeCoords', new.\"completeCoords\", 'department', new.\"department\", 'drac_text', new.\"drac_text\", 'email', new.\"email\", 'id', new.\"id\", 'marianne_text', new.\"marianne_text\", 'name', new.\"name\", 'phone', new.\"phone\", 'udap_text', new.\"udap_text\", 'visible', new.\"visible\", 'zipCode', new.\"zipCode\"), json_object('address', old.\"address\", 'city', old.\"city\", 'completeCoords', old.\"completeCoords\", 'department', old.\"department\", 'drac_text', old.\"drac_text\", 'email', old.\"email\", 'id', old.\"id\", 'marianne_text', old.\"marianne_text\", 'name', old.\"name\", 'phone', old.\"phone\", 'udap_text', old.\"udap_text\", 'visible', old.\"visible\", 'zipCode', old.\"zipCode\"), NULL);\nEND;", - "DROP TRIGGER IF EXISTS delete_main_udap_into_oplog;", - "CREATE TRIGGER delete_main_udap_into_oplog\n AFTER DELETE ON \"main\".\"udap\"\n WHEN 1 = (SELECT flag from _electric_trigger_settings WHERE namespace = 'main' AND tablename = 'udap')\nBEGIN\n INSERT INTO _electric_oplog (namespace, tablename, optype, primaryKey, newRow, oldRow, timestamp)\n VALUES ('main', 'udap', 'DELETE', json_patch('{}', json_object('id', old.\"id\")), NULL, json_object('address', old.\"address\", 'city', old.\"city\", 'completeCoords', old.\"completeCoords\", 'department', old.\"department\", 'drac_text', old.\"drac_text\", 'email', old.\"email\", 'id', old.\"id\", 'marianne_text', old.\"marianne_text\", 'name', old.\"name\", 'phone', old.\"phone\", 'udap_text', old.\"udap_text\", 'visible', old.\"visible\", 'zipCode', old.\"zipCode\"), NULL);\nEND;" - ], - "version": "6" } ] \ 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 243fc126..a6cfdf32 100644 --- a/packages/electric-client/src/generated/client/pg-migrations.ts +++ b/packages/electric-client/src/generated/client/pg-migrations.ts @@ -1,7 +1,7 @@ export default [ { "statements": [ - "CREATE TABLE udap (\n id text NOT NULL,\n department text NOT NULL,\n \"completeCoords\" text,\n visible boolean,\n name text,\n address text,\n \"zipCode\" text,\n city text,\n phone text,\n email text,\n CONSTRAINT udap_pkey PRIMARY KEY (id)\n)", + "CREATE TABLE udap (\n id text NOT NULL,\n department text NOT NULL,\n \"completeCoords\" text,\n visible boolean,\n name text,\n address text,\n \"zipCode\" text,\n city text,\n phone text,\n email text,\n marianne_text text,\n drac_text text,\n udap_text text,\n CONSTRAINT udap_pkey PRIMARY KEY (id)\n)", "CREATE TABLE \"user\" (\n id text NOT NULL,\n name text NOT NULL,\n udap_id text NOT NULL,\n CONSTRAINT user_pkey PRIMARY KEY (id),\n CONSTRAINT user_udap_id_fkey FOREIGN KEY (udap_id) REFERENCES udap(id) ON DELETE SET NULL\n)", "CREATE TABLE delegation (\n \"createdBy\" text NOT NULL,\n \"delegatedTo\" text NOT NULL,\n CONSTRAINT delegation_pkey PRIMARY KEY (\"createdBy\", \"delegatedTo\"),\n CONSTRAINT \"delegation_createdBy_fkey\" FOREIGN KEY (\"createdBy\") REFERENCES \"user\"(id) ON DELETE CASCADE,\n CONSTRAINT \"delegation_delegatedTo_fkey\" FOREIGN KEY (\"delegatedTo\") REFERENCES \"user\"(id) ON DELETE CASCADE\n)", "INSERT INTO \"public\".\"_electric_trigger_settings\" (\"namespace\", \"tablename\", \"flag\")\n VALUES ('public', 'udap', 1)\n ON CONFLICT DO NOTHING;", @@ -9,13 +9,13 @@ export default [ "CREATE OR REPLACE FUNCTION update_ensure_public_udap_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_udap_primarykey\n BEFORE UPDATE ON \"public\".\"udap\"\n FOR EACH ROW\n EXECUTE FUNCTION update_ensure_public_udap_primarykey_function();", "DROP TRIGGER IF EXISTS insert_public_udap_into_oplog ON \"public\".\"udap\";", - " CREATE OR REPLACE FUNCTION insert_public_udap_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 = 'udap';\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 'udap',\n 'INSERT',\n json_strip_nulls(json_build_object('id', new.\"id\")),\n jsonb_build_object('address', new.\"address\", 'city', new.\"city\", 'completeCoords', new.\"completeCoords\", 'department', new.\"department\", 'email', new.\"email\", 'id', new.\"id\", 'name', new.\"name\", 'phone', new.\"phone\", 'visible', new.\"visible\", 'zipCode', new.\"zipCode\"),\n NULL,\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + " CREATE OR REPLACE FUNCTION insert_public_udap_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 = 'udap';\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 'udap',\n 'INSERT',\n json_strip_nulls(json_build_object('id', new.\"id\")),\n jsonb_build_object('address', new.\"address\", 'city', new.\"city\", 'completeCoords', new.\"completeCoords\", 'department', new.\"department\", 'drac_text', new.\"drac_text\", 'email', new.\"email\", 'id', new.\"id\", 'marianne_text', new.\"marianne_text\", 'name', new.\"name\", 'phone', new.\"phone\", 'udap_text', new.\"udap_text\", 'visible', new.\"visible\", 'zipCode', new.\"zipCode\"),\n NULL,\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", "CREATE TRIGGER insert_public_udap_into_oplog\n AFTER INSERT ON \"public\".\"udap\"\n FOR EACH ROW\n EXECUTE FUNCTION insert_public_udap_into_oplog_function();", "DROP TRIGGER IF EXISTS update_public_udap_into_oplog ON \"public\".\"udap\";", - " CREATE OR REPLACE FUNCTION update_public_udap_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 = 'udap';\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 'udap',\n 'UPDATE',\n json_strip_nulls(json_build_object('id', new.\"id\")),\n jsonb_build_object('address', new.\"address\", 'city', new.\"city\", 'completeCoords', new.\"completeCoords\", 'department', new.\"department\", 'email', new.\"email\", 'id', new.\"id\", 'name', new.\"name\", 'phone', new.\"phone\", 'visible', new.\"visible\", 'zipCode', new.\"zipCode\"),\n jsonb_build_object('address', old.\"address\", 'city', old.\"city\", 'completeCoords', old.\"completeCoords\", 'department', old.\"department\", 'email', old.\"email\", 'id', old.\"id\", 'name', old.\"name\", 'phone', old.\"phone\", 'visible', old.\"visible\", 'zipCode', old.\"zipCode\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + " CREATE OR REPLACE FUNCTION update_public_udap_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 = 'udap';\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 'udap',\n 'UPDATE',\n json_strip_nulls(json_build_object('id', new.\"id\")),\n jsonb_build_object('address', new.\"address\", 'city', new.\"city\", 'completeCoords', new.\"completeCoords\", 'department', new.\"department\", 'drac_text', new.\"drac_text\", 'email', new.\"email\", 'id', new.\"id\", 'marianne_text', new.\"marianne_text\", 'name', new.\"name\", 'phone', new.\"phone\", 'udap_text', new.\"udap_text\", 'visible', new.\"visible\", 'zipCode', new.\"zipCode\"),\n jsonb_build_object('address', old.\"address\", 'city', old.\"city\", 'completeCoords', old.\"completeCoords\", 'department', old.\"department\", 'drac_text', old.\"drac_text\", 'email', old.\"email\", 'id', old.\"id\", 'marianne_text', old.\"marianne_text\", 'name', old.\"name\", 'phone', old.\"phone\", 'udap_text', old.\"udap_text\", 'visible', old.\"visible\", 'zipCode', old.\"zipCode\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", "CREATE TRIGGER update_public_udap_into_oplog\n AFTER UPDATE ON \"public\".\"udap\"\n FOR EACH ROW\n EXECUTE FUNCTION update_public_udap_into_oplog_function();", "DROP TRIGGER IF EXISTS delete_public_udap_into_oplog ON \"public\".\"udap\";", - " CREATE OR REPLACE FUNCTION delete_public_udap_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 = 'udap';\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 'udap',\n 'DELETE',\n json_strip_nulls(json_build_object('id', old.\"id\")),\n NULL,\n jsonb_build_object('address', old.\"address\", 'city', old.\"city\", 'completeCoords', old.\"completeCoords\", 'department', old.\"department\", 'email', old.\"email\", 'id', old.\"id\", 'name', old.\"name\", 'phone', old.\"phone\", 'visible', old.\"visible\", 'zipCode', old.\"zipCode\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", + " CREATE OR REPLACE FUNCTION delete_public_udap_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 = 'udap';\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 'udap',\n 'DELETE',\n json_strip_nulls(json_build_object('id', old.\"id\")),\n NULL,\n jsonb_build_object('address', old.\"address\", 'city', old.\"city\", 'completeCoords', old.\"completeCoords\", 'department', old.\"department\", 'drac_text', old.\"drac_text\", 'email', old.\"email\", 'id', old.\"id\", 'marianne_text', old.\"marianne_text\", 'name', old.\"name\", 'phone', old.\"phone\", 'udap_text', old.\"udap_text\", 'visible', old.\"visible\", 'zipCode', old.\"zipCode\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", "CREATE TRIGGER delete_public_udap_into_oplog\n AFTER DELETE ON \"public\".\"udap\"\n FOR EACH ROW\n EXECUTE FUNCTION delete_public_udap_into_oplog_function();", "INSERT INTO \"public\".\"_electric_trigger_settings\" (\"namespace\", \"tablename\", \"flag\")\n VALUES ('public', 'user', 1)\n ON CONFLICT DO NOTHING;", "DROP TRIGGER IF EXISTS update_ensure_public_user_primarykey ON \"public\".\"user\";", @@ -107,26 +107,5 @@ export default [ "CREATE TRIGGER delete_public_clause_into_oplog\n AFTER DELETE ON \"public\".\"clause\"\n FOR EACH ROW\n EXECUTE FUNCTION delete_public_clause_into_oplog_function();" ], "version": "4" - }, - { - "statements": [ - "ALTER TABLE udap ADD COLUMN marianne_text text", - "ALTER TABLE udap ADD COLUMN drac_text text", - "ALTER TABLE udap ADD COLUMN udap_text text", - "INSERT INTO \"public\".\"_electric_trigger_settings\" (\"namespace\", \"tablename\", \"flag\")\n VALUES ('public', 'udap', 1)\n ON CONFLICT DO NOTHING;", - "DROP TRIGGER IF EXISTS update_ensure_public_udap_primarykey ON \"public\".\"udap\";", - "CREATE OR REPLACE FUNCTION update_ensure_public_udap_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_udap_primarykey\n BEFORE UPDATE ON \"public\".\"udap\"\n FOR EACH ROW\n EXECUTE FUNCTION update_ensure_public_udap_primarykey_function();", - "DROP TRIGGER IF EXISTS insert_public_udap_into_oplog ON \"public\".\"udap\";", - " CREATE OR REPLACE FUNCTION insert_public_udap_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 = 'udap';\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 'udap',\n 'INSERT',\n json_strip_nulls(json_build_object('id', new.\"id\")),\n jsonb_build_object('address', new.\"address\", 'city', new.\"city\", 'completeCoords', new.\"completeCoords\", 'department', new.\"department\", 'drac_text', new.\"drac_text\", 'email', new.\"email\", 'id', new.\"id\", 'marianne_text', new.\"marianne_text\", 'name', new.\"name\", 'phone', new.\"phone\", 'udap_text', new.\"udap_text\", 'visible', new.\"visible\", 'zipCode', new.\"zipCode\"),\n NULL,\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", - "CREATE TRIGGER insert_public_udap_into_oplog\n AFTER INSERT ON \"public\".\"udap\"\n FOR EACH ROW\n EXECUTE FUNCTION insert_public_udap_into_oplog_function();", - "DROP TRIGGER IF EXISTS update_public_udap_into_oplog ON \"public\".\"udap\";", - " CREATE OR REPLACE FUNCTION update_public_udap_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 = 'udap';\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 'udap',\n 'UPDATE',\n json_strip_nulls(json_build_object('id', new.\"id\")),\n jsonb_build_object('address', new.\"address\", 'city', new.\"city\", 'completeCoords', new.\"completeCoords\", 'department', new.\"department\", 'drac_text', new.\"drac_text\", 'email', new.\"email\", 'id', new.\"id\", 'marianne_text', new.\"marianne_text\", 'name', new.\"name\", 'phone', new.\"phone\", 'udap_text', new.\"udap_text\", 'visible', new.\"visible\", 'zipCode', new.\"zipCode\"),\n jsonb_build_object('address', old.\"address\", 'city', old.\"city\", 'completeCoords', old.\"completeCoords\", 'department', old.\"department\", 'drac_text', old.\"drac_text\", 'email', old.\"email\", 'id', old.\"id\", 'marianne_text', old.\"marianne_text\", 'name', old.\"name\", 'phone', old.\"phone\", 'udap_text', old.\"udap_text\", 'visible', old.\"visible\", 'zipCode', old.\"zipCode\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", - "CREATE TRIGGER update_public_udap_into_oplog\n AFTER UPDATE ON \"public\".\"udap\"\n FOR EACH ROW\n EXECUTE FUNCTION update_public_udap_into_oplog_function();", - "DROP TRIGGER IF EXISTS delete_public_udap_into_oplog ON \"public\".\"udap\";", - " CREATE OR REPLACE FUNCTION delete_public_udap_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 = 'udap';\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 'udap',\n 'DELETE',\n json_strip_nulls(json_build_object('id', old.\"id\")),\n NULL,\n jsonb_build_object('address', old.\"address\", 'city', old.\"city\", 'completeCoords', old.\"completeCoords\", 'department', old.\"department\", 'drac_text', old.\"drac_text\", 'email', old.\"email\", 'id', old.\"id\", 'marianne_text', old.\"marianne_text\", 'name', old.\"name\", 'phone', old.\"phone\", 'udap_text', old.\"udap_text\", 'visible', old.\"visible\", 'zipCode', old.\"zipCode\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;", - "CREATE TRIGGER delete_public_udap_into_oplog\n AFTER DELETE ON \"public\".\"udap\"\n FOR EACH ROW\n EXECUTE FUNCTION delete_public_udap_into_oplog_function();" - ], - "version": "6" } ] \ No newline at end of file diff --git a/packages/electric-client/src/generated/typebox/clause.ts b/packages/electric-client/src/generated/typebox/clause.ts index 2fcfb24d..0acd8be1 100644 --- a/packages/electric-client/src/generated/typebox/clause.ts +++ b/packages/electric-client/src/generated/typebox/clause.ts @@ -1,16 +1,10 @@ import { Type, Static } from "@sinclair/typebox"; export const clause = Type.Object({ - id: Type.String(), - label: Type.String(), + key: Type.String(), value: Type.String(), - report_to_clause: Type.Array( - Type.Object({ - id: Type.String(), - reportId: Type.String(), - clauseId: Type.String(), - }) - ), + udap_id: Type.String(), + text: Type.String(), }); export type clauseType = Static; diff --git a/packages/electric-client/src/generated/typebox/clauseInput.ts b/packages/electric-client/src/generated/typebox/clauseInput.ts index b590c526..a65a8988 100644 --- a/packages/electric-client/src/generated/typebox/clauseInput.ts +++ b/packages/electric-client/src/generated/typebox/clauseInput.ts @@ -1,16 +1,10 @@ import { Type, Static } from "@sinclair/typebox"; export const clauseInput = Type.Object({ - id: Type.String(), - label: Type.String(), + key: Type.String(), value: Type.String(), - report_to_clause: Type.Array( - Type.Object({ - id: Type.String(), - reportId: Type.String(), - clauseId: Type.String(), - }) - ), + udap_id: Type.String(), + text: Type.String(), }); export type clauseInputType = Static; diff --git a/packages/electric-client/src/generated/typebox/index.ts b/packages/electric-client/src/generated/typebox/index.ts index 1bb26650..0d1dd358 100644 --- a/packages/electric-client/src/generated/typebox/index.ts +++ b/packages/electric-client/src/generated/typebox/index.ts @@ -1,15 +1,11 @@ export * from './atdatabases_migrations_applied'; export * from './atdatabases_migrations_appliedInput'; -export * from './atdatabases_migrations_version'; export * from './atdatabases_migrations_versionInput'; +export * from './atdatabases_migrations_version'; export * from './clause'; export * from './clauseInput'; export * from './report'; export * from './reportInput'; -export * from './report_to_clause'; -export * from './report_to_clauseInput'; -export * from './chip'; -export * from './chipInput'; export * from './delegation'; export * from './delegationInput'; export * from './udap'; diff --git a/packages/electric-client/src/generated/typebox/report.ts b/packages/electric-client/src/generated/typebox/report.ts index a38021a3..a4c0ead6 100644 --- a/packages/electric-client/src/generated/typebox/report.ts +++ b/packages/electric-client/src/generated/typebox/report.ts @@ -25,13 +25,6 @@ export const report = Type.Object({ name: Type.String(), udap_id: Type.String(), }), - report_to_clause: Type.Array( - Type.Object({ - id: Type.String(), - reportId: Type.String(), - clauseId: Type.String(), - }) - ), }); export type reportType = Static; diff --git a/packages/electric-client/src/generated/typebox/reportInput.ts b/packages/electric-client/src/generated/typebox/reportInput.ts index 820093f5..159bb121 100644 --- a/packages/electric-client/src/generated/typebox/reportInput.ts +++ b/packages/electric-client/src/generated/typebox/reportInput.ts @@ -25,13 +25,6 @@ export const reportInput = Type.Object({ name: Type.String(), udap_id: Type.String(), }), - report_to_clause: Type.Array( - Type.Object({ - id: Type.String(), - reportId: Type.String(), - clauseId: Type.String(), - }) - ), }); export type reportInputType = Static; diff --git a/packages/electric-client/src/generated/typebox/udap.ts b/packages/electric-client/src/generated/typebox/udap.ts index 96a87bcc..373d55e7 100644 --- a/packages/electric-client/src/generated/typebox/udap.ts +++ b/packages/electric-client/src/generated/typebox/udap.ts @@ -11,6 +11,9 @@ export const udap = Type.Object({ city: Type.Optional(Type.String()), phone: Type.Optional(Type.String()), email: Type.Optional(Type.String()), + marianne_text: Type.Optional(Type.String()), + drac_text: Type.Optional(Type.String()), + udap_text: Type.Optional(Type.String()), user: Type.Array( Type.Object({ id: Type.String(), diff --git a/packages/electric-client/src/generated/typebox/udapInput.ts b/packages/electric-client/src/generated/typebox/udapInput.ts index 03dcaa28..8868c2c2 100644 --- a/packages/electric-client/src/generated/typebox/udapInput.ts +++ b/packages/electric-client/src/generated/typebox/udapInput.ts @@ -11,6 +11,9 @@ export const udapInput = Type.Object({ city: Type.Optional(Type.String()), phone: Type.Optional(Type.String()), email: Type.Optional(Type.String()), + marianne_text: Type.Optional(Type.String()), + drac_text: Type.Optional(Type.String()), + udap_text: Type.Optional(Type.String()), user: Type.Array( Type.Object({ id: Type.String(), diff --git a/packages/electric-client/src/generated/typebox/user.ts b/packages/electric-client/src/generated/typebox/user.ts index 99d7b598..4e03873b 100644 --- a/packages/electric-client/src/generated/typebox/user.ts +++ b/packages/electric-client/src/generated/typebox/user.ts @@ -61,6 +61,9 @@ export const user = Type.Object({ city: Type.Optional(Type.String()), phone: Type.Optional(Type.String()), email: Type.Optional(Type.String()), + marianne_text: Type.Optional(Type.String()), + drac_text: Type.Optional(Type.String()), + udap_text: Type.Optional(Type.String()), }), }); diff --git a/packages/electric-client/src/generated/typebox/userInput.ts b/packages/electric-client/src/generated/typebox/userInput.ts index 33cc65a6..66905d75 100644 --- a/packages/electric-client/src/generated/typebox/userInput.ts +++ b/packages/electric-client/src/generated/typebox/userInput.ts @@ -61,6 +61,9 @@ export const userInput = Type.Object({ city: Type.Optional(Type.String()), phone: Type.Optional(Type.String()), email: Type.Optional(Type.String()), + marianne_text: Type.Optional(Type.String()), + drac_text: Type.Optional(Type.String()), + udap_text: Type.Optional(Type.String()), }), }); diff --git a/packages/frontend/public/marianne.png b/packages/frontend/public/marianne.png new file mode 100644 index 00000000..b9d39d8c Binary files /dev/null and b/packages/frontend/public/marianne.png differ diff --git a/packages/frontend/public/marianne_footer.png b/packages/frontend/public/marianne_footer.png new file mode 100644 index 00000000..b44d1abd Binary files /dev/null and b/packages/frontend/public/marianne_footer.png differ diff --git a/packages/frontend/src/api.gen.ts b/packages/frontend/src/api.gen.ts index 34ad218a..9421109d 100644 --- a/packages/frontend/src/api.gen.ts +++ b/packages/frontend/src/api.gen.ts @@ -29,6 +29,9 @@ export namespace Endpoints { city?: string | undefined; phone?: string | undefined; email?: string | undefined; + marianne_text?: string | undefined; + drac_text?: string | undefined; + udap_text?: string | undefined; }; } | undefined; @@ -59,6 +62,9 @@ export namespace Endpoints { city?: string | undefined; phone?: string | undefined; email?: string | undefined; + marianne_text?: string | undefined; + drac_text?: string | undefined; + udap_text?: string | undefined; }; } | undefined; @@ -89,6 +95,9 @@ export namespace Endpoints { city?: string | undefined; phone?: string | undefined; email?: string | undefined; + marianne_text?: string | undefined; + drac_text?: string | undefined; + udap_text?: string | undefined; }; } | undefined; @@ -127,6 +136,9 @@ export namespace Endpoints { city?: string | undefined; phone?: string | undefined; email?: string | undefined; + marianne_text?: string | undefined; + drac_text?: string | undefined; + udap_text?: string | undefined; }>; }; export type post_Apipdfreport = { diff --git a/packages/frontend/src/routes/pdf.$reportId.tsx b/packages/frontend/src/routes/pdf.$reportId.tsx index 4d201c7b..5d1aa99c 100644 --- a/packages/frontend/src/routes/pdf.$reportId.tsx +++ b/packages/frontend/src/routes/pdf.$reportId.tsx @@ -252,7 +252,11 @@ export const WithReport = ({ initialHtmlString, mode }: { initialHtmlString: str const { udap } = useUser()!; const ViewDocument = ( - + ); if (mode === "view") return ViewDocument; @@ -273,6 +277,7 @@ export const WithReport = ({ initialHtmlString, mode }: { initialHtmlString: str }; const View = (props: ReportPDFDocumentProps) => { + console.log({ props }); const query = useQuery({ queryKey: ["report-pdf", props.htmlString], queryFn: async () => { diff --git a/packages/pdf/src/report.tsx b/packages/pdf/src/report.tsx index 35b254db..8fc1fd7a 100644 --- a/packages/pdf/src/report.tsx +++ b/packages/pdf/src/report.tsx @@ -5,14 +5,16 @@ import type { Udap, Report, Clause } from "@cr-vif/electric-client/frontend"; import serviceInstructeurs from "./serviceInstructeur.json"; export const ReportPDFDocument = ({ udap, htmlString, images }: ReportPDFDocumentProps) => { + console.log(images); return ( {` @@ -35,18 +37,48 @@ export const ReportPDFDocument = ({ udap, htmlString, images }: ReportPDFDocumen font-family: Helvetica-BoldOblique; } - img { - width: 150px; + .marianne-img { + width: 35px; + } + + .marianne-footer-img { + width: 50px; } .header { display: flex; flex-direction: row; width: 100%; + align-items: flex-start; justify-content: space-between; text-align: right; - align-items: center; font-size: 18px; + margin-bottom: 32px; + + } + + + .marianne-text { + text-align: left; + font-weight: bold; + font-size: 12px; + margin-top: 4px; + margin-bottom: 4px; + text-transform: uppercase; + } + + .right-texts { + display: flex; + align-items: flex-end; + flex-direction: column; + justify-content: flex-end; + gap: 20px; + } + + .right-texts > div { + text-align: right; + font-size: 16px; + font-family: Helvetica-Bold; } .meeting-date { @@ -59,8 +91,35 @@ export const ReportPDFDocument = ({ udap, htmlString, images }: ReportPDFDocumen
- -
${udap.name?.replace("UDAP", "Union départementale de
l'architecture et du
patrimoine")}
+
+ + +
+ + ${udap.marianne_text + ?.split("\n") + .map((s) => s.trim()) + .join("
")} +
+
+ + +
+ +
+
+ ${udap.drac_text + ?.split("\n") + .map((s) => s.trim()) + .join("
")} +
+
+ ${udap.udap_text + ?.split("\n") + .map((s) => s.trim()) + .join("
")} +
+
${htmlString} @@ -80,7 +139,8 @@ export type ReportPDFDocumentProps = { }; type Images = { - header: string; + marianne: string; + marianneFooter: string; }; export type ReportWithUser = Report & { user?: { email: string; name: string } };