Skip to content

Commit 3781122

Browse files
committed
up
1 parent dcacc2a commit 3781122

10 files changed

Lines changed: 62 additions & 65 deletions

File tree

src/app/(dashboard)/products/[id]/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ async function getProduct(id: string): Promise<Product | null> {
197197
// Transform Prisma result to match Product interface
198198
return {
199199
...product,
200-
images: JSON.parse(product.images) as string[],
201-
metaKeywords: product.metaKeywords ? (JSON.parse(product.metaKeywords) as string[]) : undefined,
200+
images: JSON.parse(product.images as string) as string[],
201+
metaKeywords: product.metaKeywords ? (JSON.parse(product.metaKeywords as string) as string[]) : undefined,
202202
variants: product.variants.map(v => ({
203203
...v,
204-
options: JSON.parse(v.options) as Record<string, string>,
204+
options: JSON.parse(v.options as string) as Record<string, string>,
205205
})),
206206
createdAt: product.createdAt.toISOString(),
207207
updatedAt: product.updatedAt.toISOString(),

src/app/api/orders/__tests__/route.test.ts

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('GET /api/orders', () => {
149149
vi.mocked(getServerSession).mockResolvedValue(null);
150150

151151
const request = new NextRequest('http://localhost:3000/api/orders');
152-
const response = await GET(request);
152+
const response = await GET(request, {} as any);
153153
const data = await response.json();
154154

155155
expect(response.status).toBe(401);
@@ -161,7 +161,7 @@ describe('GET /api/orders', () => {
161161
vi.mocked(getServerSession).mockResolvedValue({ user: null } as any);
162162

163163
const request = new NextRequest('http://localhost:3000/api/orders');
164-
const response = await GET(request);
164+
const response = await GET(request, {} as any);
165165
const data = await response.json();
166166

167167
expect(response.status).toBe(401);
@@ -179,7 +179,7 @@ describe('GET /api/orders', () => {
179179
} as any);
180180

181181
const request = new NextRequest('http://localhost:3000/api/orders');
182-
const response = await GET(request);
182+
const response = await GET(request, {} as any);
183183
const data = await response.json();
184184

185185
expect(response.status).toBe(403);
@@ -197,7 +197,7 @@ describe('GET /api/orders', () => {
197197
} as any);
198198

199199
const request = new NextRequest('http://localhost:3000/api/orders');
200-
const response = await GET(request);
200+
const response = await GET(request, {} as any);
201201
const data = await response.json();
202202

203203
expect(response.status).toBe(403);
@@ -220,7 +220,7 @@ describe('GET /api/orders', () => {
220220
});
221221

222222
const request = new NextRequest('http://localhost:3000/api/orders');
223-
const response = await GET(request);
223+
const response = await GET(request, {} as any);
224224
const data = await response.json();
225225

226226
expect(response.status).toBe(200);
@@ -235,7 +235,7 @@ describe('GET /api/orders', () => {
235235
});
236236

237237
const request = new NextRequest('http://localhost:3000/api/orders');
238-
const response = await GET(request);
238+
const response = await GET(request, {} as any);
239239
const data = await response.json();
240240

241241
expect(response.status).toBe(200);
@@ -256,7 +256,7 @@ describe('GET /api/orders', () => {
256256
});
257257

258258
const request = new NextRequest('http://localhost:3000/api/orders');
259-
const response = await GET(request);
259+
const response = await GET(request, {} as any);
260260
const data = await response.json();
261261

262262
expect(response.status).toBe(200);
@@ -275,7 +275,7 @@ describe('GET /api/orders', () => {
275275

276276
it('should use default pagination if not specified', async () => {
277277
const request = new NextRequest('http://localhost:3000/api/orders');
278-
await GET(request);
278+
await GET(request, {} as any);
279279

280280
expect(orderService.listOrders).toHaveBeenCalledWith(
281281
expect.objectContaining({
@@ -286,10 +286,8 @@ describe('GET /api/orders', () => {
286286
});
287287

288288
it('should accept custom pagination parameters', async () => {
289-
const request = new NextRequest(
290-
'http://localhost:3000/api/orders?page=2&perPage=50'
291-
);
292-
await GET(request);
289+
const request = new NextRequest('http://localhost:3000/api/orders?page=2&perPage=50', {});
290+
await GET(request, {} as any);
293291

294292
expect(orderService.listOrders).toHaveBeenCalledWith(
295293
expect.objectContaining({
@@ -300,10 +298,8 @@ describe('GET /api/orders', () => {
300298
});
301299

302300
it('should enforce max perPage limit of 100', async () => {
303-
const request = new NextRequest(
304-
'http://localhost:3000/api/orders?perPage=150'
305-
);
306-
const response = await GET(request);
301+
const request = new NextRequest('http://localhost:3000/api/orders?perPage=150', {});
302+
const response = await GET(request, {} as any);
307303
const data = await response.json();
308304

309305
expect(response.status).toBe(400);
@@ -315,7 +311,7 @@ describe('GET /api/orders', () => {
315311
const request = new NextRequest(
316312
`http://localhost:3000/api/orders?status=${OrderStatus.PENDING}`
317313
);
318-
await GET(request);
314+
await GET(request, {} as any);
319315

320316
expect(orderService.listOrders).toHaveBeenCalledWith(
321317
expect.objectContaining({
@@ -325,10 +321,8 @@ describe('GET /api/orders', () => {
325321
});
326322

327323
it('should accept search query', async () => {
328-
const request = new NextRequest(
329-
'http://localhost:3000/api/orders?search=ORD-001'
330-
);
331-
await GET(request);
324+
const request = new NextRequest('http://localhost:3000/api/orders?search=ORD-001', {});
325+
await GET(request, {} as any);
332326

333327
expect(orderService.listOrders).toHaveBeenCalledWith(
334328
expect.objectContaining({
@@ -343,7 +337,7 @@ describe('GET /api/orders', () => {
343337
const request = new NextRequest(
344338
`http://localhost:3000/api/orders?dateFrom=${dateFrom}&dateTo=${dateTo}`
345339
);
346-
await GET(request);
340+
await GET(request, {} as any);
347341

348342
expect(orderService.listOrders).toHaveBeenCalledWith(
349343
expect.objectContaining({
@@ -354,10 +348,8 @@ describe('GET /api/orders', () => {
354348
});
355349

356350
it('should accept custom sorting', async () => {
357-
const request = new NextRequest(
358-
'http://localhost:3000/api/orders?sortBy=totalAmount&sortOrder=asc'
359-
);
360-
await GET(request);
351+
const request = new NextRequest('http://localhost:3000/api/orders?sortBy=totalAmount&sortOrder=asc', {});
352+
await GET(request, {} as any);
361353

362354
expect(orderService.listOrders).toHaveBeenCalledWith(
363355
expect.objectContaining({
@@ -369,7 +361,7 @@ describe('GET /api/orders', () => {
369361

370362
it('should use default sorting if not specified', async () => {
371363
const request = new NextRequest('http://localhost:3000/api/orders');
372-
await GET(request);
364+
await GET(request, {} as any);
373365

374366
expect(orderService.listOrders).toHaveBeenCalledWith(
375367
expect.objectContaining({
@@ -380,10 +372,8 @@ describe('GET /api/orders', () => {
380372
});
381373

382374
it('should return 400 for invalid sortBy value', async () => {
383-
const request = new NextRequest(
384-
'http://localhost:3000/api/orders?sortBy=invalidField'
385-
);
386-
const response = await GET(request);
375+
const request = new NextRequest('http://localhost:3000/api/orders?sortBy=invalidField', {});
376+
const response = await GET(request, {} as any);
387377
const data = await response.json();
388378

389379
expect(response.status).toBe(400);
@@ -401,10 +391,8 @@ describe('GET /api/orders', () => {
401391
const mockCSV = 'Order Number,Customer Name,Total\nORD-001,John Doe,100.00';
402392
vi.mocked(orderService.exportOrdersToCSV).mockResolvedValue(mockCSV);
403393

404-
const request = new NextRequest(
405-
'http://localhost:3000/api/orders?export=csv'
406-
);
407-
const response = await GET(request);
394+
const request = new NextRequest('http://localhost:3000/api/orders?export=csv', {});
395+
const response = await GET(request, {} as any);
408396
const csvData = await response.text();
409397

410398
expect(response.status).toBe(200);
@@ -423,7 +411,7 @@ describe('GET /api/orders', () => {
423411
const request = new NextRequest(
424412
`http://localhost:3000/api/orders?export=csv&status=${OrderStatus.PENDING}&search=ORD`
425413
);
426-
await GET(request);
414+
await GET(request, {} as any);
427415

428416
expect(orderService.exportOrdersToCSV).toHaveBeenCalledWith(
429417
expect.objectContaining({
@@ -437,10 +425,8 @@ describe('GET /api/orders', () => {
437425
const mockCSV = 'Order Number,Customer Name,Total\nORD-001,John Doe,100.00';
438426
vi.mocked(orderService.exportOrdersToCSV).mockResolvedValue(mockCSV);
439427

440-
const request = new NextRequest(
441-
'http://localhost:3000/api/orders?export=csv'
442-
);
443-
await GET(request);
428+
const request = new NextRequest('http://localhost:3000/api/orders?export=csv', {});
429+
await GET(request, {} as any);
444430

445431
expect(orderService.exportOrdersToCSV).toHaveBeenCalled();
446432
expect(orderService.listOrders).not.toHaveBeenCalled();
@@ -458,7 +444,7 @@ describe('GET /api/orders', () => {
458444

459445
it('should return orders with success response', async () => {
460446
const request = new NextRequest('http://localhost:3000/api/orders');
461-
const response = await GET(request);
447+
const response = await GET(request, {} as any);
462448
const data = await response.json();
463449

464450
expect(response.status).toBe(200);
@@ -485,7 +471,7 @@ describe('GET /api/orders', () => {
485471
});
486472

487473
const request = new NextRequest('http://localhost:3000/api/orders');
488-
const response = await GET(request);
474+
const response = await GET(request, {} as any);
489475
const data = await response.json();
490476

491477
expect(response.status).toBe(200);
@@ -505,7 +491,7 @@ describe('GET /api/orders', () => {
505491
const request = new NextRequest(
506492
'http://localhost:3000/api/orders?page=0' // Invalid: page must be positive
507493
);
508-
const response = await GET(request);
494+
const response = await GET(request, {} as any);
509495
const data = await response.json();
510496

511497
expect(response.status).toBe(400);
@@ -520,7 +506,7 @@ describe('GET /api/orders', () => {
520506
);
521507

522508
const request = new NextRequest('http://localhost:3000/api/orders');
523-
const response = await GET(request);
509+
const response = await GET(request, {} as any);
524510
const data = await response.json();
525511

526512
expect(response.status).toBe(500);
@@ -532,7 +518,7 @@ describe('GET /api/orders', () => {
532518
vi.mocked(orderService.listOrders).mockRejectedValue('Unknown error');
533519

534520
const request = new NextRequest('http://localhost:3000/api/orders');
535-
const response = await GET(request);
521+
const response = await GET(request, {} as any);
536522
const data = await response.json();
537523

538524
expect(response.status).toBe(500);
@@ -550,7 +536,7 @@ describe('GET /api/orders', () => {
550536
});
551537

552538
const request = new NextRequest('http://localhost:3000/api/orders');
553-
await GET(request);
539+
await GET(request, {} as any);
554540

555541
expect(orderService.listOrders).toHaveBeenCalledWith(
556542
expect.objectContaining({
@@ -574,7 +560,7 @@ describe('GET /api/orders', () => {
574560
});
575561

576562
const request = new NextRequest('http://localhost:3000/api/orders');
577-
await GET(request);
563+
await GET(request, {} as any);
578564

579565
expect(orderService.listOrders).toHaveBeenCalledWith(
580566
expect.objectContaining({

src/app/shop/orders/[id]/confirmation/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export default async function OrderConfirmationPage({ params }: OrderConfirmatio
126126
<div className="w-16 h-16 bg-gray-200 rounded-md flex-shrink-0 relative">
127127
{item.product?.images?.[0] ? (
128128
<Image
129-
src={item.product.images[0]}
129+
src={(item.product.images as string[])[0]}
130130
alt={item.productName}
131131
fill
132132
className="object-cover rounded-md"

src/lib/audit.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import { NextRequest } from 'next/server';
66
import { db } from './db';
7+
import type { Prisma } from '@prisma/client';
78

89
/**
910
* Audit action types (security-critical operations)
@@ -147,14 +148,16 @@ export async function createAuditLog(params: {
147148
});
148149
}
149150

151+
const changesJson = Object.keys(changes).length > 0 ? JSON.stringify(changes) : undefined;
152+
150153
await db.auditLog.create({
151154
data: {
152155
userId: params.userId,
153156
storeId: params.storeId,
154157
action: params.action,
155158
entityType: params.resource,
156159
entityId: params.resourceId || '',
157-
changes: Object.keys(changes).length > 0 ? JSON.stringify(changes) : null,
160+
...(changesJson !== undefined && { changes: changesJson }),
158161
ipAddress: params.ipAddress,
159162
userAgent: params.userAgent,
160163
},
@@ -210,7 +213,7 @@ export async function queryAuditLogs(params: {
210213
action: string;
211214
entityType: string;
212215
entityId: string;
213-
changes: string | null;
216+
changes: Prisma.JsonValue;
214217
ipAddress: string | null;
215218
userAgent: string | null;
216219
createdAt: Date;

src/services/attribute-service.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,13 @@ export class AttributeService {
579579
/**
580580
* Parse JSON attribute values safely
581581
*/
582-
private parseAttributeValues(values: string): string[] {
582+
private parseAttributeValues(values: Prisma.JsonValue): string[] {
583583
try {
584-
const parsed = JSON.parse(values);
585-
return Array.isArray(parsed) ? parsed : [];
584+
if (typeof values === 'string') {
585+
const parsed = JSON.parse(values);
586+
return Array.isArray(parsed) ? parsed : [];
587+
}
588+
return Array.isArray(values) ? values.map(String) : [];
586589
} catch {
587590
return [];
588591
}

src/services/audit-log-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,16 @@ export class AuditLogService {
108108
throw new Error(`Invalid action: ${action}. Must be one of: ${validActions.join(', ')}`);
109109
}
110110

111+
const changesJson = changes ? JSON.stringify(changes) : undefined;
112+
111113
const auditLog = await prisma.auditLog.create({
112114
data: {
113115
action: action.toUpperCase(),
114116
entityType,
115117
entityId,
116118
storeId: storeId || null,
117119
userId: userId || null,
118-
changes: changes ? JSON.stringify(changes) : null,
120+
...(changesJson !== undefined && { changes: changesJson }),
119121
ipAddress: metadata?.ipAddress || null,
120122
userAgent: metadata?.userAgent || null,
121123
},

src/services/integration-service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,8 @@ export class IntegrationService {
492492
* Log sync operation result
493493
*/
494494
static async logSync(configId: string, log: SyncLogInput) {
495+
const metadataJson = log.metadata || undefined;
496+
495497
return db.syncLog.create({
496498
data: {
497499
configId,
@@ -501,7 +503,7 @@ export class IntegrationService {
501503
recordsProcessed: log.recordsProcessed,
502504
recordsFailed: log.recordsFailed,
503505
errorMessage: log.errorMessage || null,
504-
metadata: log.metadata || null,
506+
...(metadataJson !== undefined && { metadata: metadataJson }),
505507
},
506508
});
507509
}

0 commit comments

Comments
 (0)