|
|
@@ -1,7 +1,13 @@
|
|
|
import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify'
|
|
|
import { QrCodeService } from '../services/qr-code.service'
|
|
|
import { ScanRecordService } from '../services/scan-record.service'
|
|
|
-import { GenerateQrCodeDto, QueryQrCodeDto, VerifyMaintenanceCodeDto, GetQrCodeInfoDto } from '../dto/qr-code.dto'
|
|
|
+import {
|
|
|
+ GenerateQrCodeDto,
|
|
|
+ QueryQrCodeDto,
|
|
|
+ VerifyMaintenanceCodeDto,
|
|
|
+ GetQrCodeInfoDto,
|
|
|
+ ResetMaintenanceCodeDto
|
|
|
+} from '../dto/qr-code.dto'
|
|
|
|
|
|
export class QrCodeController {
|
|
|
private qrCodeService: QrCodeService
|
|
|
@@ -106,14 +112,14 @@ export class QrCodeController {
|
|
|
const ipAddress = request.ip
|
|
|
const userAgent = request.headers['user-agent']
|
|
|
|
|
|
- // 获取二维码信息
|
|
|
- const info = await this.qrCodeService.getQrCodeInfo(qrCode, id)
|
|
|
-
|
|
|
// 如果通过 qrCode 查询,记录扫描
|
|
|
if (qrCode) {
|
|
|
await this.scanRecordService.create(qrCode, undefined, undefined, undefined, ipAddress, userAgent)
|
|
|
}
|
|
|
|
|
|
+ // 获取二维码信息
|
|
|
+ const info = await this.qrCodeService.getQrCodeInfo(qrCode, id)
|
|
|
+
|
|
|
return reply.send(info)
|
|
|
} catch (error) {
|
|
|
const message = error instanceof Error ? error.message : '获取信息失败'
|
|
|
@@ -147,4 +153,26 @@ export class QrCodeController {
|
|
|
return reply.code(500).send({ message })
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 重置维护码
|
|
|
+ */
|
|
|
+ async resetMaintenanceCode(request: FastifyRequest<{ Body: ResetMaintenanceCodeDto }>, reply: FastifyReply) {
|
|
|
+ try {
|
|
|
+ const { qrCode, maintenanceCode } = request.body
|
|
|
+
|
|
|
+ const newMaintenanceCode = await this.qrCodeService.resetMaintenanceCode(qrCode, maintenanceCode)
|
|
|
+
|
|
|
+ return reply.send({
|
|
|
+ message: '维护码重置成功',
|
|
|
+ data: {
|
|
|
+ qrCode,
|
|
|
+ maintenanceCode: newMaintenanceCode
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ const message = error instanceof Error ? error.message : '重置失败'
|
|
|
+ return reply.code(500).send({ message })
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|