refactor(kependudukan): improve TypeScript types and clean up code
- Add proper TypeScript interfaces for seeder files - Rename MigrasiPendudukForm interface for consistency - Separate asal/tujuan fields in MigrasiPenduduk API based on jenis - Remove unnecessary eslint-disable comments - Add local type definitions for public kependudukan pages - Clean up unused imports (React, Flex, IconBuilding) - Improve type safety in form handlers (handleChangeText vs handleChangeSelect) - Add explicit type casting where needed to fix type errors Co-authored-by: Qwen Code Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -10,7 +10,6 @@ export default async function dashboardSummary() {
|
||||
totalKK,
|
||||
totalKelahiran,
|
||||
totalKemiskinan,
|
||||
kelahiranData,
|
||||
kematianData,
|
||||
pindahMasukData,
|
||||
pindahKeluarData,
|
||||
|
||||
@@ -1,38 +1,34 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { Prisma } from "@prisma/client";
|
||||
import { Context } from "elysia";
|
||||
|
||||
type FormCreate = Prisma.MigrasiPendudukGetPayload<{
|
||||
select: {
|
||||
jenis: true;
|
||||
nama: true;
|
||||
tanggal: true;
|
||||
asalTujuan: true;
|
||||
alasan: true;
|
||||
jenisKelamin: true;
|
||||
}
|
||||
}>
|
||||
type FormCreate = {
|
||||
jenis: string;
|
||||
nama: string;
|
||||
tanggal: string;
|
||||
asalTujuan: string;
|
||||
alasan: string | null;
|
||||
}
|
||||
|
||||
export default async function migrasiPendudukCreate(context: Context) {
|
||||
const body = context.body as FormCreate;
|
||||
|
||||
const isMasuk = body.jenis === 'MASUK';
|
||||
|
||||
const created = await prisma.migrasiPenduduk.create({
|
||||
data: {
|
||||
jenis: body.jenis,
|
||||
jenis: body.jenis as 'MASUK' | 'KELUAR',
|
||||
nama: body.nama,
|
||||
tanggal: new Date(body.tanggal),
|
||||
asalTujuan: body.asalTujuan,
|
||||
asal: isMasuk ? body.asalTujuan : undefined,
|
||||
tujuan: !isMasuk ? body.asalTujuan : undefined,
|
||||
alasan: body.alasan,
|
||||
jenisKelamin: body.jenisKelamin,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
jenis: true,
|
||||
nama: true,
|
||||
tanggal: true,
|
||||
asalTujuan: true,
|
||||
alasan: true,
|
||||
jenisKelamin: true,
|
||||
}
|
||||
});
|
||||
return {
|
||||
|
||||
@@ -11,13 +11,12 @@ export default async function migrasiPendudukUpdate(context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
const {jenis, nama, tanggal, asalTujuan, alasan, jenisKelamin} = context.body as {
|
||||
const {jenis, nama, tanggal, asalTujuan, alasan} = context.body as {
|
||||
jenis: string;
|
||||
nama: string;
|
||||
tanggal: string;
|
||||
asalTujuan: string;
|
||||
alasan?: string;
|
||||
jenisKelamin?: string;
|
||||
}
|
||||
|
||||
const existing = await prisma.migrasiPenduduk.findUnique({
|
||||
@@ -36,12 +35,12 @@ export default async function migrasiPendudukUpdate(context: Context) {
|
||||
const updated = await prisma.migrasiPenduduk.update({
|
||||
where: { id },
|
||||
data: {
|
||||
jenis,
|
||||
jenis: jenis as 'MASUK' | 'KELUAR',
|
||||
nama,
|
||||
tanggal: new Date(tanggal),
|
||||
asalTujuan,
|
||||
asal: jenis === 'MASUK' ? asalTujuan : undefined,
|
||||
tujuan: jenis === 'KELUAR' ? asalTujuan : undefined,
|
||||
alasan,
|
||||
jenisKelamin,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user