Skip to content

Commit

Permalink
Add detect latest version method to API #138
Browse files Browse the repository at this point in the history
  • Loading branch information
haimkastner committed May 23, 2020
1 parent 93b34c8 commit 61e3133
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
14 changes: 12 additions & 2 deletions backend/src/business-layer/versionsBl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -60,6 +60,16 @@ export class VersionsBl {
};
}

/**
* Whenever the current version is not the latest
*/
public async isVersionNotUpToDate(): Promise<string> {
const latestVersion = await this.getLatestVersionName();
const currentVersionInfo = await this.getCurrentVersion();
return latestVersion === currentVersionInfo.version ? '' : latestVersion;
}


/** Get version update status */
public async getUpdateStatus(): Promise<VersionUpdateStatus> {
return {
Expand Down Expand Up @@ -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}`,
);
}
}
Expand Down
12 changes: 12 additions & 0 deletions backend/src/controllers/versionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,16 @@ export class VersionsController extends Controller {
public async getCurrentVersion(): Promise<VersionInfo> {
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<ErrorResponse>(501, 'Server error')
@Get('is-up-date')
public async isLatestVersion(): Promise<string> {
return await VersionsBlSingleton.isVersionNotUpToDate();
}
}
23 changes: 23 additions & 0 deletions backend/src/routers/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 23 additions & 0 deletions backend/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 61e3133

Please sign in to comment.