Compare commits
13 Commits
amalia/08-
...
amalia/21-
| Author | SHA1 | Date | |
|---|---|---|---|
| dd6f27cf2b | |||
| 02cf404bc9 | |||
| 545e668bef | |||
| ad6c5157e9 | |||
| 73b19e0dd1 | |||
| abcbb3cd7f | |||
| ea3bf2cc3c | |||
| 6b17378679 | |||
| d861a3ea86 | |||
| 2f97ce81e4 | |||
| 3c0a5639b6 | |||
| 3ce650a27d | |||
| 0c131b80ef |
81
CLAUDE.md
Normal file
81
CLAUDE.md
Normal file
@@ -0,0 +1,81 @@
|
||||
# CLAUDE.md
|
||||
|
||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||
|
||||
## Commands
|
||||
|
||||
```bash
|
||||
# Development
|
||||
bun install # Install dependencies
|
||||
bun run dev # Dev server with experimental HTTPS (localhost:3000)
|
||||
bun run build # Production build
|
||||
bun run start # Start production server
|
||||
bun run lint # Run ESLint
|
||||
|
||||
# Database
|
||||
npx prisma migrate dev # Run/create migrations
|
||||
npx prisma db seed # Seed with initial data
|
||||
npx prisma generate # Regenerate Prisma client after schema changes
|
||||
```
|
||||
|
||||
## Architecture
|
||||
|
||||
**Sistem Desa Mandiri** is a village administration platform built on Next.js 14 (App Router) with PostgreSQL.
|
||||
|
||||
### Key Layers
|
||||
|
||||
- **`src/app/(application)/`** — Auth-protected pages grouped by feature (announcement, division, project, discussion, member, profile, home, group)
|
||||
- **`src/app/(auth)/`** — Login/register pages
|
||||
- **`src/app/api/`** — REST API endpoints; subdirectories map to resource types (`/api/announcement`, `/api/project`, `/api/task`, etc.). Mobile-specific endpoints live under `/api/mobile/`
|
||||
- **`src/module/`** — Business logic modules, one per feature (19 modules). Each module contains hooks, components, and API call functions for that domain
|
||||
- **`src/lib/`** — Shared utilities: Prisma client singleton (`prisma.ts`), Firebase init, route definitions (`routes.ts`), push notification hooks
|
||||
|
||||
### Data Access Pattern
|
||||
|
||||
All DB access goes through the Prisma client singleton in `src/lib/prisma.ts`. Prisma schema is at `prisma/schema.prisma` (40+ models). Migrations live in `prisma/migrations/`.
|
||||
|
||||
### State Management
|
||||
|
||||
- **Hookstate** (`@hookstate/core` + `@hookstate/localstored`) for client-side global state with localStorage persistence
|
||||
- **Iron-session** for server-side session management / auth
|
||||
- **Jose** for JWT handling
|
||||
|
||||
### UI Stack
|
||||
|
||||
- **Mantine 7** is the primary UI library (components, forms, modals, notifications, charts, dates, etc.)
|
||||
- **Tailwind CSS** for utility classes — used alongside Mantine
|
||||
- **PostCSS** configured with Mantine preset (`postcss.config.mjs`)
|
||||
|
||||
### Real-time & Notifications
|
||||
|
||||
- **Firebase FCM** (`src/lib/firebase/`) for mobile push notifications
|
||||
- **Web Push + VAPID keys** (`src/lib/usePushNotifications.ts`) for browser push
|
||||
- **wibu-realtime** (custom library) for WebSocket-based real-time updates
|
||||
|
||||
### User Roles
|
||||
|
||||
Five roles with distinct access levels (see `PANDUAN PENGGUNAAN.md`):
|
||||
1. **Super Admin** — full system access
|
||||
2. **Admin Desa** — village-level administration
|
||||
3. **Ketua Divisi** — division leader
|
||||
4. **Anggota Divisi** — division member
|
||||
5. **Warga/Perangkat Desa** — village resident/official
|
||||
|
||||
## Environment Variables
|
||||
|
||||
Copy `.env.example` to `.env`. Required variables:
|
||||
|
||||
| Variable | Purpose |
|
||||
|---|---|
|
||||
| `DATABASE_URL` | PostgreSQL connection string |
|
||||
| `GOOGLE_PROJECT_ID`, `GOOGLE_CLIENT_EMAIL`, `GOOGLE_PRIVATE_KEY` | Firebase Admin SDK (FCM) |
|
||||
| `NEXT_PUBLIC_VAPID_PUBLIC_KEY`, `VAPID_PRIVATE_KEY` | Web Push |
|
||||
| `WS_APIKEY` | WebSocket/file storage API key |
|
||||
| `WIBU_REALTIME_KEY` | Real-time communication |
|
||||
| `FCM_KEY` | Firebase Cloud Messaging |
|
||||
|
||||
## Deployment
|
||||
|
||||
Docker images are built via `.github/workflows/publish.yml` and pushed to GHCR (`ghcr.io`). Portainer redeploys via `.github/workflows/re-pull.yml`. Supports `dev`, `stg`, and `prod` stacks.
|
||||
|
||||
The Dockerfile uses a two-stage build: Bun builder → Bun runner (non-root user, port 3000).
|
||||
@@ -2,6 +2,7 @@ import { prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import _, { ceil } from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import moment from "moment";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
@@ -38,10 +39,10 @@ export async function GET(request: Request) {
|
||||
DivisionProjectTask: {
|
||||
some: {
|
||||
dateStart: {
|
||||
gte: new Date(String(date))
|
||||
gte: moment(String(date)).startOf('day').toDate()
|
||||
},
|
||||
dateEnd: {
|
||||
lte: new Date(String(dateAkhir))
|
||||
lte: moment(String(dateAkhir)).endOf('day').toDate()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -54,10 +55,10 @@ export async function GET(request: Request) {
|
||||
DivisionProjectTask: {
|
||||
some: {
|
||||
dateStart: {
|
||||
gte: new Date(String(date))
|
||||
gte: moment(String(date)).startOf('day').toDate()
|
||||
},
|
||||
dateEnd: {
|
||||
lte: new Date(String(dateAkhir))
|
||||
lte: moment(String(dateAkhir)).endOf('day').toDate()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,10 +103,10 @@ export async function GET(request: Request) {
|
||||
DivisionProjectTask: {
|
||||
some: {
|
||||
dateStart: {
|
||||
gte: new Date(String(date))
|
||||
gte: moment(String(date)).startOf('day').toDate()
|
||||
},
|
||||
dateEnd: {
|
||||
lte: new Date(String(dateAkhir))
|
||||
lte: moment(String(dateAkhir)).endOf('day').toDate()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,10 +118,10 @@ export async function GET(request: Request) {
|
||||
DivisionProjectTask: {
|
||||
some: {
|
||||
dateStart: {
|
||||
gte: new Date(String(date))
|
||||
gte: moment(String(date)).startOf('day').toDate()
|
||||
},
|
||||
dateEnd: {
|
||||
lte: new Date(String(dateAkhir))
|
||||
lte: moment(String(dateAkhir)).endOf('day').toDate()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,8 +172,8 @@ export async function GET(request: Request) {
|
||||
idGroup: String(grup)
|
||||
},
|
||||
createdAt: {
|
||||
gte: new Date(String(date)),
|
||||
lte: new Date(String(dateAkhir))
|
||||
gte: moment(String(date)).startOf('day').toDate(),
|
||||
lte: moment(String(dateAkhir)).endOf('day').toDate()
|
||||
},
|
||||
}
|
||||
} else {
|
||||
@@ -181,8 +182,8 @@ export async function GET(request: Request) {
|
||||
category: 'FILE',
|
||||
idDivision: String(division),
|
||||
createdAt: {
|
||||
gte: new Date(String(date)),
|
||||
lte: new Date(String(dateAkhir))
|
||||
gte: moment(String(date)).startOf('day').toDate(),
|
||||
lte: moment(String(dateAkhir)).endOf('day').toDate()
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -252,8 +253,8 @@ export async function GET(request: Request) {
|
||||
DivisionCalendarReminder: {
|
||||
some: {
|
||||
dateStart: {
|
||||
gte: new Date(String(date)),
|
||||
lte: new Date()
|
||||
gte: moment(String(date)).startOf('day').toDate(),
|
||||
lte: moment().toDate()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -267,8 +268,8 @@ export async function GET(request: Request) {
|
||||
DivisionCalendarReminder: {
|
||||
some: {
|
||||
dateStart: {
|
||||
gt: new Date(),
|
||||
lte: new Date(String(dateAkhir))
|
||||
gt: moment().toDate(),
|
||||
lte: moment(String(dateAkhir)).endOf('day').toDate()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -293,8 +294,8 @@ export async function GET(request: Request) {
|
||||
DivisionCalendarReminder: {
|
||||
some: {
|
||||
dateStart: {
|
||||
gte: new Date(String(date)),
|
||||
lte: new Date()
|
||||
gte: moment(String(date)).startOf('day').toDate(),
|
||||
lte: moment().toDate()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -306,8 +307,8 @@ export async function GET(request: Request) {
|
||||
DivisionCalendarReminder: {
|
||||
some: {
|
||||
dateStart: {
|
||||
gt: new Date(),
|
||||
lte: new Date(String(dateAkhir))
|
||||
gt: moment().toDate(),
|
||||
lte: moment(String(dateAkhir)).endOf('day').toDate()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
.use(cors({
|
||||
origin: "*",
|
||||
methods: ["GET", "POST", "OPTIONS"],
|
||||
allowedHeaders: ["Content-Type", "Authorization"]
|
||||
}))
|
||||
.use(swagger({
|
||||
path: "/docs", // Karena prefix instance adalah /api/monitoring, maka ini akan diakses di /api/monitoring/docs
|
||||
@@ -179,6 +180,11 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
)
|
||||
.get("/comparison-activity", async ({ query, set }) => {
|
||||
try {
|
||||
const villages = await prisma.village.findMany({
|
||||
where: { isDummy: false },
|
||||
select: { name: true },
|
||||
});
|
||||
|
||||
const data = await prisma.$queryRaw`
|
||||
SELECT
|
||||
v."name",
|
||||
@@ -192,9 +198,15 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
ORDER BY total_logs DESC;
|
||||
` as any[];
|
||||
|
||||
const result = data.map(item => ({
|
||||
village: item.name,
|
||||
activity: Number(item.total_logs)
|
||||
const logMap: Record<string, number> = {};
|
||||
|
||||
data.forEach((item) => {
|
||||
logMap[item.name] = Number(item.total_logs);
|
||||
});
|
||||
|
||||
const result = villages.map((v) => ({
|
||||
village: v.name,
|
||||
activity: logMap[v.name] || 0,
|
||||
}));
|
||||
|
||||
|
||||
@@ -309,6 +321,13 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
take: 10,
|
||||
})
|
||||
|
||||
const count = await prisma.village.count({
|
||||
where: {
|
||||
isDummy: false,
|
||||
...(search && { name: { contains: search, mode: 'insensitive' } })
|
||||
},
|
||||
})
|
||||
|
||||
const result = data.map((village) => ({
|
||||
id: village.id,
|
||||
name: village.name,
|
||||
@@ -321,6 +340,9 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: result,
|
||||
totalPage: Math.ceil(count / 10),
|
||||
currentPage: pageNum,
|
||||
totalData: count,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("[villages] get-villages error:", error);
|
||||
@@ -468,6 +490,8 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
name: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
desc: true,
|
||||
User: {
|
||||
where: {
|
||||
idUserRole: "supadmin"
|
||||
@@ -493,7 +517,9 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
id: data?.id,
|
||||
name: data?.name,
|
||||
isActive: data?.isActive,
|
||||
desc: data?.desc,
|
||||
createdAt: data?.createdAt ? formatDateTime(data.createdAt) : null,
|
||||
updatedAt: data?.updatedAt ? formatDateTime(data.updatedAt) : null,
|
||||
perbekel: data?.User[0]?.name || null,
|
||||
} : null;
|
||||
|
||||
@@ -781,6 +807,143 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
},
|
||||
}
|
||||
)
|
||||
.get("/list-group-villages", async ({ query, set }) => {
|
||||
const { id } = query;
|
||||
try {
|
||||
const data = await prisma.group.findMany({
|
||||
where: {
|
||||
idVillage: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
}
|
||||
})
|
||||
|
||||
if (!data) {
|
||||
set.status = 404;
|
||||
return {
|
||||
success: false,
|
||||
message: "Desa tidak ditemukan",
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: data,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("[detail-villages] list-group-villages error:", error);
|
||||
set.status = 500;
|
||||
return {
|
||||
success: false,
|
||||
message: "Terjadi kesalahan pada server",
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
query: t.Object({
|
||||
id: t.Optional(t.String({ description: "ID desa" })),
|
||||
}),
|
||||
detail: {
|
||||
summary: "List Group Villages",
|
||||
description: "Menu Detail Villages - Mendapatkan list group untuk dropdown.",
|
||||
tags: ["detail-villages"],
|
||||
},
|
||||
}
|
||||
)
|
||||
.get("/list-position-villages", async ({ query, set }) => {
|
||||
const { id } = query;
|
||||
try {
|
||||
const data = await prisma.position.findMany({
|
||||
where: {
|
||||
idGroup: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
}
|
||||
})
|
||||
|
||||
if (!data) {
|
||||
set.status = 404;
|
||||
return {
|
||||
success: false,
|
||||
message: "Posisi tidak ditemukan",
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: data,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("[detail-villages] list-position-villages error:", error);
|
||||
set.status = 500;
|
||||
return {
|
||||
success: false,
|
||||
message: "Terjadi kesalahan pada server",
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
query: t.Object({
|
||||
id: t.Optional(t.String({ description: "ID group" })),
|
||||
}),
|
||||
detail: {
|
||||
summary: "List Position Villages",
|
||||
description: "Menu Detail Villages - Mendapatkan list jabatan untuk dropdown.",
|
||||
tags: ["detail-villages"],
|
||||
},
|
||||
}
|
||||
)
|
||||
.get("/list-userrole-villages", async ({ query, set }) => {
|
||||
try {
|
||||
const data = await prisma.userRole.findMany({
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
}
|
||||
})
|
||||
|
||||
if (!data) {
|
||||
set.status = 404;
|
||||
return {
|
||||
success: false,
|
||||
message: "Role tidak ditemukan",
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: data,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("[detail-villages] list-userrole-villages error:", error);
|
||||
set.status = 500;
|
||||
return {
|
||||
success: false,
|
||||
message: "Terjadi kesalahan pada server",
|
||||
data: null,
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
detail: {
|
||||
summary: "List User Role",
|
||||
description: "Menu Detail Villages - Mendapatkan list role untuk dropdown.",
|
||||
tags: ["detail-villages"],
|
||||
},
|
||||
}
|
||||
)
|
||||
.post("/edit-villages", async ({ body, set }) => {
|
||||
const { id, name, desc } = body;
|
||||
|
||||
@@ -1009,7 +1172,7 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
.get("/user", async ({ query, set }) => {
|
||||
const { page = 1, search } = query;
|
||||
const pageNum = Number(page) || 1;
|
||||
const take = 25;
|
||||
const take = 15;
|
||||
const skip = (pageNum - 1) * take;
|
||||
|
||||
try {
|
||||
@@ -1063,6 +1226,11 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
email: true,
|
||||
isWithoutOTP: true,
|
||||
isActive: true,
|
||||
idUserRole: true,
|
||||
idVillage: true,
|
||||
idGroup: true,
|
||||
idPosition: true,
|
||||
gender: true,
|
||||
UserRole: {
|
||||
select: {
|
||||
name: true,
|
||||
@@ -1141,12 +1309,17 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
nik: item.nik,
|
||||
phone: item.phone,
|
||||
email: item.email,
|
||||
gender: item.gender,
|
||||
isWithoutOTP: item.isWithoutOTP,
|
||||
isActive: item.isActive,
|
||||
role: item.UserRole?.name,
|
||||
village: item.Village?.name,
|
||||
group: item.Group?.name,
|
||||
position: item.Position?.name,
|
||||
idUserRole: item.idUserRole,
|
||||
idVillage: item.idVillage,
|
||||
idGroup: item.idGroup,
|
||||
idPosition: item.idPosition,
|
||||
}));
|
||||
|
||||
return {
|
||||
@@ -1349,3 +1522,4 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
|
||||
export const GET = MonitoringServer.handle;
|
||||
export const POST = MonitoringServer.handle;
|
||||
export const OPTIONS = MonitoringServer.handle;
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
return NextResponse.json({ success: true, version: "2.1.9", tahap: "beta", update: "-api untuk dashboard monitoring" }, { status: 200 });
|
||||
return NextResponse.json({ success: true, version: "2.1.10", tahap: "beta", update: "-perbaikan grafik divisi" }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
|
||||
Reference in New Issue
Block a user