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

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

chore

  • Property mode set to 100644
File size: 990 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 {
[299af01]8 const auth = await authenticateRequest(request);
9 if (!auth || auth instanceof NextResponse) {
[5d6f37a]10 return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
11 }
12
[299af01]13 const { userId, tenantId } = auth;
14
[5d6f37a]15 const body = await request.json();
16 const validatedData = customerSchema.partial().parse(body);
17
[299af01]18 console.log('validatedData', validatedData);
19
[057453c]20 const customer = await prisma.client.update({
21 where: { id: params.id },
22 data: {
23 ...validatedData,
[299af01]24 tenantId,
[057453c]25 },
[5d6f37a]26 });
27
28 return NextResponse.json(customer);
29 } catch (error) {
30 return NextResponse.json({ error: 'Internal Server Error' }, { status: 500 });
31 }
32}
Note: See TracBrowser for help on using the repository browser.