Added estimaded salary to dashboard
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
-- CreateTable
|
||||
CREATE TABLE "settings" (
|
||||
"key" TEXT NOT NULL,
|
||||
"value" TEXT NOT NULL,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "settings_pkey" PRIMARY KEY ("key")
|
||||
);
|
||||
|
||||
-- Seed
|
||||
INSERT INTO "settings" ("key", "value", "createdAt", "updatedAt")
|
||||
VALUES ('salary_multiplier', '4500', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
|
||||
@@ -122,6 +122,15 @@ model QuoteHistory {
|
||||
@@map("quotes_history")
|
||||
}
|
||||
|
||||
model Setting {
|
||||
key String @id
|
||||
value String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@map("settings")
|
||||
}
|
||||
|
||||
// Expenses
|
||||
|
||||
enum PaymentStatus {
|
||||
|
||||
@@ -11,6 +11,7 @@ import { startExpenseJob } from "./modules/expenses/expense.job";
|
||||
import expensesRouter from "./modules/expenses/expenses.routes";
|
||||
import { startQuoteJob } from "./modules/quotes/quote.job";
|
||||
import quotesRouter from "./modules/quotes/quotes.routes";
|
||||
import settingsRouter from "./modules/settings/settings.routes";
|
||||
import telegramRouter from "./modules/telegram/telegram.router";
|
||||
import walletsRouter from "./modules/wallets/wallets.routes";
|
||||
|
||||
@@ -32,6 +33,7 @@ app.use("/api/*", async (c, next) => {
|
||||
});
|
||||
|
||||
app.route("/api/quotes", quotesRouter);
|
||||
app.route("/api/settings", settingsRouter);
|
||||
app.route("/api", expensesRouter);
|
||||
app.route("/api/telegram", telegramRouter);
|
||||
app.route("/api/wallets", walletsRouter);
|
||||
|
||||
29
apps/backend/src/modules/settings/settings.handler.ts
Normal file
29
apps/backend/src/modules/settings/settings.handler.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type { Context } from "hono";
|
||||
import { cache } from "../../lib/cache";
|
||||
import { prisma } from "../../lib/prisma";
|
||||
|
||||
export async function getSettings(c: Context) {
|
||||
const cached = cache.get("settings:all");
|
||||
if (cached) return c.json(cached);
|
||||
|
||||
const settings = await prisma.setting.findMany();
|
||||
cache.set("settings:all", settings, 60_000);
|
||||
return c.json(settings);
|
||||
}
|
||||
|
||||
export async function updateSetting(c: Context) {
|
||||
const body = await c.req.json<{ key: string; value: string }>();
|
||||
|
||||
if (!body.key || body.value === undefined) {
|
||||
return c.json({ error: "key and value are required" }, 400);
|
||||
}
|
||||
|
||||
const setting = await prisma.setting.upsert({
|
||||
where: { key: body.key },
|
||||
update: { value: body.value },
|
||||
create: { key: body.key, value: body.value },
|
||||
});
|
||||
|
||||
cache.invalidateByPrefix("settings:");
|
||||
return c.json(setting);
|
||||
}
|
||||
9
apps/backend/src/modules/settings/settings.routes.ts
Normal file
9
apps/backend/src/modules/settings/settings.routes.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Hono } from "hono";
|
||||
import { getSettings, updateSetting } from "./settings.handler";
|
||||
|
||||
const app = new Hono();
|
||||
|
||||
app.get("/", getSettings);
|
||||
app.put("/", updateSetting);
|
||||
|
||||
export default app;
|
||||
Reference in New Issue
Block a user