feat: tindakan update validation for admin
This commit is contained in:
parent
ed5ec161a0
commit
1cab0a2348
|
|
@ -190,9 +190,7 @@ export class TindakanDokterService {
|
|||
throw new BadRequestException('ID tindakan tidak valid');
|
||||
}
|
||||
|
||||
const existing = await this.prisma.pemberian_tindakan.findUnique({
|
||||
where: { id: tindakanId },
|
||||
});
|
||||
const existing = await this.getTindakanDokterById(tindakanId);
|
||||
|
||||
if (!existing) {
|
||||
throw new BadRequestException(
|
||||
|
|
@ -201,10 +199,10 @@ export class TindakanDokterService {
|
|||
}
|
||||
|
||||
const hasUpdates =
|
||||
dto.id_visit !== undefined ||
|
||||
dto.tindakan !== undefined ||
|
||||
dto.kategori_tindakan !== undefined ||
|
||||
dto.kelompok_tindakan !== undefined;
|
||||
dto.id_visit !== existing.id_visit ||
|
||||
dto.tindakan !== existing.tindakan ||
|
||||
dto.kategori_tindakan !== existing.kategori_tindakan ||
|
||||
dto.kelompok_tindakan !== existing.kelompok_tindakan;
|
||||
|
||||
if (!hasUpdates) {
|
||||
throw new BadRequestException('Tidak ada data tindakan yang diubah');
|
||||
|
|
@ -217,35 +215,17 @@ export class TindakanDokterService {
|
|||
|
||||
if (!visitExists) {
|
||||
throw new BadRequestException(
|
||||
`Visit dengan ID ${dto.id_visit} tidak ditemukan`,
|
||||
`ID Visit ${dto.id_visit} tidak ditemukan`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const updateData: Prisma.pemberian_tindakanUpdateInput = {
|
||||
...(dto.id_visit !== undefined ? { id_visit: dto.id_visit } : {}),
|
||||
...(dto.tindakan !== undefined ? { tindakan: dto.tindakan } : {}),
|
||||
...(dto.kategori_tindakan !== undefined
|
||||
? { kategori_tindakan: dto.kategori_tindakan ?? null }
|
||||
: {}),
|
||||
...(dto.kelompok_tindakan !== undefined
|
||||
? { kelompok_tindakan: dto.kelompok_tindakan ?? null }
|
||||
: {}),
|
||||
};
|
||||
|
||||
const validationQueue = await this.prisma.validation_queue.create({
|
||||
data: {
|
||||
table_name: 'pemberian_tindakan',
|
||||
action: 'UPDATE',
|
||||
dataPayload: {
|
||||
...(dto.id_visit !== undefined ? { id_visit: dto.id_visit } : {}),
|
||||
...(dto.tindakan !== undefined ? { tindakan: dto.tindakan } : {}),
|
||||
...(dto.kategori_tindakan !== undefined
|
||||
? { kategori_tindakan: dto.kategori_tindakan ?? null }
|
||||
: {}),
|
||||
...(dto.kelompok_tindakan !== undefined
|
||||
? { kelompok_tindakan: dto.kelompok_tindakan ?? null }
|
||||
: {}),
|
||||
...dto,
|
||||
},
|
||||
record_id: tindakanId.toString(),
|
||||
user_id_request: user.sub,
|
||||
|
|
@ -256,6 +236,41 @@ export class TindakanDokterService {
|
|||
return validationQueue;
|
||||
}
|
||||
|
||||
async updateTindakanDokterToDBAndBlockchain(
|
||||
id: number,
|
||||
dto: UpdateTindakanDokterDto,
|
||||
userId: number,
|
||||
) {
|
||||
try {
|
||||
const updatedTindakan = await this.prisma.$transaction(async (tx) => {
|
||||
const tindakanId = Number(id);
|
||||
|
||||
const updated = await tx.pemberian_tindakan.update({
|
||||
where: { id: tindakanId },
|
||||
data: dto,
|
||||
});
|
||||
const logPayload = JSON.stringify(dto);
|
||||
const payloadHash = sha256(logPayload);
|
||||
const data = {
|
||||
id: `TINDAKAN_${updated.id}`,
|
||||
event: 'tindakan_dokter_updated',
|
||||
user_id: userId.toString(),
|
||||
payload: payloadHash,
|
||||
};
|
||||
|
||||
const createdLog = await this.logService.storeLog(data);
|
||||
return {
|
||||
...updated,
|
||||
log: createdLog,
|
||||
};
|
||||
});
|
||||
return updatedTindakan;
|
||||
} catch (error) {
|
||||
console.error('Error updating Tindakan Dokter:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
async getTindakanLogById(id: string) {
|
||||
const tindakanId = parseInt(id, 10);
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,14 @@ export class ValidationService {
|
|||
id: result.id,
|
||||
};
|
||||
},
|
||||
approveUpdate: async (queue: any) => {
|
||||
const payload = queue.dataPayload;
|
||||
return await this.tindakanDokterService.updateTindakanDokterToDBAndBlockchain(
|
||||
queue.record_id,
|
||||
payload,
|
||||
Number(queue.user_id_request),
|
||||
);
|
||||
},
|
||||
},
|
||||
pemberian_obat: {},
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user