Skip to content

Commit

Permalink
refactor: tsc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanCassiere committed Jun 17, 2024
1 parent 08d35f1 commit 09d4f07
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
6 changes: 4 additions & 2 deletions migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
14 changes: 7 additions & 7 deletions src/components/logging/logging.service.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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)] : []),
),
});

Expand Down
11 changes: 7 additions & 4 deletions src/components/services/services.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { desc, eq } from "drizzle-orm";
import { eq } from "drizzle-orm";

import { db } from "../../config/db";
import { services as serviceTable } from "../../config/db/schema";
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) {
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 09d4f07

Please sign in to comment.