source: src/app/api/customers/[id]/route.ts@ 057453c

main
Last change on this file since 057453c was 057453c, checked in by Naum Shapkarovski <naumshapkarovski@…>, 6 weeks ago

feat: implement employees

  • Property mode set to 100644
File size: 887 bytes
RevLine 
[5d6f37a]1import { NextRequest, NextResponse } from 'next/server';
[057453c]2import { customerSchema } from 'src/schemas';
[5d6f37a]3import prisma from 'src/lib/prisma';
4import { authenticateRequest } from 'src/lib/auth-middleware';
5
6export async function PATCH(request: NextRequest, { params }: { params: { id: string } }) {
7 try {
8 const userId = await authenticateRequest(request);
9 if (!userId) {
10 return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
11 }
12
13 const body = await request.json();
14 const validatedData = customerSchema.partial().parse(body);
15
[057453c]16 const customer = await prisma.client.update({
17 where: { id: params.id },
18 data: {
19 ...validatedData,
20 bankAccounts: undefined,
21 },
[5d6f37a]22 });
23
24 return NextResponse.json(customer);
25 } catch (error) {
26 return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
27 }
28}
Note: See TracBrowser for help on using the repository browser.