Fix menu admin landing page, submenu sosial media
This commit is contained in:
@@ -5,6 +5,7 @@ type FormCreate = {
|
||||
name: string;
|
||||
imageId: string;
|
||||
iconUrl: string;
|
||||
icon: string;
|
||||
};
|
||||
|
||||
export default async function mediaSosialCreate(context: Context) {
|
||||
@@ -14,8 +15,9 @@ export default async function mediaSosialCreate(context: Context) {
|
||||
const result = await prisma.mediaSosial.create({
|
||||
data: {
|
||||
name: body.name,
|
||||
imageId: body.imageId,
|
||||
imageId: body.imageId || null,
|
||||
iconUrl: body.iconUrl,
|
||||
icon: body.icon || null,
|
||||
},
|
||||
include: {
|
||||
image: true,
|
||||
@@ -29,8 +31,6 @@ export default async function mediaSosialCreate(context: Context) {
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error creating media sosial:", error);
|
||||
throw new Error(
|
||||
"Gagal membuat media sosial: " + (error as Error).message
|
||||
);
|
||||
throw new Error("Gagal membuat media sosial: " + (error as Error).message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,8 +20,9 @@ const MediaSosial = new Elysia({
|
||||
.post("/create", MediaSosialCreate, {
|
||||
body: t.Object({
|
||||
name: t.String(),
|
||||
imageId: t.String(),
|
||||
iconUrl: t.String(),
|
||||
imageId: t.Union([t.String(), t.Null()]),
|
||||
iconUrl: t.Union([t.String(), t.Null()]),
|
||||
icon: t.Union([t.String(), t.Null()]),
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -29,8 +30,9 @@ const MediaSosial = new Elysia({
|
||||
.put("/:id", MediaSosialUpdate, {
|
||||
body: t.Object({
|
||||
name: t.String(),
|
||||
imageId: t.Optional(t.String()),
|
||||
iconUrl: t.Optional(t.String()),
|
||||
imageId: t.Optional(t.Union([t.String(), t.Null()])),
|
||||
iconUrl: t.Optional(t.Union([t.String(), t.Null()])),
|
||||
icon: t.Optional(t.Union([t.String(), t.Null()])),
|
||||
}),
|
||||
})
|
||||
// ✅ Delete
|
||||
|
||||
@@ -6,6 +6,7 @@ type FormUpdateMediaSosial = {
|
||||
name?: string;
|
||||
imageId?: string;
|
||||
iconUrl?: string;
|
||||
icon?: string;
|
||||
};
|
||||
|
||||
export default async function mediaSosialUpdate(context: Context) {
|
||||
@@ -20,13 +21,29 @@ export default async function mediaSosialUpdate(context: Context) {
|
||||
};
|
||||
}
|
||||
|
||||
// 🚨 Tambahkan validasi di sini
|
||||
if (!body.name || body.name.trim().length < 3) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Nama media sosial minimal 3 karakter",
|
||||
};
|
||||
}
|
||||
|
||||
if (!body.iconUrl || body.iconUrl.trim().length < 3) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Icon URL minimal 3 karakter",
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
const updated = await prisma.mediaSosial.update({
|
||||
where: { id },
|
||||
data: {
|
||||
name: body.name,
|
||||
imageId: body.imageId,
|
||||
imageId: body.imageId || null, // pastikan null jika kosong
|
||||
iconUrl: body.iconUrl,
|
||||
icon: body.icon || null, // pastikan null jika kosong
|
||||
},
|
||||
include: {
|
||||
image: true,
|
||||
|
||||
Reference in New Issue
Block a user