Parse postgres connection information out of the environment
Build and Publish Docker Container / build (push) Failing after 3m12s
Build and Publish Docker Container / build (push) Failing after 3m12s
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import {SubjectComparisonCard} from "@/components/cards/subjectComparisonCard";
|
||||
import {CalendarOverviewCard} from "@/components/cards/calendarOverviewCard";
|
||||
import {SubjectOverviewCard} from "@/components/cards/subjectOverviewCard";
|
||||
import {getData} from "@/data/fetchData";
|
||||
import {getDataSQL} from "@/data/fetchWithSQL";
|
||||
|
||||
export interface OverviewConfig {
|
||||
|
||||
+43
-6
@@ -2,15 +2,52 @@ import {DB as Database} from './db' // this is the Database interface we defined
|
||||
import {Pool} from 'pg'
|
||||
import {Kysely, PostgresDialect} from 'kysely'
|
||||
import * as fs from "node:fs";
|
||||
import {z} from 'zod';
|
||||
|
||||
function fileOrEnv(fileKey: string, valueKey: string): string | undefined {
|
||||
const file = process.env[fileKey];
|
||||
const envSchema = z.object({
|
||||
POSTGRES_DB: z.string(),
|
||||
POSTGRES_HOST: z.string(),
|
||||
POSTGRES_PORT: z.string().transform((val, ctx) => {
|
||||
const parsed = parseInt(val);
|
||||
if (isNaN(parsed)) {
|
||||
ctx.addIssue({
|
||||
code: z.ZodIssueCode.custom,
|
||||
message: "Not a number",
|
||||
});
|
||||
|
||||
return z.NEVER;
|
||||
}
|
||||
return parsed;
|
||||
}),
|
||||
|
||||
POSTGRES_USER: z.string().optional(),
|
||||
POSTGRES_USER_FILE: z.string().optional(),
|
||||
POSTGRES_PASSWORD: z.string().optional(),
|
||||
POSTGRES_PASSWORD_FILE: z.string().optional(),
|
||||
}).refine(
|
||||
env => env.POSTGRES_USER || env.POSTGRES_USER_FILE,
|
||||
{
|
||||
message: "Either POSTGRES_USER or POSTGRES_USER_FILE must be set",
|
||||
path: ["POSTGRES_USER", "POSTGRES_USER_FILE"],
|
||||
}
|
||||
).refine(
|
||||
env => env.POSTGRES_PASSWORD || env.POSTGRES_PASSWORD_FILE,
|
||||
{
|
||||
message: "Either POSTGRES_PASSWORD or POSTGRES_PASSWORD_FILE must be set",
|
||||
path: ["POSTGRES_PASSWORD", "POSTGRES_PASSWORD_FILE"],
|
||||
}
|
||||
);
|
||||
|
||||
const env = envSchema.parse(process.env);
|
||||
|
||||
function fileOrEnv(fileKey: keyof typeof env, valueKey: keyof typeof env): string | undefined {
|
||||
const file: string = env[fileKey] as string;
|
||||
|
||||
if (file && fs.existsSync(file)) {
|
||||
return fs.readFileSync(file, 'utf8');
|
||||
}
|
||||
|
||||
return process.env[valueKey];
|
||||
return env[valueKey] as string;
|
||||
}
|
||||
|
||||
function getCredentials() {
|
||||
@@ -22,9 +59,9 @@ function getCredentials() {
|
||||
|
||||
const dialect = new PostgresDialect({
|
||||
pool: new Pool({
|
||||
database: process.env.POSTGRES_DB!,
|
||||
host: process.env.POSTGRES_HOST!,
|
||||
port: parseInt(process.env.POSTGRES_PORT!),
|
||||
database: env.POSTGRES_DB,
|
||||
host: env.POSTGRES_HOST,
|
||||
port: env.POSTGRES_PORT,
|
||||
...getCredentials(),
|
||||
max: 10,
|
||||
})
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
"use server";
|
||||
import {OverviewConfig} from "@/components/OverviewPage";
|
||||
|
||||
export interface Data {
|
||||
projects: {
|
||||
@@ -16,29 +15,3 @@ export interface Data {
|
||||
// description: string,
|
||||
}[],
|
||||
}
|
||||
|
||||
export async function getData(config: OverviewConfig): Promise<Data> {
|
||||
const projectIds = config.subjects.map((subject) => subject.projectId);
|
||||
const projectResponse = await fetch(`https://cosmos.tail307fc.ts.net/api/project?select=raw_json&toggl_id=in.(${projectIds.join(',')})`);
|
||||
const projects = await projectResponse.json();
|
||||
const projectLensed = projects.map((project: any) => ({
|
||||
projectId: project.raw_json.id,
|
||||
name: project.raw_json.name,
|
||||
color: project.raw_json.color,
|
||||
}));
|
||||
|
||||
const timeEntriesResponse = await fetch(`https://cosmos.tail307fc.ts.net/api/time_entry?select=project_id,raw_json&project_id=in.(${projectIds.join(',')})&start=gt.${config.timePeriod.start}&start=lt.${config.timePeriod.end}`);
|
||||
const timeEntries = await timeEntriesResponse.json();
|
||||
const timeEntriesLensed = timeEntries.map((timeEntry: any) => ({
|
||||
projectId: timeEntry.project_id,
|
||||
start: timeEntry.raw_json.start,
|
||||
end: timeEntry.raw_json.end,
|
||||
duration: timeEntry.raw_json.seconds,
|
||||
// description: timeEntry.raw_json.description,
|
||||
}));
|
||||
|
||||
return {
|
||||
projects: projectLensed,
|
||||
timeEntries: timeEntriesLensed,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user