From 78eb0a879268c51a27ff555d918b9360081efea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Burkard?= <22095555+JeromeBu@users.noreply.github.com> Date: Fri, 12 Jul 2024 10:02:13 +0200 Subject: [PATCH] WIP implementing PG software.update --- .../adapters/dbApi/kysely/createPgDbApi.ts | 98 ++++++++++++++++--- 1 file changed, 84 insertions(+), 14 deletions(-) diff --git a/api/src/core/adapters/dbApi/kysely/createPgDbApi.ts b/api/src/core/adapters/dbApi/kysely/createPgDbApi.ts index ce8c2b3e..23682175 100644 --- a/api/src/core/adapters/dbApi/kysely/createPgDbApi.ts +++ b/api/src/core/adapters/dbApi/kysely/createPgDbApi.ts @@ -1,4 +1,6 @@ import { Kysely } from "kysely"; +import type { Equals } from "tsafe"; +import { assert } from "tsafe/assert"; import { CompiledData } from "../../../ports/CompileData"; import { Db } from "../../../ports/DbApi"; import { Software, SoftwareFormData } from "../../../usecases/readWriteSillData"; @@ -41,38 +43,106 @@ export const createKyselyPgDbApi = (db: Kysely): NewDbApi => { return { software: { create: async ({ formData, agent }) => { + const { + softwareName, + softwareDescription, + softwareLicense, + softwareLogoUrl, + softwareMinimalVersion, + isPresentInSupportContract, + isFromFrenchPublicService, + doRespectRgaa, + similarSoftwareExternalDataIds, + softwareType, + externalId, + comptoirDuLibreId, + softwareKeywords, + ...rest + } = formData; + + assert>(); + const now = Date.now(); await db .insertInto("softwares") .values({ - name: formData.softwareName, - description: formData.softwareDescription, - license: formData.softwareLicense, - logoUrl: formData.softwareLogoUrl, - versionMin: formData.softwareMinimalVersion, + name: softwareName, + description: softwareDescription, + license: softwareLicense, + logoUrl: softwareLogoUrl, + versionMin: softwareMinimalVersion, referencedSinceTime: now, updateTime: now, dereferencing: undefined, isStillInObservation: false, parentSoftwareWikidataId: undefined, - doRespectRgaa: formData.doRespectRgaa, - isFromFrenchPublicService: formData.isFromFrenchPublicService, - isPresentInSupportContract: formData.isPresentInSupportContract, - similarSoftwareExternalDataIds: JSON.stringify(formData.similarSoftwareExternalDataIds), - externalId: formData.externalId, - comptoirDuLibreId: formData.comptoirDuLibreId, - softwareType: JSON.stringify(formData.softwareType), + doRespectRgaa: doRespectRgaa, + isFromFrenchPublicService: isFromFrenchPublicService, + isPresentInSupportContract: isPresentInSupportContract, + similarSoftwareExternalDataIds: JSON.stringify(similarSoftwareExternalDataIds), + externalId: externalId, + comptoirDuLibreId: comptoirDuLibreId, + softwareType: JSON.stringify(softwareType), + catalogNumeriqueGouvFrId: undefined, + workshopUrls: JSON.stringify([]), + testUrls: JSON.stringify([]), + categories: JSON.stringify([]), + generalInfoMd: undefined, + addedByAgentEmail: agent.email, + keywords: JSON.stringify(softwareKeywords) + }) + .execute(); + }, + update: async ({ formData, softwareSillId, agent }) => { + const { + softwareName, + softwareDescription, + softwareLicense, + softwareLogoUrl, + softwareMinimalVersion, + isPresentInSupportContract, + isFromFrenchPublicService, + doRespectRgaa, + similarSoftwareExternalDataIds, + softwareType, + externalId, + comptoirDuLibreId, + softwareKeywords, + ...rest + } = formData; + + assert>(); + + const now = Date.now(); + await db + .updateTable("softwares") + .set({ + name: softwareName, + description: softwareDescription, + license: softwareLicense, + logoUrl: softwareLogoUrl, + versionMin: softwareMinimalVersion, + updateTime: now, + isStillInObservation: false, + parentSoftwareWikidataId: undefined, + doRespectRgaa: doRespectRgaa, + isFromFrenchPublicService: isFromFrenchPublicService, + isPresentInSupportContract: isPresentInSupportContract, + similarSoftwareExternalDataIds: JSON.stringify(similarSoftwareExternalDataIds), + externalId: externalId, + comptoirDuLibreId: comptoirDuLibreId, + softwareType: JSON.stringify(softwareType), catalogNumeriqueGouvFrId: undefined, workshopUrls: JSON.stringify([]), testUrls: JSON.stringify([]), categories: JSON.stringify([]), generalInfoMd: undefined, addedByAgentEmail: agent.email, - keywords: JSON.stringify(formData.softwareKeywords) + keywords: JSON.stringify(softwareKeywords) }) + .where("id", "=", softwareSillId) .execute(); }, - update: async ({ formData, softwareSillId, agent }) => {}, getAll: (): Promise => db .selectFrom("softwares as s")