Test AUTH - 30 Jul
This commit is contained in:
35
src/app/api/[[...slugs]]/_lib/user/updt.ts
Normal file
35
src/app/api/[[...slugs]]/_lib/user/updt.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
// /api/user/update.ts
|
||||
import prisma from '@/lib/prisma';
|
||||
import { Context } from 'elysia';
|
||||
|
||||
export default async function userUpdate(context: Context) {
|
||||
const { id } = context.params as { id: string };
|
||||
const body = await context.body as {
|
||||
nama?: string;
|
||||
email?: string;
|
||||
password?: string;
|
||||
roleId?: string;
|
||||
isActive?: boolean;
|
||||
};
|
||||
|
||||
try {
|
||||
const updated = await prisma.user.update({
|
||||
where: { id },
|
||||
data: {
|
||||
...body,
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
success: true,
|
||||
message: 'User berhasil diupdate',
|
||||
data: updated,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return {
|
||||
success: false,
|
||||
message: 'Gagal mengupdate user',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user