Fix home component

This commit is contained in:
Torjus Håkestad 2021-04-11 12:39:51 +02:00
parent 65fb8254f5
commit b7893b61eb

View File

@ -55,40 +55,60 @@ interface TotalStatsResult {
@Component @Component
export default class Home extends Vue { export default class Home extends Vue {
totalLoginAttempts?: number; totalLoginAttempts: number;
uniquePasswords?: number; uniquePasswords: number;
uniqueUsernames?: number; uniqueUsernames: number;
uniqueIPs?: number; uniqueIPs: number;
uniqueCountries?: number; uniqueCountries: number;
ready = false; ready = false;
constructor() {
super();
this.totalLoginAttempts = 0;
this.uniquePasswords = 0;
this.uniqueUsernames = 0;
this.uniqueIPs = 0;
this.uniqueCountries = 0;
}
updateStats(): void { updateStats(): void {
const url = `/api/stats?type=total`; const url = `/api/stats?type=total`;
axios axios
.get<TotalStatsResult[]>(url) .get<TotalStatsResult[]>(url)
.then((resp) => { .then((resp) => {
this.totalLoginAttempts = resp.data.find( const totals = resp.data.find((e) => e.name === 'TotalLoginAttempts')
(e) => e.name === 'TotalLoginAttempts', ?.count;
)?.count; if (totals) {
this.totalLoginAttempts = totals;
}
this.uniquePasswords = resp.data.find( const passwords = resp.data.find((e) => e.name === 'UniquePasswords')
(e) => e.name === 'UniquePasswords', ?.count;
)?.count; if (passwords) {
this.uniquePasswords = passwords;
}
this.uniqueUsernames = resp.data.find( const usernames = resp.data.find((e) => e.name === 'UniqueUsernames')
(e) => e.name === 'UniqueUsernames', ?.count;
)?.count; if (usernames) {
this.uniqueUsernames = usernames;
}
this.uniqueIPs = resp.data.find((e) => e.name === 'UniqueIPs')?.count; const ips = resp.data.find((e) => e.name === 'UniqueIPs')?.count;
if (ips) {
this.uniqueIPs = ips;
}
this.uniqueCountries = resp.data.find( const countries = resp.data.find((e) => e.name === 'UniqueCountries')
(e) => e.name === 'UniqueCountries', ?.count;
)?.count; if (countries) {
this.uniqueCountries = countries;
}
this.ready = true; this.ready = true;
}) })