cityssm/parking-ticket-system

View on GitHub
handlers/plates-post/doAddLicencePlateToLookupBatch.ts

Summary

Maintainability
A
0 mins
Test Coverage
import type { Request, Response } from 'express'

import { addLicencePlateToLookupBatch } from '../../database/parkingDB/addLicencePlateToLookupBatch.js'
import getLookupBatch from '../../database/parkingDB/getLookupBatch.js'
import type { LicencePlateLookupBatchEntry } from '../../types/recordTypes.js'

export default function handler(request: Request, response: Response): void {
  const result = addLicencePlateToLookupBatch(
    request.body as LicencePlateLookupBatchEntry,
    request.session.user as PTSUser
  )

  if (result.success) {
    result.batch = getLookupBatch(
      Number.parseInt(request.body.batchId as string, 10)
    )
  }

  response.json(result)
}