diff --git a/backend/src/business-layer/versionsBl.ts b/backend/src/business-layer/versionsBl.ts index f48021d0..4126aef5 100644 --- a/backend/src/business-layer/versionsBl.ts +++ b/backend/src/business-layer/versionsBl.ts @@ -15,7 +15,7 @@ import { logger } from '../utilities/logger'; export class VersionsBl { private updateStatus: ProgressStatus = 'finished'; - constructor() {} + constructor() { } /** * Update CASA-net application to the latest version. @@ -60,6 +60,16 @@ export class VersionsBl { }; } + /** + * Whenever the current version is not the latest + */ + public async isVersionNotUpToDate(): Promise { + const latestVersion = await this.getLatestVersionName(); + const currentVersionInfo = await this.getCurrentVersion(); + return latestVersion === currentVersionInfo.version ? '' : latestVersion; + } + + /** Get version update status */ public async getUpdateStatus(): Promise { return { @@ -195,7 +205,7 @@ export class VersionsBl { this.updateStatus = 'fail'; logger.warn( `executing RESET_MACHINE_ON_VERSION_UPDATE=${RESET_MACHINE_ON_VERSION_UPDATE}' command failed ${error.stdout || - error.message}`, + error.message}`, ); } } diff --git a/backend/src/controllers/versionsController.ts b/backend/src/controllers/versionsController.ts index 4f0715cb..f8f3f26c 100644 --- a/backend/src/controllers/versionsController.ts +++ b/backend/src/controllers/versionsController.ts @@ -52,4 +52,16 @@ export class VersionsController extends Controller { public async getCurrentVersion(): Promise { return await VersionsBlSingleton.getCurrentVersion(); } + + /** + * Detect if the current version is last, and if not return the latest version. + * @returns Empty if latest, if not the version name. + */ + @Security('adminAuth') + @Security('userAuth') + @Response(501, 'Server error') + @Get('is-up-date') + public async isLatestVersion(): Promise { + return await VersionsBlSingleton.isVersionNotUpToDate(); + } } diff --git a/backend/src/routers/routes.ts b/backend/src/routers/routes.ts index cd05d139..58529ece 100644 --- a/backend/src/routers/routes.ts +++ b/backend/src/routers/routes.ts @@ -1762,6 +1762,29 @@ export function RegisterRoutes(app: express.Express) { const promise = controller.getCurrentVersion.apply(controller, validatedArgs as any); promiseHandler(controller, promise, response, next); }); + app.get('/API/version/is-up-date', + authenticateMiddleware([{ "adminAuth": [] }, { "userAuth": [] }]), + function(request: any, response: any, next: any) { + const args = { + }; + + let validatedArgs: any[] = []; + try { + validatedArgs = getValidatedArgs(args, request); + } catch (err) { + response.status(422).send({ + responseCode: 1422, + message: JSON.stringify(err.fields), + } as ErrorResponse); + return; + } + + const controller = new VersionsController(); + + + const promise = controller.isLatestVersion.apply(controller, validatedArgs as any); + promiseHandler(controller, promise, response, next); + }); app.get('/API/rf/devices', authenticateMiddleware([{ "userAuth": [] }, { "adminAuth": [] }]), function(request: any, response: any, next: any) { diff --git a/backend/swagger.yaml b/backend/swagger.yaml index a613a59d..8c3e2610 100644 --- a/backend/swagger.yaml +++ b/backend/swagger.yaml @@ -2465,6 +2465,29 @@ paths: - userAuth: [] parameters: [] + /version/is-up-date: + get: + operationId: IsLatestVersion + produces: + - application/json + responses: + '200': + description: Ok + schema: + type: string + '501': + description: 'Server error' + schema: + $ref: '#/definitions/ErrorResponse' + description: 'Detect if the current version is last, and if not return the latest version.' + tags: + - Version + security: + - + adminAuth: [] + - + userAuth: [] + parameters: [] /rf/devices: get: operationId: GetCommandsRepoAvailableDevices