felicity-lims/webapp/stores/audit_log.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-04-01 04:29:09 +08:00
import { defineStore } from 'pinia'
2022-04-04 02:54:31 +08:00
import { useApiUtil } from '../composables'
2022-04-01 04:29:09 +08:00
2022-04-04 02:54:31 +08:00
const { withClientQuery } = useApiUtil()
2022-04-01 04:29:09 +08:00
import {
GET_AUDIT_LOG_FOR_TARGET
} from '../graphql/_queries';
2022-04-04 02:54:31 +08:00
export const useAuditLogStore = defineStore('auditlog', {
2022-04-01 04:29:09 +08:00
state: () => {
return {
auditLogs: [] as any as any[],
fetchingAudits: false,
2022-04-01 04:29:09 +08:00
}
},
getters: {
getAuditLogs: (state) => state.auditLogs,
},
actions: {
async fetchAuditLogs(params){
this.fetchingAudits = true;
2022-04-04 02:54:31 +08:00
await withClientQuery(GET_AUDIT_LOG_FOR_TARGET, params, "auditLogsFilter")
.then(payload => {
this.fetchingAudits = false
2022-08-19 22:40:02 +08:00
this.auditLogs = payload?.map(logs => {
logs.stateAfter = typeof logs?.stateAfter === "string" ? JSON.parse(logs?.stateAfter) : logs?.stateAfter
logs.stateBefore = typeof logs?.stateBefore === "string" ? JSON.parse(logs?.stateBefore) : logs?.stateBefore
return logs
2022-08-19 22:40:02 +08:00
})
}).catch(err => this.fetchingAudits = false)
2022-04-01 04:29:09 +08:00
},
2022-08-19 22:40:02 +08:00
async restLogs(){
this.auditLogs = [];
},
2022-04-01 04:29:09 +08:00
}
})