Fix Dibagian Data Kesehatan Warga

This commit is contained in:
2025-06-28 00:10:45 +08:00
parent 6d5b8dcf64
commit 41181d4cb3
18 changed files with 184 additions and 118 deletions

View File

@@ -0,0 +1,68 @@
/*
Warnings:
- The primary key for the `DataKematian_Kelahiran` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `uuid` on the `DataKematian_Kelahiran` table. All the data in the column will be lost.
- The primary key for the `GrafikKepuasan` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `uuid` on the `GrafikKepuasan` table. All the data in the column will be lost.
- A unique constraint covering the columns `[id]` on the table `DataKematian_Kelahiran` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[id]` on the table `GrafikKepuasan` will be added. If there are existing duplicate values, this will fail.
- Added the required column `doctorSignId` to the `ArtikelKesehatan` table without a default value. This is not possible if the table is not empty.
- Added the required column `firstAidId` to the `ArtikelKesehatan` table without a default value. This is not possible if the table is not empty.
- Added the required column `introductionId` to the `ArtikelKesehatan` table without a default value. This is not possible if the table is not empty.
- Added the required column `mythVsFactId` to the `ArtikelKesehatan` table without a default value. This is not possible if the table is not empty.
- Added the required column `preventionId` to the `ArtikelKesehatan` table without a default value. This is not possible if the table is not empty.
- Added the required column `symptomId` to the `ArtikelKesehatan` table without a default value. This is not possible if the table is not empty.
*/
-- DropIndex
DROP INDEX "DataKematian_Kelahiran_uuid_key";
-- DropIndex
DROP INDEX "GrafikKepuasan_uuid_key";
-- AlterTable
ALTER TABLE "ArtikelKesehatan" ADD COLUMN "doctorSignId" TEXT NOT NULL,
ADD COLUMN "firstAidId" TEXT NOT NULL,
ADD COLUMN "introductionId" TEXT NOT NULL,
ADD COLUMN "mythVsFactId" TEXT NOT NULL,
ADD COLUMN "preventionId" TEXT NOT NULL,
ADD COLUMN "symptomId" TEXT NOT NULL;
-- AlterTable
ALTER TABLE "DataKematian_Kelahiran" DROP CONSTRAINT "DataKematian_Kelahiran_pkey",
DROP COLUMN "uuid",
ALTER COLUMN "id" DROP DEFAULT,
ALTER COLUMN "id" SET DATA TYPE TEXT;
DROP SEQUENCE "DataKematian_Kelahiran_id_seq";
-- AlterTable
ALTER TABLE "GrafikKepuasan" DROP CONSTRAINT "GrafikKepuasan_pkey",
DROP COLUMN "uuid",
ALTER COLUMN "id" DROP DEFAULT,
ALTER COLUMN "id" SET DATA TYPE TEXT;
DROP SEQUENCE "GrafikKepuasan_id_seq";
-- CreateIndex
CREATE UNIQUE INDEX "DataKematian_Kelahiran_id_key" ON "DataKematian_Kelahiran"("id");
-- CreateIndex
CREATE UNIQUE INDEX "GrafikKepuasan_id_key" ON "GrafikKepuasan"("id");
-- AddForeignKey
ALTER TABLE "ArtikelKesehatan" ADD CONSTRAINT "ArtikelKesehatan_introductionId_fkey" FOREIGN KEY ("introductionId") REFERENCES "Introduction"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ArtikelKesehatan" ADD CONSTRAINT "ArtikelKesehatan_symptomId_fkey" FOREIGN KEY ("symptomId") REFERENCES "Symptom"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ArtikelKesehatan" ADD CONSTRAINT "ArtikelKesehatan_preventionId_fkey" FOREIGN KEY ("preventionId") REFERENCES "Prevention"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ArtikelKesehatan" ADD CONSTRAINT "ArtikelKesehatan_firstAidId_fkey" FOREIGN KEY ("firstAidId") REFERENCES "FirstAid"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ArtikelKesehatan" ADD CONSTRAINT "ArtikelKesehatan_mythVsFactId_fkey" FOREIGN KEY ("mythVsFactId") REFERENCES "MythVsFact"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ArtikelKesehatan" ADD CONSTRAINT "ArtikelKesehatan_doctorSignId_fkey" FOREIGN KEY ("doctorSignId") REFERENCES "DoctorSign"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View File

@@ -650,8 +650,7 @@ model PendaftaranJadwalKegiatan {
// ========================================= PERSENTASE KELAHIRAN & KEMATIAN ========================================= //
model DataKematian_Kelahiran {
id Int @id @default(autoincrement())
uuid String @unique @default(cuid())
id String @unique @default(cuid())
tahun String
kematianKasar String
kematianBayi String
@@ -664,8 +663,7 @@ model DataKematian_Kelahiran {
// ========================================= GRAFIK KEPUASAN ========================================= //
model GrafikKepuasan {
id Int @id @default(autoincrement())
uuid String @unique @default(cuid())
id String @unique @default(cuid())
label String
jumlah String
createdAt DateTime @default(now())
@@ -708,13 +706,13 @@ model Introduction {
}
model Symptom {
id String @id @default(cuid())
title String
content String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime @default(now())
isActive Boolean @default(true)
id String @id @default(cuid())
title String
content String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
deletedAt DateTime @default(now())
isActive Boolean @default(true)
ArtikelKesehatan ArtikelKesehatan[]
}

View File

@@ -39,15 +39,15 @@ const grafikkepuasan = proxy({
const res = await ApiFetch.api.kesehatan.grafikkepuasan["create"].post(grafikkepuasan.create.form);
if (res.status === 200) {
const uuid = res.data?.data?.uuid;
if (uuid) {
const id = res.data?.data?.id;
if (id) {
toast.success("Success create");
grafikkepuasan.create.form = {
label: "",
jumlah: "",
};
grafikkepuasan.findMany.load();
return uuid;
return id;
}
}
toast.error("failed create");
@@ -77,9 +77,9 @@ const grafikkepuasan = proxy({
data: null as Prisma.GrafikKepuasanGetPayload<{
omit: { isActive: true }
}> | null,
async load(uuid: string) {
async load(id: string) {
try {
const res = await fetch(`/api/kesehatan/grafikkepuasan/${uuid}`);
const res = await fetch(`/api/kesehatan/grafikkepuasan/${id}`);
if (res.ok) {
const data = await res.json();
grafikkepuasan.findUnique.data = data.data ?? null;
@@ -94,14 +94,14 @@ const grafikkepuasan = proxy({
},
},
update: {
uuid: "",
id: "",
form: {...defaultForm},
loading: false,
async byId() {
},
async submit() {
const uuid = this.uuid;
if (!uuid) {
const id = this.id;
if (!id) {
toast.warn("ID tidak valid");
return null;
}
@@ -114,7 +114,7 @@ const grafikkepuasan = proxy({
}
try {
this.loading = true;
const response = await fetch(`/api/kesehatan/grafikkepuasan/${uuid}`, {
const response = await fetch(`/api/kesehatan/grafikkepuasan/${id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
@@ -143,14 +143,14 @@ const grafikkepuasan = proxy({
},
delete: {
loading: false,
async byId(uuid: string) {
if (!uuid) {
async byId(id: string) {
if (!id) {
return toast.warn("ID tidak valid");
}
try {
grafikkepuasan.delete.loading = true;
const response = await fetch(`/api/kesehatan/grafikkepuasan/del/${uuid}`, {
const response = await fetch(`/api/kesehatan/grafikkepuasan/del/${id}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",

View File

@@ -45,12 +45,12 @@ const persentasekelahiran = proxy({
);
if (res.status === 200) {
const uuid = res.data?.data?.uuid;
if (uuid) {
const id = res.data?.data?.id;
if (id) {
toast.success("Success create");
persentasekelahiran.create.form = { ...defaultForm };
persentasekelahiran.findMany.load();
return uuid;
return id;
}
}
toast.error("failed create");
@@ -80,9 +80,9 @@ const persentasekelahiran = proxy({
data: null as Prisma.DataKematian_KelahiranGetPayload<{
omit: { isActive: true };
}> | null,
async load(uuid: string) {
async load(id: string) {
try {
const res = await fetch(`/api/kesehatan/persentasekelahiran/${uuid}`);
const res = await fetch(`/api/kesehatan/persentasekelahiran/${id}`);
if (res.ok) {
const data = await res.json();
persentasekelahiran.findUnique.data = data.data ?? null;
@@ -98,13 +98,13 @@ const persentasekelahiran = proxy({
},
update: {
uuid: "",
id: "",
form: { ...defaultForm },
loading: false,
async submit() {
const uuid = this.uuid;
if (!uuid) {
toast.warn("UUID tidak valid");
const id = this.id;
if (!id) {
toast.warn("ID tidak valid");
return null;
}
@@ -126,7 +126,7 @@ update: {
try {
this.loading = true;
const res = await fetch(`/api/kesehatan/persentasekelahiran/${uuid}`, {
const res = await fetch(`/api/kesehatan/persentasekelahiran/${id}`, {
method: "PUT",
headers: {
"Content-Type": "application/json",
@@ -156,13 +156,13 @@ update: {
delete: {
loading: false,
async byId(uuid: string) {
if (!uuid) return toast.warn("UUID tidak valid");
async byId(id: string) {
if (!id) return toast.warn("ID tidak valid");
try {
persentasekelahiran.delete.loading = true;
const response = await fetch(`/api/kesehatan/persentasekelahiran/del/${uuid}`, {
const response = await fetch(`/api/kesehatan/persentasekelahiran/del/${id}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
@@ -177,7 +177,7 @@ update: {
} else {
toast.error(result?.message || "Gagal menghapus persentase kelahiran");
}
} catch (error) {
} catch (error) {
console.error("Gagal delete:", error);
toast.error("Terjadi kesalahan saat menghapus persentase kelahiran");
} finally {

View File

@@ -11,15 +11,15 @@ import { useProxy } from 'valtio/utils';
function EditGrafikHasilKepuasan() {
const router = useRouter()
const params = useParams() as { uuid: string }
const params = useParams() as { id: string }
const stateGrafikKepuasan = useProxy(grafikkepuasan)
const uuid = params.uuid
const id = params.id
// Load data saat komponen mount
useEffect(() => {
if (uuid) {
stateGrafikKepuasan.findUnique.load(uuid).then(() => {
if (id) {
stateGrafikKepuasan.findUnique.load(id).then(() => {
const data = stateGrafikKepuasan.findUnique.data
if (data) {
stateGrafikKepuasan.update.form = {
@@ -29,11 +29,11 @@ function EditGrafikHasilKepuasan() {
}
})
}
}, [uuid])
}, [id])
const handleSubmit = async () => {
// Set the ID before submitting
stateGrafikKepuasan.update.uuid = uuid;
stateGrafikKepuasan.update.id = id;
await stateGrafikKepuasan.update.submit();
router.push('/admin/kesehatan/data-kesehatan-warga/grafik_hasil_kepuasan')
}

View File

@@ -45,7 +45,7 @@ function GrafikHasilKepuasanMasyarakat() {
setMounted(true);
if (stateGrafikKepuasan.findMany.data) {
setChartData(stateGrafikKepuasan.findMany.data.map((item) => ({
id: item.uuid,
id: item.id,
label: item.label,
jumlah: Number(item.jumlah),
})));
@@ -82,11 +82,11 @@ function GrafikHasilKepuasanMasyarakat() {
</TableThead>
<TableTbody>
{stateGrafikKepuasan.findMany.data?.map((item) => (
<TableTr key={item.uuid}>
<TableTr key={item.id}>
<TableTd>{item.label}</TableTd>
<TableTd>{item.jumlah}</TableTd>
<TableTd>
<Button color='green' onClick={() => router.push(`/admin/kesehatan/data-kesehatan-warga/grafik_hasil_kepuasan/${item.uuid}`)}>
<Button color='green' onClick={() => router.push(`/admin/kesehatan/data-kesehatan-warga/grafik_hasil_kepuasan/${item.id}`)}>
<IconEdit size={20} />
</Button>
</TableTd>
@@ -95,7 +95,7 @@ function GrafikHasilKepuasanMasyarakat() {
color='red'
disabled={stateGrafikKepuasan.delete.loading}
onClick={() => {
setSelectedId(item.uuid)
setSelectedId(item.id)
setModalHapus(true)
}}>
<IconTrash size={20} />

View File

@@ -12,16 +12,16 @@ import { useProxy } from 'valtio/utils';
function EditPersentaseDataKelahiranKematian() {
const router = useRouter()
const params = useParams() as { uuid: string }
const params = useParams() as { id: string }
const statePresentase = useProxy(persentasekelahiran)
const id = params.uuid
const id = params.id
// Load data saat komponen mount
// Di file page.tsx, ubah useEffect-nya menjadi:
useEffect(() => {
if (!id) return;
statePresentase.update.uuid = id;
statePresentase.update.id = id;
statePresentase.findUnique.load(id)
.then(() => {
const data = statePresentase.findUnique.data;
@@ -43,7 +43,7 @@ useEffect(() => {
// Di handleSubmit, ubah menjadi:
const handleSubmit = async () => {
try {
statePresentase.update.uuid = id;
statePresentase.update.id = id;
await statePresentase.update.submit();
toast.success('Data berhasil diperbarui');
router.push('/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian');

View File

@@ -13,7 +13,7 @@ import { ModalKonfirmasiHapus } from '../../../_com/modalKonfirmasiHapus';
function PersentaseDataKelahiranKematian() {
type PDKMGrafik = {
uuid: string;
id: string;
tahun: string;
kematianKasar: number;
kematianBayi: number;
@@ -47,7 +47,7 @@ function PersentaseDataKelahiranKematian() {
setMounted(true);
if (statePersentase.findMany.data) {
setChartData(statePersentase.findMany.data.map((item) => ({
uuid: item.uuid,
id: item.id,
tahun: item.tahun,
kematianKasar: Number(item.kematianKasar),
kematianBayi: Number(item.kematianBayi),
@@ -88,13 +88,13 @@ function PersentaseDataKelahiranKematian() {
</TableThead>
<TableTbody>
{statePersentase.findMany.data?.map((item) => (
<TableTr key={item.uuid}>
<TableTr key={item.id}>
<TableTd>{item.tahun}</TableTd>
<TableTd>{item.kematianKasar}</TableTd>
<TableTd>{item.kematianBayi}</TableTd>
<TableTd>{item.kelahiranKasar}</TableTd>
<TableTd>
<Button color='green' onClick={() => router.push(`/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian/${item.uuid}`)}>
<Button color='green' onClick={() => router.push(`/admin/kesehatan/data-kesehatan-warga/persentase_data_kelahiran_kematian/${item.id}`)}>
<IconEdit size={20} />
</Button>
</TableTd>
@@ -103,7 +103,7 @@ function PersentaseDataKelahiranKematian() {
color='red'
disabled={statePersentase.delete.loading}
onClick={() => {
setSelectedId(item.uuid)
setSelectedId(item.id)
setModalHapus(true)
}}>
<IconTrash size={20} />

View File

@@ -17,7 +17,7 @@ export default async function grafikKepuasanCreate(context: Context) {
jumlah: body.jumlah,
},
select: {
uuid: true,
id: true,
label: true,
jumlah: true,
}

View File

@@ -2,35 +2,35 @@ import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function grafikKepuasanDelete(context: Context) {
const uuid = context.params?.uuid;
if (!uuid) {
return {
success: false,
message: "ID tidak ditemukan"
}
}
const existing = await prisma.grafikKepuasan.findUnique({
where: {
uuid: uuid,
},
})
if (!existing) {
return {
success: false,
message: "Data tidak ditemukan",
}
}
const deleted = await prisma.grafikKepuasan.delete({
where: { uuid },
})
const id = context.params?.id;
if (!id) {
return {
success: true,
message: "Data berhasil dihapus",
data: deleted,
}
}
success: false,
message: "ID tidak ditemukan",
};
}
const existing = await prisma.grafikKepuasan.findUnique({
where: {
id: id,
},
});
if (!existing) {
return {
success: false,
message: "Data tidak ditemukan",
};
}
const deleted = await prisma.grafikKepuasan.delete({
where: { id },
});
return {
success: true,
message: "Data berhasil dihapus",
data: deleted,
};
}

View File

@@ -3,9 +3,9 @@ import prisma from "@/lib/prisma";
export default async function grafikKepuasanFindUnique(request: Request) {
const url = new URL(request.url);
const pathSegments = url.pathname.split('/');
const uuid = pathSegments[pathSegments.length - 1];
const id = pathSegments[pathSegments.length - 1];
if (!uuid) {
if (!id) {
return Response.json({
success: false,
message: 'ID tidak boleh kosong',
@@ -13,7 +13,7 @@ export default async function grafikKepuasanFindUnique(request: Request) {
}
try {
if (typeof uuid !== 'string') {
if (typeof id !== 'string') {
return Response.json({
success: false,
message: "ID tidak valid",
@@ -21,7 +21,7 @@ export default async function grafikKepuasanFindUnique(request: Request) {
}
const data = await prisma.grafikKepuasan.findUnique({
where: { uuid },
where: { id },
});
if (!data) {

View File

@@ -9,7 +9,7 @@ const GrafikKepuasan = new Elysia({
prefix: "/grafikkepuasan",
tags: ["Data Kesehatan/Grafik Kepuasan"]
})
.get("/:uuid", async (context) => {
.get("/:id", async (context) => {
const response = await grafikKepuasanFindUnique(new Request(context.request));
return response;
})
@@ -20,18 +20,18 @@ const GrafikKepuasan = new Elysia({
jumlah: t.String(),
}),
})
.put("/:uuid", grafikKepuasanUpdate, {
.put("/:id", grafikKepuasanUpdate, {
params: t.Object({
uuid: t.String(),
id: t.String(),
}),
body: t.Object({
label: t.String(),
jumlah: t.String(),
}),
})
.delete("/del/:uuid", grafikKepuasanDelete, {
.delete("/del/:id", grafikKepuasanDelete, {
params: t.Object({
uuid: t.String(),
id: t.String(),
}),
})
export default GrafikKepuasan

View File

@@ -2,9 +2,9 @@ import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function grafikKepuasanUpdate(context: Context) {
const uuid = context.params?.uuid;
const id = context.params?.id;
if (!uuid) {
if (!id) {
return {
success: false,
message: "ID tidak ditemukan"
@@ -18,7 +18,7 @@ export default async function grafikKepuasanUpdate(context: Context) {
const existing = await prisma.grafikKepuasan.findUnique({
where: {
uuid: uuid,
id: id,
},
})
@@ -30,7 +30,7 @@ export default async function grafikKepuasanUpdate(context: Context) {
}
const updated = await prisma.grafikKepuasan.update({
where: { uuid },
where: { id },
data: {
label,
jumlah,

View File

@@ -22,7 +22,7 @@ export default async function persentaseKelahiranKematianCreate(context: Context
kelahiranKasar: body.kelahiranKasar,
},
select: {
uuid: true,
id: true,
tahun: true,
kematianKasar: true,
kematianBayi: true,

View File

@@ -2,9 +2,9 @@ import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function persentaseKelahiranKematianDelete(context: Context) {
const uuid = context.params?.uuid;
const id = context.params?.id;
if (!uuid) {
if (!id) {
return {
success: false,
message: "ID tidak ditemukan",
@@ -13,7 +13,7 @@ export default async function persentaseKelahiranKematianDelete(context: Context
const existing = await prisma.dataKematian_Kelahiran.findUnique({
where: {
uuid: uuid,
id: id,
},
})
@@ -25,7 +25,7 @@ export default async function persentaseKelahiranKematianDelete(context: Context
}
const deleted = await prisma.dataKematian_Kelahiran.delete({
where: { uuid },
where: { id },
})
return {

View File

@@ -3,9 +3,9 @@ import prisma from "@/lib/prisma";
export default async function persentaseKelahiranKematianFindUnique(request: Request) {
const url = new URL(request.url);
const pathSegments = url.pathname.split('/');
const uuid = pathSegments[pathSegments.length - 1];
const id = pathSegments[pathSegments.length - 1];
if (!uuid) {
if (!id) {
return Response.json({
success: false,
message: "ID tidak boleh kosong",
@@ -13,7 +13,7 @@ export default async function persentaseKelahiranKematianFindUnique(request: Req
}
try {
if (typeof uuid !== 'string') {
if (typeof id !== 'string') {
return Response.json({
success: false,
message: "ID tidak valid",
@@ -21,7 +21,7 @@ export default async function persentaseKelahiranKematianFindUnique(request: Req
}
const data = await prisma.dataKematian_Kelahiran.findUnique({
where: { uuid },
where: { id },
});
if (!data) {

View File

@@ -9,7 +9,7 @@ const PersentaseKelahiranKematian = new Elysia({
prefix: "/persentasekelahiran",
tags: ["Data Kesehatan/Persentase Kelahiran Kematian"],
})
.get("/:uuid", async (context) => {
.get("/:id", async (context) => {
const response = await persentaseKelahiranKematianFindUnique(new Request(context.request))
return response
})
@@ -22,9 +22,9 @@ const PersentaseKelahiranKematian = new Elysia({
kelahiranKasar: t.String(),
}),
})
.put("/:uuid", persentaseKelahiranKematianUpdate, {
.put("/:id", persentaseKelahiranKematianUpdate, {
params: t.Object({
uuid: t.String(),
id: t.String(),
}),
body: t.Object({
tahun: t.String(),
@@ -33,9 +33,9 @@ const PersentaseKelahiranKematian = new Elysia({
kelahiranKasar: t.String(),
}),
})
.delete("/del/:uuid", persentaseKelahiranKematianDelete, {
.delete("/del/:id", persentaseKelahiranKematianDelete, {
params: t.Object({
uuid: t.String(),
id: t.String(),
}),
})
export default PersentaseKelahiranKematian;

View File

@@ -2,9 +2,9 @@ import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function persentaseKelahiranKematianUpdate(context: Context) {
const uuid = context.params?.uuid;
const id = context.params?.id;
if (!uuid) {
if (!id) {
return {
success: false,
message: "ID tidak ditemukan",
@@ -20,7 +20,7 @@ export default async function persentaseKelahiranKematianUpdate(context: Context
const existing = await prisma.dataKematian_Kelahiran.findUnique({
where: {
uuid: uuid,
id: id,
},
})
@@ -32,7 +32,7 @@ export default async function persentaseKelahiranKematianUpdate(context: Context
}
const updated = await prisma.dataKematian_Kelahiran.update({
where: { uuid },
where: { id },
data: {
tahun,
kematianKasar,