Files
desa-darmasaba/src/app/api/[[...slugs]]/_lib/kependudukan/migrasi-penduduk/updt.ts
nico 80186bf493 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>
2026-04-13 15:00:33 +08:00

53 lines
1.2 KiB
TypeScript

import prisma from "@/lib/prisma";
import { Context } from "elysia";
export default async function migrasiPendudukUpdate(context: Context) {
const id = context.params?.id;
if (!id) {
return {
success: false,
message: "ID tidak ditemukan",
}
}
const {jenis, nama, tanggal, asalTujuan, alasan} = context.body as {
jenis: string;
nama: string;
tanggal: string;
asalTujuan: string;
alasan?: string;
}
const existing = await prisma.migrasiPenduduk.findUnique({
where: {
id: id,
},
})
if (!existing) {
return {
success: false,
message: "Data tidak ditemukan",
}
}
const updated = await prisma.migrasiPenduduk.update({
where: { id },
data: {
jenis: jenis as 'MASUK' | 'KELUAR',
nama,
tanggal: new Date(tanggal),
asal: jenis === 'MASUK' ? asalTujuan : undefined,
tujuan: jenis === 'KELUAR' ? asalTujuan : undefined,
alasan,
},
})
return {
success: true,
message: "Data berhasil diupdate",
data: updated,
}
}