Refactor server version object into own interface

This makes the type of getServerVersionFromPackageJson() way easier
to read.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-02-27 21:21:41 +01:00
parent fc1008e773
commit 609b1cf3a3
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
2 changed files with 13 additions and 22 deletions

View file

@ -5,24 +5,13 @@
*/
import { Injectable } from '@nestjs/common';
import { ServerStatusDto } from './server-status.dto';
import { promises as fs } from 'fs';
import { join as joinPath } from 'path';
import { ServerStatusDto, ServerVersion } from './server-status.dto';
let versionCache: null | {
major: number;
minor: number;
patch: number;
preRelease?: string;
commit?: string;
} = null;
async function getServerVersionFromPackageJson(): Promise<{
major: number;
minor: number;
patch: number;
preRelease?: string;
commit?: string;
}> {
let versionCache: ServerVersion;
async function getServerVersionFromPackageJson(): Promise<ServerVersion> {
if (versionCache === null) {
const rawFileContent: string = await fs.readFile(
joinPath(__dirname, '../../package.json'),

View file

@ -4,14 +4,16 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
export class ServerStatusDto {
serverVersion: {
export interface ServerVersion {
major: number;
minor: number;
patch: number;
preRelease?: string;
commit?: string;
};
}
export class ServerStatusDto {
serverVersion: ServerVersion;
onlineNotes: number;
onlineUsers: number;
destictOnlineUsers: number;