Compare commits
5 Commits
amalia/08-
...
amalia/10-
| Author | SHA1 | Date | |
|---|---|---|---|
| d861a3ea86 | |||
| 2f97ce81e4 | |||
| 3c0a5639b6 | |||
| 3ce650a27d | |||
| 0c131b80ef |
@@ -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);
|
||||
@@ -781,6 +803,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 +1168,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 +1222,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 +1305,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 +1518,4 @@ const MonitoringServer = new Elysia({ prefix: "/api/monitoring" })
|
||||
|
||||
export const GET = MonitoringServer.handle;
|
||||
export const POST = MonitoringServer.handle;
|
||||
export const OPTIONS = MonitoringServer.handle;
|
||||
|
||||
Reference in New Issue
Block a user