feat: delete validation on admin at tindakna

This commit is contained in:
yosaphatprs 2025-11-26 16:59:44 +07:00
parent e1a539325f
commit 3bf3c9e1eb
3 changed files with 18 additions and 38 deletions

View File

@ -84,30 +84,6 @@ export class AuditService {
let bookmark = ''; let bookmark = '';
let processedCount = 0; let processedCount = 0;
// try {
// const intervalId = setInterval(() => {
// processedCount++;
// const progressData = {
// status: 'RUNNING',
// progress_count: processedCount,
// };
// this.logger.log('Mengirim progres via WebSocket:', progressData);
// // PANGGIL FUNGSI GATEWAY
// this.auditGateway.sendProgress(progressData);
// if (processedCount >= BATCH_SIZE) {
// clearInterval(intervalId);
// const completeData = { status: 'COMPLETED' };
// this.logger.log('Mengirim selesai via WebSocket:', completeData);
// // PANGGIL FUNGSI GATEWAY
// this.auditGateway.sendComplete(completeData);
// }
// }, 500);
// } catch (error) {
// console.error('Tes streaming GAGAL', error);
// }
try { try {
while (true) { while (true) {
const pageResults = await this.logService.getLogsWithPagination( const pageResults = await this.logService.getLogsWithPagination(
@ -135,15 +111,6 @@ export class AuditService {
) )
).filter((record): record is AuditRecordPayload => record !== null); ).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);
// }
// await new Promise((resolve) => setTimeout(resolve, 250));
// }
if (records.length > 0) { if (records.length > 0) {
await this.prisma.$transaction( await this.prisma.$transaction(
records.map((record) => records.map((record) =>
@ -252,9 +219,8 @@ export class AuditService {
} }
let dbHash: string | null = null; let dbHash: string | null = null;
//
try { try {
if (logId.startsWith('OBAT_')) { if (logId.startsWith('OBAT')) {
const obatId = this.extractNumericId(logId); const obatId = this.extractNumericId(logId);
if (obatId !== null) { if (obatId !== null) {
const obat = await this.obatService.getObatById(obatId); const obat = await this.obatService.getObatById(obatId);
@ -302,9 +268,17 @@ export class AuditService {
console.warn(`Failed to resolve related data for log ${logId}:`, err); console.warn(`Failed to resolve related data for log ${logId}:`, err);
} }
const isNotTampered = dbHash let isNotTampered = false;
? await this.compareData(blockchainHash, dbHash) const eventType = logEntry.value.event?.split('_').at(-1);
: false;
if (eventType === 'deleted') {
isNotTampered = true;
console.log('Detected deleted event, marking as not tempered');
} else {
const hashesMatch =
dbHash && (await this.compareData(blockchainHash, dbHash));
isNotTampered = Boolean(hashesMatch);
}
const result: ResultStatus = isNotTampered ? 'non_tampered' : 'tampered'; const result: ResultStatus = isNotTampered ? 'non_tampered' : 'tampered';

View File

@ -42,6 +42,10 @@ const formatCellValue = (item: T, columnKey: keyof T) => {
if (segments.length >= 2 && segments[segments.length - 1] === "updated") { if (segments.length >= 2 && segments[segments.length - 1] === "updated") {
return "UPDATE"; return "UPDATE";
} }
if (segments.length >= 2 && segments[segments.length - 1] === "deleted") {
return "DELETE";
}
} }
return value; return value;

View File

@ -218,6 +218,8 @@ const fetchData = async () => {
`/audit/trail${params.toString() ? `?${params.toString()}` : ""}` `/audit/trail${params.toString() ? `?${params.toString()}` : ""}`
); );
console.log("Audit Log Response:", response);
const apiResponse = response as any; const apiResponse = response as any;
pagination.totalCount.value = apiResponse.totalCount; pagination.totalCount.value = apiResponse.totalCount;