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');
|
throw new BadRequestException('ID tindakan tidak valid');
|
||||||
}
|
}
|
||||||
|
|
||||||
const existing = await this.prisma.pemberian_tindakan.findUnique({
|
const existing = await this.getTindakanDokterById(tindakanId);
|
||||||
where: { id: tindakanId },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
|
|
@ -201,10 +199,10 @@ export class TindakanDokterService {
|
||||||
}
|
}
|
||||||
|
|
||||||
const hasUpdates =
|
const hasUpdates =
|
||||||
dto.id_visit !== undefined ||
|
dto.id_visit !== existing.id_visit ||
|
||||||
dto.tindakan !== undefined ||
|
dto.tindakan !== existing.tindakan ||
|
||||||
dto.kategori_tindakan !== undefined ||
|
dto.kategori_tindakan !== existing.kategori_tindakan ||
|
||||||
dto.kelompok_tindakan !== undefined;
|
dto.kelompok_tindakan !== existing.kelompok_tindakan;
|
||||||
|
|
||||||
if (!hasUpdates) {
|
if (!hasUpdates) {
|
||||||
throw new BadRequestException('Tidak ada data tindakan yang diubah');
|
throw new BadRequestException('Tidak ada data tindakan yang diubah');
|
||||||
|
|
@ -217,35 +215,17 @@ export class TindakanDokterService {
|
||||||
|
|
||||||
if (!visitExists) {
|
if (!visitExists) {
|
||||||
throw new BadRequestException(
|
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({
|
const validationQueue = await this.prisma.validation_queue.create({
|
||||||
data: {
|
data: {
|
||||||
table_name: 'pemberian_tindakan',
|
table_name: 'pemberian_tindakan',
|
||||||
action: 'UPDATE',
|
action: 'UPDATE',
|
||||||
dataPayload: {
|
dataPayload: {
|
||||||
...(dto.id_visit !== undefined ? { id_visit: dto.id_visit } : {}),
|
...dto,
|
||||||
...(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 }
|
|
||||||
: {}),
|
|
||||||
},
|
},
|
||||||
record_id: tindakanId.toString(),
|
record_id: tindakanId.toString(),
|
||||||
user_id_request: user.sub,
|
user_id_request: user.sub,
|
||||||
|
|
@ -256,6 +236,41 @@ export class TindakanDokterService {
|
||||||
return validationQueue;
|
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) {
|
async getTindakanLogById(id: string) {
|
||||||
const tindakanId = parseInt(id, 10);
|
const tindakanId = parseInt(id, 10);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,14 @@ export class ValidationService {
|
||||||
id: result.id,
|
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: {},
|
pemberian_obat: {},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user