From 3903191cdc80fb4828d5a97b08e1bc557cc6c771 Mon Sep 17 00:00:00 2001
From: yosaphatprs
Date: Mon, 17 Nov 2025 14:51:47 +0700
Subject: [PATCH] feat: add handler for invalid proof at proof service backend
because of age doesn't meet proving requirement
---
.../api/src/common/fabric-gateway/index.ts | 2 +-
backend/api/src/main.ts | 7 ++++-
.../api/src/modules/audit/audit.controller.ts | 6 ----
.../api/src/modules/audit/audit.service.ts | 31 +++++++++----------
.../src/modules/proof/dto/log-proof.dto.ts | 2 +-
.../api/src/modules/proof/proof.service.ts | 30 ++++++++++++------
.../src/views/dashboard/AuditTrailView.vue | 2 +-
7 files changed, 44 insertions(+), 36 deletions(-)
diff --git a/backend/api/src/common/fabric-gateway/index.ts b/backend/api/src/common/fabric-gateway/index.ts
index c448dda..abec209 100644
--- a/backend/api/src/common/fabric-gateway/index.ts
+++ b/backend/api/src/common/fabric-gateway/index.ts
@@ -238,7 +238,7 @@ class FabricGateway {
`Evaluating getLogWithPagination transaction with pageSize: ${pageSize}, bookmark: ${bookmark}...`,
);
const resultBytes = await this.contract.evaluateTransaction(
- 'getLogWithPagination',
+ 'getLogsWithPagination',
pageSize.toString(),
bookmark,
);
diff --git a/backend/api/src/main.ts b/backend/api/src/main.ts
index 6b34265..ba67f11 100644
--- a/backend/api/src/main.ts
+++ b/backend/api/src/main.ts
@@ -14,7 +14,12 @@ async function bootstrap() {
const configService = app.get(ConfigService);
app.setGlobalPrefix('api/');
app.enableCors({
- origin: 'https://64spbch3-5173.asse.devtunnels.ms',
+ origin: [
+ 'https://64spbch3-5173.asse.devtunnels.ms',
+ 'https://64spbch3-5174.asse.devtunnels.ms',
+ 'http://localhost:5173',
+ 'http://localhost:5174',
+ ],
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'],
allowedHeaders: 'Content-Type, Accept, X-CSRF-Token',
diff --git a/backend/api/src/modules/audit/audit.controller.ts b/backend/api/src/modules/audit/audit.controller.ts
index dd9079f..390f870 100644
--- a/backend/api/src/modules/audit/audit.controller.ts
+++ b/backend/api/src/modules/audit/audit.controller.ts
@@ -43,12 +43,6 @@ export class AuditController {
createAuditTrail() {
this.auditService.storeAuditTrail();
return { message: 'Proses audit trail dijalankan', status: 'STARTED' };
- // return interval(1000).pipe(
- // map(
- // (_) =>
- // ({ data: { message: 'Audit trail in progress...' } }) as MessageEvent,
- // ),
- // );
}
@Sse('stream')
diff --git a/backend/api/src/modules/audit/audit.service.ts b/backend/api/src/modules/audit/audit.service.ts
index 05745cc..a378071 100644
--- a/backend/api/src/modules/audit/audit.service.ts
+++ b/backend/api/src/modules/audit/audit.service.ts
@@ -130,23 +130,22 @@ export class AuditService {
break;
}
- // const records = (
- // await Promise.all(
- // logs.map((logEntry, index) =>
- // this.buildAuditRecord(logEntry, index),
- // ),
- // )
- // ).filter((record): record is AuditRecordPayload => record !== null);
+ const records = (
+ await Promise.all(
+ logs.map((logEntry, index) =>
+ this.buildAuditRecord(logEntry, index),
+ ),
+ )
+ ).filter((record): record is AuditRecordPayload => record !== null);
- const records: AuditRecordPayload[] = [];
- for (let index = 0; index < logs.length; index++) {
- const record = await this.buildAuditRecord(logs[index], index);
- if (record !== null) {
- records.push(record);
- }
- // Wait 1 second before processing next item
- await new Promise((resolve) => setTimeout(resolve, 250));
- }
+ // const records: AuditRecordPayload[] = [];
+ // for (let index = 0; index < logs.length; index++) {
+ // const record = await this.buildAuditRecord(logs[index], index);
+ // if (record !== null) {
+ // records.push(record);
+ // }
+ // await new Promise((resolve) => setTimeout(resolve, 250));
+ // }
if (records.length > 0) {
await this.prisma.$transaction(
diff --git a/backend/api/src/modules/proof/dto/log-proof.dto.ts b/backend/api/src/modules/proof/dto/log-proof.dto.ts
index 03be28e..03dcc04 100644
--- a/backend/api/src/modules/proof/dto/log-proof.dto.ts
+++ b/backend/api/src/modules/proof/dto/log-proof.dto.ts
@@ -9,7 +9,7 @@ import {
export class LogProofDto {
@IsNotEmpty({ message: 'Proof wajib diisi' })
@IsObject({ message: 'Proof harus berupa objek' })
- proofHash: any;
+ proof: any;
@IsNotEmpty({ message: 'ID Visit wajib diisi' })
@IsString({ message: 'ID Visit harus berupa string' })
diff --git a/backend/api/src/modules/proof/proof.service.ts b/backend/api/src/modules/proof/proof.service.ts
index 8866035..7c1d07a 100644
--- a/backend/api/src/modules/proof/proof.service.ts
+++ b/backend/api/src/modules/proof/proof.service.ts
@@ -1,6 +1,6 @@
import {
+ BadRequestException,
Injectable,
- InternalServerErrorException,
NotFoundException,
} from '@nestjs/common';
import { PrismaService } from '../prisma/prisma.service';
@@ -62,14 +62,24 @@ export class ProofService {
// const { proof, publicSignals } = await this.generateProof();
- const { proof, publicSignals } = await groth16.fullProve(
- {
- age: age,
- threshold: 18,
- },
- this.wasmPath,
- this.zkeyPath,
- );
+ let result: any;
+
+ try {
+ result = await groth16.fullProve(
+ {
+ age: age,
+ threshold: 18,
+ },
+ this.wasmPath,
+ this.zkeyPath,
+ );
+ } catch (error) {
+ throw new BadRequestException(
+ "Can't generate proof from input based on constraint. Please check the input data and try again.",
+ );
+ }
+
+ const { proof, publicSignals } = result;
return {
proof: proof,
@@ -80,7 +90,7 @@ export class ProofService {
async logVerificationProof(logProofDto: LogProofDto) {
const payload = {
id_visit: logProofDto.id_visit || null,
- proofHash: logProofDto.proofHash || null,
+ proofHash: logProofDto.proof || null,
proofResult: logProofDto.proofResult || null,
};
diff --git a/frontend/hospital-log/src/views/dashboard/AuditTrailView.vue b/frontend/hospital-log/src/views/dashboard/AuditTrailView.vue
index 049b6e4..b29511c 100644
--- a/frontend/hospital-log/src/views/dashboard/AuditTrailView.vue
+++ b/frontend/hospital-log/src/views/dashboard/AuditTrailView.vue
@@ -447,7 +447,7 @@ onBeforeUnmount(() => {
Proses audit sedang berjalan...
- {{ progres + 1 }} data telah diperiksa
+ {{ progres }} data telah diperiksa