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

View file

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