Skip to content

Commit

Permalink
feat: clauses v2 + some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ledouxm authored Jul 12, 2024
2 parents 2435e85 + 83db85b commit 961df59
Show file tree
Hide file tree
Showing 50 changed files with 4,900 additions and 3,960 deletions.
1 change: 1 addition & 0 deletions db/migrations/901-add_applicant_mail.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "report" ADD COLUMN "applicantEmail" TEXT;
11 changes: 11 additions & 0 deletions db/migrations/902-rework_clauses.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

CREATE TABLE clause_v2 (
id text NOT NULL PRIMARY KEY
,key text NOT NULL
,value text NOT NULL
,position int
,udap_id text
,text text NOT NULL
);

ALTER TABLE clause_v2 ENABLE ELECTRIC;
1 change: 1 addition & 0 deletions db/migrations/903-fix_clausev1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE clause ADD COLUMN "hidden" BOOLEAN;
9 changes: 9 additions & 0 deletions db/migrations/904-add_pdf_snapshot.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE pdf_snapshot (
id TEXT PRIMARY KEY,
report_id TEXT,
html TEXT,
report TEXT,
user_id TEXT
);

ALTER TABLE pdf_snapshot ENABLE ELECTRIC;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"db:migrate": "pnpm db:create",
"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",
"electric:migrate": "pnpm electric:up && pnpm electric-client generate:front && pnpm electric-client generate:back",
"client:json": "pnpm backend dev --create-only",
"client:ts": "typed-openapi ./packages/backend/openapi.json --output ./packages/frontend/src/api.gen.ts",
"client:generate": "pnpm client:json && pnpm client:ts",
Expand All @@ -27,7 +27,7 @@
"@pandabox/prettier-plugin": "^0.1.0",
"@playwright/test": "^1.43.0",
"@types/node": "^20.11.28",
"electric-sql": "^0.12.0",
"electric-sql": "^0.12.1",
"prettier": "^3.2.5",
"prisma": "^4.8.1",
"typed-openapi": "^0.4.1"
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { onHmr, registerViteHmrServerRestart } from "./hmr";
import { ENV } from "./envVars";
import { generateOpenApi, initFastify } from "./router";
import { makeDebug } from "./features/debug";
import { initClauseV2 } from "./tmp";

const debug = makeDebug("index");

const start = async () => {
await registerViteHmrServerRestart();

await initClauseV2();
debug("Starting fastify server in", ENV.NODE_ENV, "mode");

const fastifyInstance = await initFastify();
Expand Down
30 changes: 30 additions & 0 deletions packages/backend/src/tmp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { db } from "./db/db";
import { v4 } from "uuid";
import { groupBy } from "pastable";

export const initClauseV2 = async () => {
const nbClausesV2 = await db.clause_v2.count();
if (nbClausesV2 > 0) return;

const clauses = await db.clause.findMany();

const grouped = groupBy(clauses, (clause) => `${clause.udap_id}-${clause.key}`);

for (const clausesToAdd of Object.values(grouped)) {
for (let i = 0; i < clausesToAdd.length; i++) {
const clause = clausesToAdd[i]!;
await db.clause_v2.create({
data: {
id: v4(),
key: clause.key,
text: clause.text,
value: clause.value,
position: i,
udap_id: clause.udap_id,
},
});
}
}

return "done";
};
2 changes: 1 addition & 1 deletion packages/electric-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"peerDependencies": {
"@prisma/client": "^4.8.1",
"@sinclair/typebox": "^0.32.20",
"electric-sql": "^0.12.0",
"electric-sql": "^0.12.1",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
21 changes: 21 additions & 0 deletions packages/electric-client/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ model clause {
value String
udap_id String
text String
hidden Boolean?
@@id([key, value, udap_id])
}
Expand All @@ -56,6 +57,8 @@ model report {
pdf String?
disabled Boolean?
udap_id String?
redactedById String?
applicantEmail String?
user user @relation(fields: [createdBy], references: [id], onDelete: SetNull, onUpdate: NoAction)
}

Expand Down Expand Up @@ -110,3 +113,21 @@ model internal_user {
userId String
user user @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: NoAction)
}

model service_instructeurs {
id Int @id
full_name String
short_name String
email String?
tel String?
udap_id String?
}

model clause_v2 {
id String @id
key String
value String
position Int?
udap_id String?
text String
}
Loading

0 comments on commit 961df59

Please sign in to comment.