From 09d4f07542a237bbfcc48d41b4476c7cb3c87e5a Mon Sep 17 00:00:00 2001 From: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com> Date: Tue, 18 Jun 2024 07:37:11 +1200 Subject: [PATCH] refactor: tsc fixes --- migrator.ts | 6 ++++-- src/components/logging/logging.service.ts | 14 +++++++------- src/components/services/services.service.ts | 11 +++++++---- tsconfig.json | 6 +++--- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/migrator.ts b/migrator.ts index 1627c1b..d3399f3 100644 --- a/migrator.ts +++ b/migrator.ts @@ -13,9 +13,11 @@ if (!DB_URL) { const main = async () => { const start = new Date(); - const migrationClient = postgres(DB_URL, { max: 1 }); - const db = drizzle(migrationClient); + const client = postgres(DB_URL, { max: 1 }); + const db = drizzle(client); + await migrate(db, { migrationsFolder: "./drizzle" }); + await client.end(); const end = new Date(); console.log(`Migrations complete in ${end.getTime() - start.getTime()}ms`); diff --git a/src/components/logging/logging.service.ts b/src/components/logging/logging.service.ts index 3fcc333..092504f 100644 --- a/src/components/logging/logging.service.ts +++ b/src/components/logging/logging.service.ts @@ -1,4 +1,4 @@ -import { and, eq, lt, inArray } from "drizzle-orm"; +import { and, eq, lt } from "drizzle-orm"; import { CreateLogInput, TGetLogsSearchParamsInput } from "./logging.schema"; @@ -61,13 +61,13 @@ export async function getLogs({ const logs = await db.query.logs.findMany({ limit, offset: skip, - orderBy: (table, { asc, desc }) => (sortDirection === "asc" ? asc(table.createdAt) : desc(table.createdAt)), - where: (table, { and, eq }) => + orderBy: (fields, { asc, desc }) => (sortDirection === "asc" ? asc(fields.createdAt) : desc(fields.createdAt)), + where: (fields, { and, eq, inArray }) => and( - ...[eq(table.serviceId, data.serviceId)], - ...(data.environment ? [eq(table.environment, data.environment)] : []), - ...(data.lookupValue ? [eq(table.lookupFilterValue, data.lookupValue)] : []), - ...(isSpecificLogLevel ? [inArray(table.level, levelsWithoutAll)] : []), + ...[eq(fields.serviceId, data.serviceId)], + ...(data.environment ? [eq(fields.environment, data.environment)] : []), + ...(data.lookupValue ? [eq(fields.lookupFilterValue, data.lookupValue)] : []), + ...(isSpecificLogLevel ? [inArray(fields.level, levelsWithoutAll)] : []), ), }); diff --git a/src/components/services/services.service.ts b/src/components/services/services.service.ts index ff2afde..6973eff 100644 --- a/src/components/services/services.service.ts +++ b/src/components/services/services.service.ts @@ -1,4 +1,4 @@ -import { desc, eq } from "drizzle-orm"; +import { eq } from "drizzle-orm"; import { db } from "../../config/db"; import { services as serviceTable } from "../../config/db/schema"; @@ -6,7 +6,8 @@ import { createDbId, dbPrefixes } from "../../utils/db"; import type { CreateServiceInput } from "./services.schema"; export async function findActiveService(data: { serviceId: string; isAdmin?: boolean }) { - const service = await db.query.services.findFirst({ where: eq(serviceTable.id, data.serviceId) }); + const service = await db.query.services.findFirst({ where: (fields, { eq }) => eq(fields.id, data.serviceId) }); + if (data.isAdmin && service && service.isActive) { return service.isAdmin ? service : null; } else if (service && service.isActive) { @@ -17,11 +18,13 @@ export async function findActiveService(data: { serviceId: string; isAdmin?: boo } export async function findAllServices() { - return await db.query.services.findMany({ orderBy: desc(serviceTable.createdAt) }); + const services = await db.query.services.findMany({ orderBy: (fields, { desc }) => desc(fields.createdAt) }); + return services; } export async function findServiceById(data: { serviceId: string }) { - return (await db.query.services.findFirst({ where: eq(serviceTable.id, data.serviceId) })) ?? null; + const service = await db.query.services.findFirst({ where: (fields, { eq }) => eq(fields.id, data.serviceId) }); + return service ?? null; } export async function createService(data: CreateServiceInput) { diff --git a/tsconfig.json b/tsconfig.json index 609dad2..01b3049 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,11 +1,11 @@ { "compilerOptions": { - "target": "es2016", + "target": "ESNext", "lib": ["ESNext"], "experimentalDecorators": true, "emitDecoratorMetadata": true, - "module": "commonjs", - "moduleResolution": "node", + "module": "CommonJS", + "moduleResolution": "Node", "baseUrl": ".", "resolveJsonModule": true, "outDir": "./dist",