Skip to content

Commit b145fc4

Browse files
committed
Refactor type definitions in audit and routes for improved clarity and type safety. Replace Prisma imports with local type annotations and enhance metadata handling in audit logs to use a more flexible Record type.
1 parent 2d77fb3 commit b145fc4

3 files changed

Lines changed: 6 additions & 17 deletions

File tree

backend/src/lib/audit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import { Prisma } from '@prisma/client'
21
import prisma from './prisma.js'
32

43
interface AuditLogData {
54
actorUserId?: string | null
65
action: string
76
entityType: string
87
entityId?: string | null
9-
metadata?: Prisma.InputJsonValue
8+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
9+
metadata?: Record<string, any>
1010
}
1111

1212
/**

backend/src/routes/messages.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Router, Request, Response } from 'express'
22
import { z } from 'zod'
3-
import { Prisma } from '@prisma/client'
43
import prisma from '../lib/prisma.js'
54
import { requireAuth, requirePermission } from '../middleware/auth.js'
65
import { getProviderForChannel } from '../providers/messaging/index.js'
@@ -11,9 +10,6 @@ type MessageChannel = 'email' | 'sms'
1110
type MemberStatus = 'active' | 'inactive' | 'visitor'
1211
type DeliveryStatus = 'pending' | 'sent' | 'failed'
1312

14-
// Type for Prisma transaction client
15-
type TransactionClient = Prisma.TransactionClient
16-
1713
const router = Router()
1814

1915
// ============================================
@@ -232,7 +228,7 @@ router.post('/', requireAuth, requirePermission('communications.send'), async (r
232228
}
233229

234230
// Create message and recipients in a transaction
235-
const message = await prisma.$transaction(async (tx: TransactionClient) => {
231+
const message = await prisma.$transaction(async (tx) => {
236232
const newMessage = await tx.message.create({
237233
data: {
238234
channel: channel as MessageChannel,

backend/src/routes/sales.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
import { Router } from 'express'
22
import { z } from 'zod'
3-
import { Prisma } from '@prisma/client'
43
import prisma from '../lib/prisma.js'
54
import { requireAuth, requirePermission } from '../middleware/auth.js'
65
import { JwtPayload } from '../lib/auth.js'
76
import { createAuditLog } from '../lib/audit.js'
87

9-
// Type for Prisma transaction client
10-
type TransactionClient = Prisma.TransactionClient
11-
12-
// Infer Product type from Prisma client
13-
type Product = Prisma.ProductGetPayload<Record<string, never>>
14-
158
const router = Router()
169

1710
// Zod schemas
@@ -39,7 +32,7 @@ router.post('/', requireAuth, requirePermission('sales.edit'), async (req, res)
3932
const user = req.user as JwtPayload
4033

4134
// Use a transaction to ensure atomicity
42-
const result = await prisma.$transaction(async (tx: TransactionClient) => {
35+
const result = await prisma.$transaction(async (tx) => {
4336
// Generate sale number within transaction
4437
const saleNumber = await (async () => {
4538
const year = new Date().getFullYear()
@@ -69,7 +62,7 @@ router.post('/', requireAuth, requirePermission('sales.edit'), async (req, res)
6962
throw new Error('One or more products not found')
7063
}
7164

72-
const productMap = new Map<string, Product>(products.map((p) => [p.id, p]))
65+
const productMap = new Map(products.map((p: typeof products[0]) => [p.id, p] as const))
7366

7467
// Calculate line items and subtotal
7568
let subtotalCents = 0
@@ -251,7 +244,7 @@ router.post('/:id/void', requireAuth, requirePermission('sales.edit'), async (re
251244
const user = req.user as JwtPayload
252245

253246
// Use transaction for atomicity
254-
const result = await prisma.$transaction(async (tx: TransactionClient) => {
247+
const result = await prisma.$transaction(async (tx) => {
255248
const sale = await tx.sale.findUnique({
256249
where: { id },
257250
include: {

0 commit comments

Comments
 (0)