Fix UI Admin Menu Kesehatan, Login Admin, OTP
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
if (req.method !== "POST") {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method Not Allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const { data } = await req.json();
|
||||
|
||||
const cekUsername = await prisma.user.findUnique({
|
||||
where: {
|
||||
username: data.username,
|
||||
nomor: data.nomor,
|
||||
},
|
||||
});
|
||||
|
||||
if (cekUsername)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Username sudah digunakan",
|
||||
});
|
||||
|
||||
const createUser = await prisma.user.create({
|
||||
data: {
|
||||
username: data.username,
|
||||
nomor: data.nomor,
|
||||
},
|
||||
});
|
||||
|
||||
if (!createUser)
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Gagal Registrasi" },
|
||||
{ status: 500 }
|
||||
);
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Registrasi Berhasil, Anda Sedang Login",
|
||||
// data: createUser,
|
||||
},
|
||||
{ status: 201 }
|
||||
);
|
||||
} catch (error) {
|
||||
console.error("Error registrasi:", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Maaf, Terjadi Keselahan",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,64 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function artikelKesehatanFindMany(context: Context) {
|
||||
// Ambil parameter dari query
|
||||
const page = Number(context.query.page) || 1;
|
||||
const limit = Number(context.query.limit) || 10;
|
||||
const search = (context.query.search as string) || "";
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
// Buat where clause
|
||||
const where: any = { isActive: true };
|
||||
|
||||
// Tambahkan pencarian (jika ada)
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ title: { contains: search, mode: "insensitive" } },
|
||||
{ introduction: { content: { contains: search, mode: "insensitive" } } },
|
||||
{ symptom: { title: { contains: search, mode: "insensitive" } } },
|
||||
{ prevention: { title: { contains: search, mode: "insensitive" } } },
|
||||
{ firstaid: { title: { contains: search, mode: "insensitive" } } },
|
||||
{ mythvsfact: { title: { contains: search, mode: "insensitive" } } },
|
||||
{ doctorsign: { content: { contains: search, mode: "insensitive" } } },
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
// Ambil data dan total count secara paralel
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.artikelKesehatan.findMany({
|
||||
where,
|
||||
include: {
|
||||
introduction: true,
|
||||
symptom: true,
|
||||
prevention: true,
|
||||
firstaid: true,
|
||||
mythvsfact: true,
|
||||
doctorsign: true,
|
||||
},
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" },
|
||||
}),
|
||||
prisma.artikelKesehatan.count({ where }),
|
||||
]);
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil ambil keamanan lingkungan dengan pagination",
|
||||
data,
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("Error di findMany paginated:", e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Gagal mengambil data keamanan lingkungan",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default async function artikelKesehatanFindMany() {
|
||||
try {
|
||||
const data = await prisma.artikelKesehatan.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
include: {
|
||||
introduction: true,
|
||||
symptom: true,
|
||||
prevention: true,
|
||||
firstaid: true,
|
||||
mythvsfact: true,
|
||||
doctorsign: true,
|
||||
}
|
||||
})
|
||||
return {
|
||||
success: true,
|
||||
message: "Success fetch artikel kesehatan",
|
||||
data,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Find many error:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed fetch artikel kesehatan",
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,35 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
// /api/berita/findManyPaginated.ts
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function findManyFasilitasKesehatan() {
|
||||
try {
|
||||
const data = await prisma.fasilitasKesehatan.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
async function fasilitasKesehatanFindMany(context: Context) {
|
||||
// Ambil parameter dari query
|
||||
const page = Number(context.query.page) || 1;
|
||||
const limit = Number(context.query.limit) || 10;
|
||||
const search = (context.query.search as string) || '';
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
// Buat where clause
|
||||
const where: any = { isActive: true };
|
||||
|
||||
// Tambahkan pencarian (jika ada)
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ informasiUmum: { fasilitas: { contains: search, mode: 'insensitive' } } },
|
||||
{ layananUnggulan: { content: { contains: search, mode: 'insensitive' } } },
|
||||
{ dokterdanTenagaMedis: { name: { contains: search, mode: 'insensitive' } } },
|
||||
{ fasilitasPendukung: { content: { contains: search, mode: 'insensitive' } } },
|
||||
{ prosedurPendaftaran: { content: { contains: search, mode: 'insensitive' } } },
|
||||
{ tarifdanlayanan: { layanan: { contains: search, mode: 'insensitive' } } },
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
// Ambil data dan total count secara paralel
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.fasilitasKesehatan.findMany({
|
||||
where,
|
||||
include: {
|
||||
informasiumum: true,
|
||||
layananunggulan: true,
|
||||
@@ -13,18 +37,29 @@ export default async function findManyFasilitasKesehatan() {
|
||||
fasilitaspendukung: true,
|
||||
prosedurpendaftaran: true,
|
||||
tarifdanlayanan: true,
|
||||
}
|
||||
})
|
||||
return {
|
||||
success: true,
|
||||
message: "Success fetch fasilitas kesehatan",
|
||||
data,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Find many error:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed fetch fasilitas kesehatan",
|
||||
}
|
||||
},
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: 'desc' },
|
||||
}),
|
||||
prisma.fasilitasKesehatan.count({ where }),
|
||||
]);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil ambil keamanan lingkungan dengan pagination",
|
||||
data,
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
};
|
||||
} catch (e) {
|
||||
console.error("Error di findMany paginated:", e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Gagal mengambil data keamanan lingkungan",
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
export default fasilitasKesehatanFindMany
|
||||
@@ -1,30 +1,60 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function jadwalKegiatanFindMany() {
|
||||
try {
|
||||
const data = await prisma.jadwalKegiatan.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
},
|
||||
include: {
|
||||
informasijadwalkegiatan: true,
|
||||
deskripsijadwalkegiatan: true,
|
||||
layananjadwalkegiatan: true,
|
||||
syaratketentuanjadwalkegiatan: true,
|
||||
dokumenjadwalkegiatan: true,
|
||||
pendaftaranjadwalkegiatan: true,
|
||||
}
|
||||
})
|
||||
return {
|
||||
success: true,
|
||||
message: "Success fetch jadwal kegiatan",
|
||||
data,
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Find many error:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed fetch jadwal kegiatan",
|
||||
}
|
||||
}
|
||||
}
|
||||
export default async function jadwalKegiatanFindMany(context: Context) {
|
||||
// Ambil parameter dari query
|
||||
const page = Number(context.query.page) || 1;
|
||||
const limit = Number(context.query.limit) || 10;
|
||||
const search = (context.query.search as string) || "";
|
||||
const skip = (page - 1) * limit;
|
||||
|
||||
// Buat where clause
|
||||
const where: any = { isActive: true };
|
||||
|
||||
// Tambahkan pencarian (jika ada)
|
||||
if (search) {
|
||||
where.OR = [
|
||||
{ informasijadwalkegiatan: { name: { contains: search, mode: "insensitive" } } },
|
||||
{ deskripsijadwalkegiatan: { deskripsi: { contains: search, mode: "insensitive" } } },
|
||||
{layananjadwalkegiatan: { content: { contains: search, mode: "insensitive" } } },
|
||||
{syaratketentuanjadwalkegiatan: { content: { contains: search, mode: "insensitive" } } },
|
||||
{dokumenjadwalkegiatan: { content: { contains: search, mode: "insensitive" } } },
|
||||
{pendaftaranjadwalkegiatan: { content: { contains: search, mode: "insensitive" } } },
|
||||
];
|
||||
}
|
||||
try {
|
||||
const [data, total] = await Promise.all([
|
||||
prisma.jadwalKegiatan.findMany({
|
||||
where,
|
||||
include: {
|
||||
informasijadwalkegiatan: true,
|
||||
deskripsijadwalkegiatan: true,
|
||||
layananjadwalkegiatan: true,
|
||||
syaratketentuanjadwalkegiatan: true,
|
||||
dokumenjadwalkegiatan: true,
|
||||
pendaftaranjadwalkegiatan: true,
|
||||
},
|
||||
skip,
|
||||
take: limit,
|
||||
orderBy: { createdAt: "desc" },
|
||||
}),
|
||||
prisma.jadwalKegiatan.count({ where }),
|
||||
]);
|
||||
return {
|
||||
success: true,
|
||||
message: "Success fetch jadwal kegiatan",
|
||||
data,
|
||||
page,
|
||||
limit,
|
||||
total,
|
||||
totalPages: Math.ceil(total / limit),
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Find many error:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed fetch jadwal kegiatan",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Elysia, t } from "elysia";
|
||||
import userFindMany from "./findMany";
|
||||
import userFindUnique from "./findUnique";
|
||||
import userDelete from "./del"; // `delete` nggak boleh jadi nama file JS langsung, jadi biasanya `del.ts`
|
||||
import userUpdate from "./updt";
|
||||
|
||||
const User = new Elysia({ prefix: "/api/user" })
|
||||
.get("/findMany", userFindMany)
|
||||
@@ -12,6 +13,7 @@ const User = new Elysia({ prefix: "/api/user" })
|
||||
params: t.Object({
|
||||
id: t.String(),
|
||||
}),
|
||||
}); // pakai PUT untuk soft delete
|
||||
}) // pakai PUT untuk soft delete
|
||||
.put("/updt", userUpdate);
|
||||
|
||||
export default User;
|
||||
|
||||
40
src/app/api/[[...slugs]]/_lib/user/updt.ts
Normal file
40
src/app/api/[[...slugs]]/_lib/user/updt.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Context } from "elysia";
|
||||
|
||||
export default async function userUpdate(context: Context) {
|
||||
try {
|
||||
const { id, isActive } = await context.body as { id: string, isActive: boolean };
|
||||
|
||||
if (!id) {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID user wajib ada",
|
||||
};
|
||||
}
|
||||
|
||||
const updatedUser = await prisma.user.update({
|
||||
where: { id },
|
||||
data: { isActive },
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
nomor: true,
|
||||
isActive: true,
|
||||
updatedAt: true,
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: `User berhasil ${isActive ? "diaktifkan" : "dinonaktifkan"}`,
|
||||
data: updatedUser,
|
||||
};
|
||||
} catch (e: any) {
|
||||
console.error("Error update user:", e);
|
||||
return {
|
||||
success: false,
|
||||
message: "Gagal mengupdate status user",
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user