From 008cfdba093a7f0485fb5350461f94c8ad8d7caf Mon Sep 17 00:00:00 2001 From: dominicbachmann Date: Wed, 6 Apr 2022 20:30:29 +0200 Subject: [PATCH] Added types to database/services --- src/lib/database/services.ts | 138 ++++++++++++++++++++++++++++++----- 1 file changed, 121 insertions(+), 17 deletions(-) diff --git a/src/lib/database/services.ts b/src/lib/database/services.ts index c5d221e9e..359722bf8 100644 --- a/src/lib/database/services.ts +++ b/src/lib/database/services.ts @@ -1,18 +1,24 @@ -import { asyncExecShell, getEngine } from '$lib/common'; import { decrypt, encrypt } from '$lib/crypto'; +import type { Minio, Service } from '@prisma/client'; import cuid from 'cuid'; import { generatePassword } from '.'; import { prisma } from './common'; -export async function listServices(teamId) { +export async function listServices(teamId: string): Promise { return await prisma.service.findMany({ where: { teams: { some: { id: teamId } } } }); } -export async function newService({ name, teamId }) { +export async function newService({ + name, + teamId +}: { + name: string; + teamId: string; +}): Promise { return await prisma.service.create({ data: { name, teams: { connect: { id: teamId } } } }); } -export async function getService({ id, teamId }) { +export async function getService({ id, teamId }: { id: string; teamId: string }): Promise { const body = await prisma.service.findFirst({ where: { id, teams: { some: { id: teamId } } }, include: { @@ -63,7 +69,13 @@ export async function getService({ id, teamId }) { return { ...body }; } -export async function configureServiceType({ id, type }) { +export async function configureServiceType({ + id, + type +}: { + id: string; + type: string; +}): Promise { if (type === 'plausibleanalytics') { const password = encrypt(generatePassword()); const postgresqlUser = cuid(); @@ -179,56 +191,148 @@ export async function configureServiceType({ id, type }) { }); } } -export async function setServiceVersion({ id, version }) { +export async function setServiceVersion({ + id, + version +}: { + id: string; + version: string; +}): Promise { return await prisma.service.update({ where: { id }, data: { version } }); } -export async function setServiceSettings({ id, dualCerts }) { +export async function setServiceSettings({ + id, + dualCerts +}: { + id: string; + dualCerts: boolean; +}): Promise { return await prisma.service.update({ where: { id }, data: { dualCerts } }); } -export async function updatePlausibleAnalyticsService({ id, fqdn, email, username, name }) { +export async function updatePlausibleAnalyticsService({ + id, + fqdn, + email, + username, + name +}: { + id: string; + fqdn: string; + name: string; + email: string; + username: string; +}): Promise { await prisma.plausibleAnalytics.update({ where: { serviceId: id }, data: { email, username } }); await prisma.service.update({ where: { id }, data: { name, fqdn } }); } -export async function updateService({ id, fqdn, name }) { +export async function updateService({ + id, + fqdn, + name +}: { + id: string; + fqdn: string; + name: string; +}): Promise { return await prisma.service.update({ where: { id }, data: { fqdn, name } }); } -export async function updateLanguageToolService({ id, fqdn, name }) { +export async function updateLanguageToolService({ + id, + fqdn, + name +}: { + id: string; + fqdn: string; + name: string; +}): Promise { return await prisma.service.update({ where: { id }, data: { fqdn, name } }); } -export async function updateMeiliSearchService({ id, fqdn, name }) { +export async function updateMeiliSearchService({ + id, + fqdn, + name +}: { + id: string; + fqdn: string; + name: string; +}): Promise { return await prisma.service.update({ where: { id }, data: { fqdn, name } }); } -export async function updateVaultWardenService({ id, fqdn, name }) { +export async function updateVaultWardenService({ + id, + fqdn, + name +}: { + id: string; + fqdn: string; + name: string; +}): Promise { return await prisma.service.update({ where: { id }, data: { fqdn, name } }); } -export async function updateVsCodeServer({ id, fqdn, name }) { +export async function updateVsCodeServer({ + id, + fqdn, + name +}: { + id: string; + fqdn: string; + name: string; +}): Promise { return await prisma.service.update({ where: { id }, data: { fqdn, name } }); } -export async function updateWordpress({ id, fqdn, name, mysqlDatabase, extraConfig }) { +export async function updateWordpress({ + id, + fqdn, + name, + mysqlDatabase, + extraConfig +}: { + id: string; + fqdn: string; + name: string; + mysqlDatabase: string; + extraConfig: string; +}): Promise { return await prisma.service.update({ where: { id }, data: { fqdn, name, wordpress: { update: { mysqlDatabase, extraConfig } } } }); } -export async function updateMinioService({ id, publicPort }) { +export async function updateMinioService({ + id, + publicPort +}: { + id: string; + publicPort: number; +}): Promise { return await prisma.minio.update({ where: { serviceId: id }, data: { publicPort } }); } -export async function updateGhostService({ id, fqdn, name, mariadbDatabase }) { +export async function updateGhostService({ + id, + fqdn, + name, + mariadbDatabase +}: { + id: string; + fqdn: string; + name: string; + mariadbDatabase: string; +}): Promise { return await prisma.service.update({ where: { id }, data: { fqdn, name, ghost: { update: { mariadbDatabase } } } }); } -export async function removeService({ id }) { +export async function removeService({ id }: { id: string }): Promise { await prisma.meiliSearch.deleteMany({ where: { serviceId: id } }); await prisma.ghost.deleteMany({ where: { serviceId: id } }); await prisma.plausibleAnalytics.deleteMany({ where: { serviceId: id } });