Skip to content

Commit

Permalink
feat: add service instructeurs in db
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm authored Jun 17, 2024
2 parents 3f36efb + b9f2f7b commit 38d39ae
Show file tree
Hide file tree
Showing 20 changed files with 1,921 additions and 420 deletions.
111 changes: 1 addition & 110 deletions db/migrations/03-insert_udaps.sql

Large diffs are not rendered by default.

62 changes: 0 additions & 62 deletions db/migrations/04-add_chips_table.sql

Large diffs are not rendered by default.

32 changes: 1 addition & 31 deletions db/migrations/06-insert_drac.sql
Original file line number Diff line number Diff line change
@@ -1,31 +1 @@

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';
SELECT 1;
11 changes: 11 additions & 0 deletions db/migrations/07-add_service_instructeurs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS service_instructeurs (
id INTEGER NOT NULL PRIMARY KEY,
full_name TEXT NOT NULL,
short_name TEXT NOT NULL,
email TEXT,
tel TEXT,
udap_id TEXT
);


ALTER TABLE service_instructeurs ENABLE ELECTRIC;
1 change: 1 addition & 0 deletions db/migrations/08-migrate_report.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE report SET "serviceInstructeur" = NULL;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"pdf": "pnpm --filter @cr-vif/pdf",
"db:create": "pnpm backend migration:create",
"db:migrate": "pnpm db:create",
"electric:up": "pnpm electric-sql with-config \"pnpm pg-migrations apply --database {{ELECTRIC_PROXY}} --directory ./db/migrations\"",
"electric:up": "pnpm electric-sql with-config \"pnpm pg-migrations apply --database {{ELECTRIC_PROXY}} --ignore-error migration_file_edited --directory ./db/migrations\"",
"show-config": "pnpm electric-sql show-config",
"electric:migrate": "pnpm electric:up && pnpm electric-client generate:front && pnpm electric-client generate:back && pnpm client:generate",
"client:json": "pnpm backend dev --create-only",
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/routes/pdfRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const pdfPlugin: FastifyPluginAsyncTypebox = async (fastify, _) => {
},
},
async (request) => {
console.log("salut");
const { reportId } = request.query;
const buffer = await request.services.upload.getReportPDF({ reportId });

Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/services/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,8 @@ export class UserService {

getUserByToken(token: string) {
const payload = this.validateToken(token);
console.log(payload);
const { sub } = payload;
if (!sub) throw new AppError(403, "Token invalide");
console.log("token id", sub);
return this.getUserById(sub);
}

Expand Down
392 changes: 392 additions & 0 deletions packages/electric-client/src/generated/client/index.ts

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions packages/electric-client/src/generated/client/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,20 @@ 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": [
"CREATE TABLE \"service_instructeurs\" (\n \"id\" INTEGER NOT NULL,\n \"full_name\" TEXT NOT NULL,\n \"short_name\" TEXT NOT NULL,\n \"email\" TEXT,\n \"tel\" TEXT,\n \"udap_id\" TEXT,\n CONSTRAINT \"service_instructeurs_pkey\" PRIMARY KEY (\"id\")\n) WITHOUT ROWID;\n",
"INSERT OR IGNORE INTO _electric_trigger_settings (namespace, tablename, flag) VALUES ('main', 'service_instructeurs', 1);",
"DROP TRIGGER IF EXISTS update_ensure_main_service_instructeurs_primarykey;",
"CREATE TRIGGER update_ensure_main_service_instructeurs_primarykey\n BEFORE UPDATE ON \"main\".\"service_instructeurs\"\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_service_instructeurs_into_oplog;",
"CREATE TRIGGER insert_main_service_instructeurs_into_oplog\n AFTER INSERT 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', 'INSERT', json_patch('{}', json_object('id', new.\"id\")), json_object('email', new.\"email\", 'full_name', new.\"full_name\", 'id', new.\"id\", 'short_name', new.\"short_name\", 'tel', new.\"tel\", 'udap_id', new.\"udap_id\"), NULL, NULL);\nEND;",
"DROP TRIGGER IF EXISTS update_main_service_instructeurs_into_oplog;",
"CREATE TRIGGER update_main_service_instructeurs_into_oplog\n AFTER UPDATE 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', 'UPDATE', json_patch('{}', json_object('id', new.\"id\")), json_object('email', new.\"email\", 'full_name', new.\"full_name\", 'id', new.\"id\", 'short_name', new.\"short_name\", 'tel', new.\"tel\", 'udap_id', new.\"udap_id\"), 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;",
"DROP TRIGGER IF EXISTS delete_main_service_instructeurs_into_oplog;",
"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"
}
]
19 changes: 19 additions & 0 deletions packages/electric-client/src/generated/client/pg-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,24 @@ 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": [
"CREATE TABLE service_instructeurs (\n id integer NOT NULL,\n full_name text NOT NULL,\n short_name text NOT NULL,\n email text,\n tel text,\n udap_id text,\n CONSTRAINT service_instructeurs_pkey PRIMARY KEY (id)\n)",
"INSERT INTO \"public\".\"_electric_trigger_settings\" (\"namespace\", \"tablename\", \"flag\")\n VALUES ('public', 'service_instructeurs', 1)\n ON CONFLICT DO NOTHING;",
"DROP TRIGGER IF EXISTS update_ensure_public_service_instructeurs_primarykey ON \"public\".\"service_instructeurs\";",
"CREATE OR REPLACE FUNCTION update_ensure_public_service_instructeurs_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_service_instructeurs_primarykey\n BEFORE UPDATE ON \"public\".\"service_instructeurs\"\n FOR EACH ROW\n EXECUTE FUNCTION update_ensure_public_service_instructeurs_primarykey_function();",
"DROP TRIGGER IF EXISTS insert_public_service_instructeurs_into_oplog ON \"public\".\"service_instructeurs\";",
" CREATE OR REPLACE FUNCTION insert_public_service_instructeurs_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 = 'service_instructeurs';\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 'service_instructeurs',\n 'INSERT',\n json_strip_nulls(json_build_object('id', new.\"id\")),\n jsonb_build_object('email', new.\"email\", 'full_name', new.\"full_name\", 'id', new.\"id\", 'short_name', new.\"short_name\", 'tel', new.\"tel\", '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_service_instructeurs_into_oplog\n AFTER INSERT ON \"public\".\"service_instructeurs\"\n FOR EACH ROW\n EXECUTE FUNCTION insert_public_service_instructeurs_into_oplog_function();",
"DROP TRIGGER IF EXISTS update_public_service_instructeurs_into_oplog ON \"public\".\"service_instructeurs\";",
" CREATE OR REPLACE FUNCTION update_public_service_instructeurs_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 = 'service_instructeurs';\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 'service_instructeurs',\n 'UPDATE',\n json_strip_nulls(json_build_object('id', new.\"id\")),\n jsonb_build_object('email', new.\"email\", 'full_name', new.\"full_name\", 'id', new.\"id\", 'short_name', new.\"short_name\", 'tel', new.\"tel\", 'udap_id', new.\"udap_id\"),\n jsonb_build_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\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;",
"CREATE TRIGGER update_public_service_instructeurs_into_oplog\n AFTER UPDATE ON \"public\".\"service_instructeurs\"\n FOR EACH ROW\n EXECUTE FUNCTION update_public_service_instructeurs_into_oplog_function();",
"DROP TRIGGER IF EXISTS delete_public_service_instructeurs_into_oplog ON \"public\".\"service_instructeurs\";",
" CREATE OR REPLACE FUNCTION delete_public_service_instructeurs_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 = 'service_instructeurs';\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 'service_instructeurs',\n 'DELETE',\n json_strip_nulls(json_build_object('id', old.\"id\")),\n NULL,\n jsonb_build_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\"),\n NULL\n );\n END IF;\n\n RETURN NEW;\n END;\n END;\n $$ LANGUAGE plpgsql;",
"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"
}
]
Loading

0 comments on commit 38d39ae

Please sign in to comment.