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
|
Line | |
---|
1 | import { NextRequest, NextResponse } from 'next/server';
|
---|
2 | import { customerSchema } from 'src/schemas';
|
---|
3 | import prisma from 'src/lib/prisma';
|
---|
4 | import { authenticateRequest } from 'src/lib/auth-middleware';
|
---|
5 |
|
---|
6 | export 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 |
|
---|
16 | const customer = await prisma.client.update({
|
---|
17 | where: { id: params.id },
|
---|
18 | data: {
|
---|
19 | ...validatedData,
|
---|
20 | bankAccounts: undefined,
|
---|
21 | },
|
---|
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.