From 2c93c6778d7ce0914388c71e3933091fdfaa2bc7 Mon Sep 17 00:00:00 2001 From: Christopher Langton Date: Tue, 26 Nov 2024 13:57:58 +1100 Subject: [PATCH] fix: create arguments needs data property --- Makefile | 24 +++++++++---------- functions/api/cdx.js | 11 +++++---- .../api/github/repos/[org]/[repo]/spdx.js | 7 +++--- functions/api/spdx.js | 7 +++--- prisma/schema.prisma | 2 +- 5 files changed, 27 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 3bbc151..44d9b15 100644 --- a/Makefile +++ b/Makefile @@ -64,18 +64,18 @@ git-demo: _purge_data: ## FOR DOCO ONLY npx wrangler d1 execute vulnetix --local --command "DELETE FROM Session;" - npx wrangler d1 execute vulnetix --local --command "DELETE FROM GitBranch;" - npx wrangler d1 execute vulnetix --local --command "DELETE FROM Dependency;" - npx wrangler d1 execute vulnetix --local --command "DELETE FROM SarifResults;" - npx wrangler d1 execute vulnetix --local --command "DELETE FROM CycloneDXInfo;" - npx wrangler d1 execute vulnetix --local --command "DELETE FROM SPDXInfo;" - npx wrangler d1 execute vulnetix --local --command "DELETE FROM SARIFInfo;" - npx wrangler d1 execute vulnetix --local --command "DELETE FROM IntegrationUsageLog;" - npx wrangler d1 execute vulnetix --local --command "DELETE FROM Triage;" - npx wrangler d1 execute vulnetix --local --command "DELETE FROM Finding;" - npx wrangler d1 execute vulnetix --local --command "DELETE FROM GitRepo;" - npx wrangler d1 execute vulnetix --local --command "DELETE FROM Artifact;" - npx wrangler d1 execute vulnetix --local --command "DELETE FROM Link WHERE artifactUuid IS NOT NULL;" + npx wrangler d1 execute vulnetix --local --command "DELETE FROM GitBranch;" + npx wrangler d1 execute vulnetix --local --command "DELETE FROM Dependency;" + npx wrangler d1 execute vulnetix --local --command "DELETE FROM SarifResults;" + npx wrangler d1 execute vulnetix --local --command "DELETE FROM CycloneDXInfo;" + npx wrangler d1 execute vulnetix --local --command "DELETE FROM SPDXInfo;" + npx wrangler d1 execute vulnetix --local --command "DELETE FROM SARIFInfo;" + npx wrangler d1 execute vulnetix --local --command "DELETE FROM IntegrationUsageLog;" + npx wrangler d1 execute vulnetix --local --command "DELETE FROM Triage;" + npx wrangler d1 execute vulnetix --local --command "DELETE FROM Finding;" + npx wrangler d1 execute vulnetix --local --command "DELETE FROM GitRepo;" + npx wrangler d1 execute vulnetix --local --command "DELETE FROM Artifact;" + npx wrangler d1 execute vulnetix --local --command "DELETE FROM Link WHERE artifactUuid IS NOT NULL;" _helpers: ## FOR DOCO ONLY npx wrangler d1 execute vulnetix --local --file ./migrations/0001_init.sql diff --git a/functions/api/cdx.js b/functions/api/cdx.js index 5f0488d..e339c18 100644 --- a/functions/api/cdx.js +++ b/functions/api/cdx.js @@ -84,6 +84,7 @@ export async function onRequestPost(context) { } } }) + const newData = { ...dep, cdxId } if (lookup?.key) { const infoUpd = await data.prisma.Dependency.update({ where: { @@ -94,12 +95,12 @@ export async function onRequestPost(context) { childOfKey: dep.childOfKey } }) - data.logger(`Update CDX ${cdxId} Dep ${dep.name}`, infoUpd) - dependencies.push({ ...dep, cdxId }) + data.logger(`Update CycloneDX ${cdxId} Dep ${dep.name}`, infoUpd) + dependencies.push(newData) } else { - const infoAdd = await data.prisma.Dependency.create({ ...dep, cdxId }) - data.logger(`Create CDX ${cdxId} Dep ${dep.name}`, infoAdd) - dependencies.push({ ...dep, cdxId }) + const infoAdd = await data.prisma.Dependency.create({ data: newData }) + data.logger(`Create CycloneDX ${cdxId} Dep ${dep.name}`, infoAdd) + dependencies.push(newData) } } const cdxStr = JSON.stringify(cdx) diff --git a/functions/api/github/repos/[org]/[repo]/spdx.js b/functions/api/github/repos/[org]/[repo]/spdx.js index 5c9c8fc..a567109 100644 --- a/functions/api/github/repos/[org]/[repo]/spdx.js +++ b/functions/api/github/repos/[org]/[repo]/spdx.js @@ -76,6 +76,7 @@ export async function onRequestGet(context) { } } }) + const newData = { ...dep, spdxId } if (lookup?.key) { const infoUpd = await data.prisma.Dependency.update({ where: { @@ -87,11 +88,11 @@ export async function onRequestGet(context) { } }) data.logger(`Update SPDX ${spdxId} Dep ${dep.name}`, infoUpd) - dependencies.push({ ...dep, spdxId }) + dependencies.push(newData) } else { - const infoAdd = await data.prisma.Dependency.create({ ...dep, spdxId }) + const infoAdd = await data.prisma.Dependency.create({ data: newData }) data.logger(`Create SPDX ${spdxId} Dep ${dep.name}`, infoAdd) - dependencies.push({ ...dep, spdxId }) + dependencies.push(newData) } } spdx.dependencies = dependencies diff --git a/functions/api/spdx.js b/functions/api/spdx.js index 349df58..52d7b3d 100644 --- a/functions/api/spdx.js +++ b/functions/api/spdx.js @@ -109,6 +109,7 @@ export async function onRequestPost(context) { } } }) + const newData = { ...dep, spdxId } if (lookup?.key) { const infoUpd = await data.prisma.Dependency.update({ where: { @@ -120,11 +121,11 @@ export async function onRequestPost(context) { } }) data.logger(`Update SPDX ${spdxId} Dep ${dep.name}`, infoUpd) - dependencies.push({ ...dep, spdxId }) + dependencies.push(newData) } else { - const infoAdd = await data.prisma.Dependency.create({ ...dep, spdxId }) + const infoAdd = await data.prisma.Dependency.create({ data: newData }) data.logger(`Create SPDX ${spdxId} Dep ${dep.name}`, infoAdd) - dependencies.push({ ...dep, spdxId }) + dependencies.push(newData) } } const spdxData = { diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4ec266e..b6b3834 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -269,7 +269,7 @@ model SPDXInfo { } model Dependency { - key String @unique + key String @id name String version String license String?