Skip to content
This repository has been archived by the owner on Nov 7, 2020. It is now read-only.

Commit

Permalink
feat: improve status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mentos1386 committed Jul 29, 2018
1 parent d01aefe commit 6a311a8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
3 changes: 3 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ DB_SYNC=true
# Log
LOG_LEVEL=debug

# ZKillboard
ZKILLBOARD_ENDPOINT=https://

# ESI
ESI_CLIENT=7sdf771c2casc8das8va78vasd
ESI_SECRET=Jb1b3j12jaskjdkjJjhk3jHJhs6Jkj456sdh3
Expand Down
4 changes: 2 additions & 2 deletions src/modules/core/status/status.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiModelProperty } from '@nestjs/swagger';
import { IStatus } from './status.interface';
import { IStatus, IESIStatus } from './status.interface';
import { IGetStatus } from '../external/esi/esi.interface';

export class DStatus {
Expand All @@ -10,7 +10,7 @@ export class DStatus {
version: string;

@ApiModelProperty()
esi: IGetStatus;
esi: IESIStatus;

constructor(status: IStatus) {
this.state = status.state;
Expand Down
14 changes: 12 additions & 2 deletions src/modules/core/status/status.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { IGetStatus } from '../external/esi/esi.interface';

export type STATE = 'OK' | 'NOK';

export interface IStatus {
esi: IGetStatus;
state: 'OK' | 'NOK';
esi: IESIStatus;
version: string;
state: STATE;
}

export interface IESIStatus {
players?: IGetStatus['players'];
serverVersion?: IGetStatus['server_version'];
startTime?: IGetStatus['start_time'];
exception?: string;
state: STATE;
}
22 changes: 20 additions & 2 deletions src/modules/core/status/status.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable, Inject } from '@nestjs/common';
import { ESIService } from '../external/esi/esi.service';
import { IStatus } from './status.interface';
import { IStatus, IESIStatus } from './status.interface';
import { IGetStatus } from '../external/esi/esi.interface';

@Injectable()
export class StatusService {
Expand All @@ -11,12 +12,29 @@ export class StatusService {
}

async status(): Promise<IStatus> {
const esiStatus = await this.esiService.status();
const esiStatus = await this.esiStatus();

return {
esi: esiStatus,
state: 'OK',
version: process.env.npm_package_version,
};
}

async esiStatus(): Promise<IESIStatus> {
try {
const esiStatus = await this.esiService.status();
return {
players: esiStatus.players,
serverVersion: esiStatus.server_version,
startTime: esiStatus.start_time,
state: 'OK',
}
} catch(exception) {
return {
exception: exception.message,
state: 'NOK',
}
}
}
}

0 comments on commit 6a311a8

Please sign in to comment.