UI & API Menu Ekonomi, SubMenu PADesa : Tabs Pendapatan, Pembiayaan, dan Belanja
This commit is contained in:
@@ -3,9 +3,9 @@ import { Context } from "elysia";
|
||||
|
||||
type FormCreate = {
|
||||
tahun: number;
|
||||
pendapatanId: string;
|
||||
belanjaId: string;
|
||||
pembiayaanId: string;
|
||||
pendapatanIds: string[];
|
||||
belanjaIds: string[];
|
||||
pembiayaanIds: string[];
|
||||
}
|
||||
|
||||
export default async function apbDesaCreate(context: Context) {
|
||||
@@ -14,16 +14,22 @@ export default async function apbDesaCreate(context: Context) {
|
||||
const created = await prisma.apbDesa.create({
|
||||
data: {
|
||||
tahun: body.tahun,
|
||||
pendapatanId: body.pendapatanId,
|
||||
belanjaId: body.belanjaId,
|
||||
pembiayaanId: body.pembiayaanId,
|
||||
pendapatan: {
|
||||
connect: body.pendapatanIds.map((id) => ({ id })),
|
||||
},
|
||||
belanja: {
|
||||
connect: body.belanjaIds.map((id) => ({ id })),
|
||||
},
|
||||
pembiayaan: {
|
||||
connect: body.pembiayaanIds.map((id) => ({ id })),
|
||||
},
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
tahun: true,
|
||||
pendapatanId: true,
|
||||
belanjaId: true,
|
||||
pembiayaanId: true,
|
||||
pendapatan: true,
|
||||
belanja: true,
|
||||
pembiayaan: true,
|
||||
}
|
||||
});
|
||||
return {
|
||||
|
||||
@@ -26,6 +26,11 @@ export default async function apbDesaFindUnique(
|
||||
|
||||
const data = await prisma.apbDesa.findUnique({
|
||||
where: { id },
|
||||
include: {
|
||||
pendapatan: true,
|
||||
belanja: true,
|
||||
pembiayaan: true,
|
||||
}
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
|
||||
@@ -17,9 +17,9 @@ const APBDesa = new Elysia({
|
||||
.post("/create", apbDesaCreate, {
|
||||
body: t.Object({
|
||||
tahun: t.Number(),
|
||||
pendapatanId: t.String(),
|
||||
belanjaId: t.String(),
|
||||
pembiayaanId: t.String(),
|
||||
pendapatanIds: t.Array(t.String()),
|
||||
belanjaIds: t.Array(t.String()),
|
||||
pembiayaanIds: t.Array(t.String()),
|
||||
}),
|
||||
})
|
||||
.delete("/delete/:id", apbDesaDelete)
|
||||
@@ -32,9 +32,9 @@ const APBDesa = new Elysia({
|
||||
{
|
||||
body: t.Object({
|
||||
tahun: t.Number(),
|
||||
pendapatanId: t.String(),
|
||||
belanjaId: t.String(),
|
||||
pembiayaanId: t.String(),
|
||||
pendapatanIds: t.Array(t.String()),
|
||||
belanjaIds: t.Array(t.String()),
|
||||
pembiayaanIds: t.Array(t.String()),
|
||||
}),
|
||||
}
|
||||
);
|
||||
|
||||
@@ -1,26 +1,23 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
|
||||
type FormUpdate = Prisma.ApbDesaGetPayload<{
|
||||
select: {
|
||||
id: true;
|
||||
tahun: true;
|
||||
pendapatanId: true;
|
||||
belanjaId: true;
|
||||
pembiayaanId: true;
|
||||
};
|
||||
}>;
|
||||
type FormUpdate = {
|
||||
id: string;
|
||||
tahun: number;
|
||||
pendapatanIds: string[];
|
||||
belanjaIds: string[];
|
||||
pembiayaanIds: string[];
|
||||
};
|
||||
export default async function apbDesaUpdate(context: Context) {
|
||||
try {
|
||||
const id = context.params?.id as string;
|
||||
const body = (await context.body) as Omit<FormUpdate, "id">;
|
||||
const body = (await context.body) as FormUpdate;
|
||||
|
||||
const {
|
||||
tahun,
|
||||
pendapatanId,
|
||||
belanjaId,
|
||||
pembiayaanId,
|
||||
pendapatanIds,
|
||||
belanjaIds,
|
||||
pembiayaanIds,
|
||||
} = body;
|
||||
|
||||
if (!id) {
|
||||
@@ -45,9 +42,15 @@ export default async function apbDesaUpdate(context: Context) {
|
||||
where: { id },
|
||||
data: {
|
||||
tahun,
|
||||
pendapatanId,
|
||||
belanjaId,
|
||||
pembiayaanId,
|
||||
pendapatan: {
|
||||
connect: pendapatanIds.map((id) => ({ id })),
|
||||
},
|
||||
belanja: {
|
||||
connect: belanjaIds.map((id) => ({ id })),
|
||||
},
|
||||
pembiayaan: {
|
||||
connect: pembiayaanIds.map((id) => ({ id })),
|
||||
},
|
||||
}
|
||||
});
|
||||
return {
|
||||
|
||||
@@ -20,7 +20,7 @@ const Belanja = new Elysia({
|
||||
value: t.Number(),
|
||||
}),
|
||||
})
|
||||
.delete("/delete/:id", belanjaDelete)
|
||||
.delete("/del/:id", belanjaDelete)
|
||||
.put("/:id", async (context) => {
|
||||
const response = await belanjaUpdate(context);
|
||||
return response;
|
||||
|
||||
@@ -1,60 +1,36 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
|
||||
type FormUpdate = Prisma.BelanjaGetPayload<{
|
||||
select: {
|
||||
id: true;
|
||||
name: true;
|
||||
value: true;
|
||||
};
|
||||
}>;
|
||||
|
||||
export default async function belanjaUpdate(context: Context) {
|
||||
try {
|
||||
const id = context.params?.id as string;
|
||||
const body = (await context.body) as Omit<FormUpdate, "id">;
|
||||
|
||||
const {
|
||||
name,
|
||||
value,
|
||||
} = body;
|
||||
|
||||
if (!id) {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID tidak boleh kosong",
|
||||
};
|
||||
}
|
||||
|
||||
const existing = await prisma.belanja.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Belanja tidak ditemukan",
|
||||
};
|
||||
}
|
||||
|
||||
const updated = await prisma.belanja.update({
|
||||
where: { id },
|
||||
data: {
|
||||
name,
|
||||
value,
|
||||
}
|
||||
});
|
||||
return {
|
||||
success: true,
|
||||
message: "Success update belanja",
|
||||
data: updated,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Update error:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed update belanja",
|
||||
};
|
||||
const id = context.params?.id as string;
|
||||
const body = context.body as { name: string; value: number };
|
||||
|
||||
if (!id) {
|
||||
return { success: false, message: "ID tidak boleh kosong" };
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const existing = await prisma.belanja.findUnique({ where: { id } });
|
||||
if (!existing) {
|
||||
return { success: false, message: "Data tidak ditemukan" };
|
||||
}
|
||||
|
||||
const updated = await prisma.belanja.update({
|
||||
where: { id },
|
||||
data: {
|
||||
name: body.name,
|
||||
value: body.value,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil update belanja",
|
||||
data: updated,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Update error:", error);
|
||||
return { success: false, message: "Gagal update belanja" };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,60 +1,36 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
|
||||
type FormUpdate = Prisma.PembiayaanGetPayload<{
|
||||
select: {
|
||||
id: true;
|
||||
name: true;
|
||||
value: true;
|
||||
};
|
||||
}>;
|
||||
|
||||
export default async function pembiayaanUpdate(context: Context) {
|
||||
try {
|
||||
const id = context.params?.id as string;
|
||||
const body = (await context.body) as Omit<FormUpdate, "id">;
|
||||
|
||||
const {
|
||||
name,
|
||||
value,
|
||||
} = body;
|
||||
|
||||
if (!id) {
|
||||
return {
|
||||
success: false,
|
||||
message: "ID tidak boleh kosong",
|
||||
};
|
||||
}
|
||||
|
||||
const existing = await prisma.pembiayaan.findUnique({
|
||||
where: { id },
|
||||
});
|
||||
|
||||
if (!existing) {
|
||||
return {
|
||||
success: false,
|
||||
message: "Pembiayaan tidak ditemukan",
|
||||
};
|
||||
}
|
||||
|
||||
const updated = await prisma.pembiayaan.update({
|
||||
where: { id },
|
||||
data: {
|
||||
name,
|
||||
value,
|
||||
}
|
||||
});
|
||||
return {
|
||||
success: true,
|
||||
message: "Success update pembiayaan",
|
||||
data: updated,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Update error:", error);
|
||||
return {
|
||||
success: false,
|
||||
message: "Failed update pembiayaan",
|
||||
};
|
||||
const id = context.params?.id as string;
|
||||
const body = context.body as { name: string; value: number };
|
||||
|
||||
if (!id) {
|
||||
return { success: false, message: "ID tidak boleh kosong" };
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const existing = await prisma.pembiayaan.findUnique({ where: { id } });
|
||||
if (!existing) {
|
||||
return { success: false, message: "Data tidak ditemukan" };
|
||||
}
|
||||
|
||||
const updated = await prisma.pembiayaan.update({
|
||||
where: { id },
|
||||
data: {
|
||||
name: body.name,
|
||||
value: body.value,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: "Berhasil update pembiayaan",
|
||||
data: updated,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Update error:", error);
|
||||
return { success: false, message: "Gagal update pembiayaan" };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user