Compare commits

...

22 Commits

Author SHA1 Message Date
1e02747e22 feat: tambahkan village-report endpoint dengan perbandingan periode sebelumnya
- Endpoint /village-report kini menghitung activity_count periode saat ini
  dan prev_activity_count periode sebelumnya dalam satu query (doubleRange)
- Tambahkan kalkulasi trend persentase perubahan antar periode
- Sertakan data perbekel, active_users, inactive_users, lastActivity, dan daysSince
- Tambahkan endpoint /export-logs dan /export-users untuk ekspor CSV
2026-05-28 15:39:47 +08:00
a0bffd53cb feat: tambah endpoint export-logs dan export-users untuk CSV download 2026-05-28 15:06:23 +08:00
8dca3e440f feat: tambah endpoint peak-hours untuk distribusi aktivitas per jam 2026-05-28 14:47:11 +08:00
1df1d10c91 feat: tambah endpoint inactive-users dan lengkapi field response-nya 2026-05-28 14:32:49 +08:00
e5891f0da3 feat: tambah idVillage ke response log-all-villages 2026-05-28 14:18:03 +08:00
619cc9a403 feat: tambah endpoint stale-villages untuk deteksi desa tidak aktif 2026-05-28 14:14:35 +08:00
3272ecaef3 feat: tambah field lastActivity ke endpoint monitoring /user 2026-05-28 14:09:42 +08:00
3b5126d8ee Merge pull request 'amalia/25-mei-26' (#53) from amalia/25-mei-26 into join
Reviewed-on: #53
2026-05-25 17:32:47 +08:00
552957282b bump: version 0.1.18 + migration 2026-05-25 15:36:30 +08:00
22555079f3 feat: graph-log-villages support dateFrom/dateTo + recent-village-logs endpoint 2026-05-25 15:08:30 +08:00
6cf6486172 feat: tambah endpoint GET /api-keys/:id untuk ambil full key 2026-05-25 12:00:53 +08:00
35e51028db Merge pull request 'amalia/22-mei-26' (#52) from amalia/22-mei-26 into join
Reviewed-on: #52
2026-05-22 17:41:21 +08:00
37ea4e37e7 bump: version 0.1.17 + migration 2026-05-22 14:46:33 +08:00
e270db3bfa feat: add range param to daily-activity and comparison-activity endpoints
Both endpoints now accept ?range=7|30|90 (default 7).
comparison-activity result now follows SQL ORDER BY instead of being
remapped through villages array.
2026-05-22 14:16:36 +08:00
32dac32532 feat: add village and date range filter on /log-all-villages endpoint 2026-05-22 11:37:42 +08:00
d369a71eb6 feat: add filter and orderBy support on /user monitoring endpoint 2026-05-22 11:17:42 +08:00
7334831d61 Merge pull request 'bump: version 0.1.16 + migration' (#51) from amalia/21-mei-26 into join
Reviewed-on: #51
2026-05-21 17:25:52 +08:00
c0a4d584af bump: version 0.1.16 + migration 2026-05-21 11:07:23 +08:00
9ac105e7bc Merge pull request 'amalia/20-mei-26' (#50) from amalia/20-mei-26 into join
Reviewed-on: #50
2026-05-20 17:22:20 +08:00
10457e96e8 feat: tambah autentikasi x-api-key pada NOC API dan ekstrak isValidApiKey ke shared lib 2026-05-20 12:23:38 +08:00
9ad934c99f bump: version 0.1.15 + migration 2026-05-19 16:05:35 +08:00
5bfcde32ed Merge pull request 'amalia/18-mei-26' (#49) from amalia/18-mei-26 into join
Reviewed-on: #49
2026-05-18 17:26:42 +08:00
9 changed files with 693 additions and 243 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "sistem-desa-mandiri",
"version": "0.1.14",
"version": "0.1.18",
"private": true,
"scripts": {
"dev": "next dev --experimental-https",

View File

@@ -0,0 +1 @@
-- This is an empty migration.

View File

@@ -0,0 +1 @@
-- This is an empty migration.

View File

@@ -0,0 +1 @@
-- This is an empty migration.

View File

@@ -0,0 +1 @@
-- This is an empty migration.

View File

@@ -1,3 +1,4 @@
import { isValidApiKey } from "@/lib/apiKey";
import { prisma } from "@/module/_global";
import cors from "@elysiajs/cors";
import { swagger } from "@elysiajs/swagger";
@@ -6,20 +7,6 @@ import _ from "lodash";
import moment from "moment";
import "moment/locale/id";
const CACHE_TTL_MS = 60_000;
let apiKeyCache: Set<string> = new Set();
let cacheExpiresAt = 0;
async function isValidApiKey(incoming: string): Promise<boolean> {
const now = Date.now();
if (now > cacheExpiresAt) {
const rows = await prisma.apiKey.findMany({ where: { isActive: true }, select: { key: true } });
apiKeyCache = new Set(rows.map((r) => r.key));
cacheExpiresAt = now + CACHE_TTL_MS;
}
return apiKeyCache.has(incoming);
}
const AiServer = new Elysia({ prefix: "/api/ai" })
.use(cors({
origin: "*",

File diff suppressed because it is too large Load Diff

View File

@@ -1,3 +1,4 @@
import { isValidApiKey } from "@/lib/apiKey";
import { prisma } from "@/module/_global";
import cors from "@elysiajs/cors";
import { swagger } from "@elysiajs/swagger";
@@ -11,20 +12,40 @@ const NocServer = new Elysia({ prefix: "/api/noc" })
.use(cors({
origin: "*",
methods: ["GET", "POST", "OPTIONS"],
allowedHeaders: ["Content-Type", "x-api-key"],
}))
.use(swagger({
path: "/docs", // Karena prefix instance adalah /api/noc, maka ini akan diakses di /api/noc/docs
path: "/docs",
documentation: {
info: {
title: "Sistem Desa Mandiri - NOC API",
version: "1.0.0",
description: "API Khusus untuk kebutuhan NOC (Network Operation Center) dan Monitoring Desa",
},
components: {
securitySchemes: {
ApiKeyAuth: {
type: "apiKey",
in: "header",
name: "x-api-key",
},
},
},
security: [{ ApiKeyAuth: [] }],
tags: [
{ name: "NOC", description: "Endpoint khusus monitoring" }
]
}
}))
.onBeforeHandle(async ({ request, set, path }) => {
if (path.startsWith("/api/noc/docs")) return;
const incoming = request.headers.get("x-api-key");
if (!incoming || !(await isValidApiKey(incoming))) {
set.status = 401;
return { success: false, message: "Unauthorized" };
}
})
// ── GET /api/noc/active-divisions ──────────────────────────────────────────
.get(

15
src/lib/apiKey.ts Normal file
View File

@@ -0,0 +1,15 @@
import { prisma } from "@/module/_global";
const CACHE_TTL_MS = 60_000;
let apiKeyCache: Set<string> = new Set();
let cacheExpiresAt = 0;
export async function isValidApiKey(incoming: string): Promise<boolean> {
const now = Date.now();
if (now > cacheExpiresAt) {
const rows = await prisma.apiKey.findMany({ where: { isActive: true }, select: { key: true } });
apiKeyCache = new Set(rows.map((r) => r.key));
cacheExpiresAt = now + CACHE_TTL_MS;
}
return apiKeyCache.has(incoming);
}