Files
desa-darmasaba/src/app/api/[[...slugs]]/_lib/kependudukan/migrasi-penduduk/updt.ts
nico 50801e5c8a fix(kependudukan): remove jenisKelamin field and align MigrasiPenduduk with database schema
- Remove jenisKelamin field from API, state, and UI components
- Fix MigrasiPenduduk API to use null instead of undefined for optional fields
- Update create/edit forms to properly handle asal/tujuan fields based on jenis
- Fix DatePickerInput type handling with valueFormat prop
- Update list page to display asal or tujuan conditionally
- Add proper select statements in API responses
- Fix TypeScript type errors in migrasi-penduduk module

Closes: Schema mismatch causing errors when inputting migrasi penduduk data

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-04-13 15:53:58 +08:00

62 lines
1.4 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 : null,
tujuan: jenis === 'KELUAR' ? asalTujuan : null,
alasan,
},
select: {
id: true,
jenis: true,
nama: true,
tanggal: true,
asal: true,
tujuan: true,
alasan: true,
},
})
return {
success: true,
message: "Data berhasil diupdate",
data: updated,
}
}