From 9973197fa52b1a09c4bd51b147c4ebcc26a0dddc Mon Sep 17 00:00:00 2001 From: dominicbachmann Date: Wed, 6 Apr 2022 20:23:27 +0200 Subject: [PATCH] Added types for database/secrets --- src/lib/database/secrets.ts | 69 ++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/src/lib/database/secrets.ts b/src/lib/database/secrets.ts index 835eb4def..2aade4a2f 100644 --- a/src/lib/database/secrets.ts +++ b/src/lib/database/secrets.ts @@ -1,7 +1,8 @@ import { encrypt, decrypt } from '$lib/crypto'; import { prisma } from './common'; +import type { ServiceSecret, Secret, Prisma } from '@prisma/client'; -export async function listServiceSecrets(serviceId: string) { +export async function listServiceSecrets(serviceId: string): Promise { let secrets = await prisma.serviceSecret.findMany({ where: { serviceId }, orderBy: { createdAt: 'desc' } @@ -14,7 +15,7 @@ export async function listServiceSecrets(serviceId: string) { return secrets; } -export async function listSecrets(applicationId: string) { +export async function listSecrets(applicationId: string): Promise { let secrets = await prisma.secret.findMany({ where: { applicationId }, orderBy: { createdAt: 'desc' } @@ -27,20 +28,48 @@ export async function listSecrets(applicationId: string) { return secrets; } -export async function createServiceSecret({ id, name, value }) { +export async function createServiceSecret({ + id, + name, + value +}: { + id: string; + name: string; + value: string; +}): Promise { value = encrypt(value); return await prisma.serviceSecret.create({ data: { name, value, service: { connect: { id } } } }); } -export async function createSecret({ id, name, value, isBuildSecret, isPRMRSecret }) { +export async function createSecret({ + id, + name, + value, + isBuildSecret, + isPRMRSecret +}: { + id: string; + name: string; + value: string; + isBuildSecret: boolean; + isPRMRSecret: boolean; +}): Promise { value = encrypt(value); return await prisma.secret.create({ data: { name, value, isBuildSecret, isPRMRSecret, application: { connect: { id } } } }); } -export async function updateServiceSecret({ id, name, value }) { +export async function updateServiceSecret({ + id, + name, + value +}: { + id: string; + name: string; + value: string; +}): Promise { value = encrypt(value); const found = await prisma.serviceSecret.findFirst({ where: { serviceId: id, name } }); @@ -55,7 +84,19 @@ export async function updateServiceSecret({ id, name, value }) { }); } } -export async function updateSecret({ id, name, value, isBuildSecret, isPRMRSecret }) { +export async function updateSecret({ + id, + name, + value, + isBuildSecret, + isPRMRSecret +}: { + id: string; + name: string; + value: string; + isBuildSecret: boolean; + isPRMRSecret: boolean; +}): Promise { value = encrypt(value); const found = await prisma.secret.findFirst({ where: { applicationId: id, name, isPRMRSecret } }); @@ -71,10 +112,22 @@ export async function updateSecret({ id, name, value, isBuildSecret, isPRMRSecre } } -export async function removeServiceSecret({ id, name }) { +export async function removeServiceSecret({ + id, + name +}: { + id: string; + name: string; +}): Promise { return await prisma.serviceSecret.deleteMany({ where: { serviceId: id, name } }); } -export async function removeSecret({ id, name }) { +export async function removeSecret({ + id, + name +}: { + id: string; + name: string; +}): Promise { return await prisma.secret.deleteMany({ where: { applicationId: id, name } }); }