Fakultas Ilmu Komputer UI

Commit 5248e610 authored by Sean Zeliq Urian's avatar Sean Zeliq Urian
Browse files

[RED] create utils for Log decoding

parent 46fa99ec
import { LogDetail } from 'scenes/ActivityLog/types/types'
const generateLogMessage = async (log: any, services: any) => {
let message = '';
switch (log.model_name) {
case 'Account': {
const accountResponse = await services.main.getAccount(log.object_id);
switch (log.action_type) {
case 'Create': {
if (accountResponse.status === 200) {
let username = accountResponse.data.username;
let accountType = accountResponse.data.is_admin
? 'admin'
: 'kader';
message =
'Menambahkan akun ' +
accountType +
' dengan username ' +
username;
} else {
message = 'Menambahkan akun yang sudah dihapus';
}
break;
}
case 'Edit': {
if (accountResponse.status === 200) {
let username = accountResponse.data.username;
let accountType = accountResponse.data.is_admin
? 'admin'
: 'kader';
message =
'Memperbarui akun ' +
accountType +
' dengan username ' +
username;
} else {
message = 'Memperbarui akun yang sudah dihapus';
}
break;
}
case 'Delete': {
message = 'Menghapus akun';
break;
}
}
break;
}
case 'Case Subject': {
const caseSubjectResponse = await services.main.getCaseSubject(
log.object_id
);
message =
'Menambahkan subjek kasus baru atas nama ' +
caseSubjectResponse.data.name;
break;
}
case 'Investigation Case': {
const investigationCaseResponse = await services.main.getInvestigationCase(
log.object_id
);
message =
'Menambahkan kasus positif atas nama ' +
investigationCaseResponse.data.case_subject.name;
break;
}
case 'Monitoring Case': {
const monitoringCaseResponse = await services.main.getMonitoringCase(
log.object_id
);
message =
'Menambahkan objek pemantauan baru atas nama ' +
monitoringCaseResponse.data.investigation_case.case_subject.name;
break;
}
}
return message;
};
const generateLogDetail = async (log: any, services: any): Promise<LogDetail> => {
let logDetail: LogDetail = {
activity: log.model_name,
authorRole: log.author.is_admin ? 'admin' : 'kader',
authorName: log.author.username,
object: '',
};
switch (log.model_name) {
case 'Account': {
logDetail.activity = `${log.action_type} ${logDetail.activity}`;
const accountResponse = await services.main.getAccount(log.object_id);
if (accountResponse.status === 200) {
let username = accountResponse.data.username;
let accountType = accountResponse.data.is_admin ? 'admin' : 'kader';
logDetail.object = `${username} as ${accountType}`;
} else {
logDetail.object = 'deleted';
}
break;
}
case 'Case Subject': {
const caseSubjectResponse = await services.main.getCaseSubject(
log.object_id
);
logDetail.object = caseSubjectResponse.data.name;
break;
}
case 'Investigation Case': {
const investigationCaseResponse = await services.main.getInvestigationCase(
log.object_id
);
logDetail.object = investigationCaseResponse.data.case_subject.name;
break;
}
case 'Monitoring Case': {
const monitoringCaseResponse = await services.main.getMonitoringCase(
log.object_id
);
logDetail.object =
monitoringCaseResponse.data.investigation_case.case_subject.name;
break;
}
}
return logDetail;
};
export { generateLogDetail, generateLogMessage };
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment