UI & API Struktur organisasi sudah bisa aktif & tidak aktif
This commit is contained in:
@@ -17,7 +17,7 @@ type FormCreatePegawai = {
|
||||
export default async function pegawaiCreate(context: Context) {
|
||||
const body = await context.body as FormCreatePegawai;
|
||||
|
||||
if (!body) {
|
||||
if (!body || typeof body !== 'object') {
|
||||
return {
|
||||
success: false,
|
||||
message: "Data tidak valid",
|
||||
@@ -42,7 +42,7 @@ export default async function pegawaiCreate(context: Context) {
|
||||
telepon: body.telepon,
|
||||
alamat: body.alamat,
|
||||
posisiId: body.posisiId,
|
||||
isActive: body.isActive !== false // default true kalau tidak dikirim
|
||||
isActive: body.isActive ?? true, // default true kalau tidak dikirim
|
||||
|
||||
},
|
||||
});
|
||||
|
||||
@@ -4,7 +4,6 @@ import prisma from "@/lib/prisma";
|
||||
export default async function pegawaiFindMany() {
|
||||
try {
|
||||
const pegawaiList = await prisma.pegawai.findMany({
|
||||
where: { isActive: true }, // Using the correct field name from Prisma model
|
||||
orderBy: { createdAt: "desc" },
|
||||
include: {
|
||||
posisi: true,
|
||||
|
||||
@@ -25,6 +25,11 @@ export default async function pegawaiUpdate(context: Context) {
|
||||
};
|
||||
}
|
||||
|
||||
if (typeof body.isActive !== 'boolean') {
|
||||
body.isActive = true; // fallback
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const updated = await prisma.pegawai.update({
|
||||
where: { id: body.id },
|
||||
@@ -37,7 +42,7 @@ export default async function pegawaiUpdate(context: Context) {
|
||||
telepon: body.telepon,
|
||||
alamat: body.alamat,
|
||||
posisiId: body.posisiId,
|
||||
isActive: body.isActive === true, // Konversi ke boolean
|
||||
isActive: body.isActive ?? true, // default true kalau tidak dikirim
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
include: {
|
||||
|
||||
Reference in New Issue
Block a user