bootstrap
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import type { FastifyInstance } from 'fastify'
|
||||
import { parseUpdXml } from '../services/upd-parser.js'
|
||||
import { checkCodesAuth } from '../services/cises-service.js'
|
||||
|
||||
export async function updRoutes(app: FastifyInstance): Promise<void> {
|
||||
app.post('/api/upload-upd', async (request, reply) => {
|
||||
const data = await request.file()
|
||||
if (!data) {
|
||||
return reply.status(400).send({ error: 'No file uploaded' })
|
||||
}
|
||||
|
||||
const buffer = await data.toBuffer()
|
||||
const xmlContent = buffer.toString('utf-8')
|
||||
const fileName = data.filename
|
||||
|
||||
const parsed = await parseUpdXml(xmlContent, fileName)
|
||||
|
||||
if (parsed.codes.length === 0) {
|
||||
return reply.status(400).send({ error: 'No marking codes found in UPD' })
|
||||
}
|
||||
|
||||
const checkResults = await checkCodesAuth({ codes: parsed.codes })
|
||||
|
||||
return {
|
||||
document: {
|
||||
number: parsed.documentNumber,
|
||||
date: parsed.documentDate,
|
||||
seller: parsed.sellerName,
|
||||
buyer: parsed.buyerName,
|
||||
fileName: parsed.fileName,
|
||||
},
|
||||
codesFound: parsed.codes.length,
|
||||
results: checkResults,
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user