Skip to content

Commit

Permalink
feat(sandbox): sonar fix
Browse files Browse the repository at this point in the history
MIGRATION CHANGE:
migration-20210716062747- lint fix

gh-208
  • Loading branch information
yeshamavani committed Aug 25, 2021
1 parent 2f94db1 commit 7f4e9a6
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 56 deletions.
2 changes: 2 additions & 0 deletions sandbox/pubnub-example/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
node_modules/
dist/
coverage/
migrations/
migration.js
.eslintrc.js
28 changes: 13 additions & 15 deletions sandbox/pubnub-example/migrations/20210716062747-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,46 +8,44 @@ var path = require('path');
var Promise;

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function (options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};

exports.up = function(db) {
exports.up = function (db) {
var filePath = path.join(__dirname, 'sqls', '20210716062747-init-up.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
return new Promise(function (resolve, reject) {
fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) {
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
}).then(function (data) {
return db.runSql(data);
});
};

exports.down = function(db) {
exports.down = function (db) {
var filePath = path.join(__dirname, 'sqls', '20210716062747-init-down.sql');
return new Promise( function( resolve, reject ) {
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
return new Promise(function (resolve, reject) {
fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) {
if (err) return reject(err);
console.log('received data: ' + data);

resolve(data);
});
})
.then(function(data) {
}).then(function (data) {
return db.runSql(data);
});
};

exports._meta = {
"version": 1
version: 1,
};
2 changes: 1 addition & 1 deletion sandbox/pubnub-example/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ <h3>API Explorer: <a href="/explorer">/explorer</a></h3>

<footer class="power">
<a href="https://loopback.io" target="_blank">
<img src="https://loopback.io/images/branding/powered-by-loopback/blue/powered-by-loopback-sm.png" />
<img src="https://loopback.io/images/branding/powered-by-loopback/blue/powered-by-loopback-sm.png" alt="loopback-logo" />
</a>
</footer>
</body>
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion sandbox/pubnub-example/src/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class PubnubExampleApplication extends BootMixin(
ssl: true,
logVerbosity: true,
uuid: 'my-app',
apns2Env: 'production',
apns2Env: 'dev',
apns2BundleId: 'com.app.myapp',
});

Expand Down
8 changes: 6 additions & 2 deletions sandbox/pubnub-example/src/controllers/ping.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,17 @@ const PING_RESPONSE: ResponseObject = {
/**
* A simple controller to bounce back http requests
*/
const OK = 200;

export class PingController {
constructor(@inject(RestBindings.Http.REQUEST) private req: Request) {}
constructor(
@inject(RestBindings.Http.REQUEST) private readonly req: Request,
) {}

// Map to `GET /ping`
@authorize({permissions: ['*']})
@get('/ping')
@response(200, PING_RESPONSE)
@response(OK, PING_RESPONSE)
ping(): object {
// Reply with a greeting, the current time, the url, and request headers
return {
Expand Down
3 changes: 2 additions & 1 deletion sandbox/pubnub-example/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {ApplicationConfig, PubnubExampleApplication} from './application';

export * from './application';
const PORT = 3000;

export async function main(options: ApplicationConfig = {}) {
const app = new PubnubExampleApplication(options);
Expand All @@ -18,7 +19,7 @@ if (require.main === module) {
// Run the application
const config = {
rest: {
port: +(process.env.PORT ?? 3000),
port: +(process.env.PORT ?? PORT),
host: process.env.HOST,
// The `gracePeriodForClose` provides a graceful close for http/https
// servers with keep-alive clients. The default value is `Infinity`
Expand Down
4 changes: 2 additions & 2 deletions sandbox/pubnub-example/src/migrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {PubnubExampleApplication} from './application';

export async function migrate(args: string[]) {
const existingSchema = args.includes('--rebuild') ? 'drop' : 'alter';
console.log('Migrating schemas (%s existing schema)', existingSchema);
console.log('Migrating schemas (%s existing schema)', existingSchema); //NOSONAR

const app = new PubnubExampleApplication();
await app.boot();
Expand All @@ -15,6 +15,6 @@ export async function migrate(args: string[]) {
}

migrate(process.argv).catch(err => {
console.error('Cannot migrate database schema', err);
console.error('Cannot migrate database schema', err); //NOSONAR
process.exit(1);
});
9 changes: 6 additions & 3 deletions sandbox/pubnub-example/src/openapi-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ import {PubnubExampleApplication} from './application';
/**
* Export the OpenAPI spec from the application
*/

const PORT = 3000;
const FILESIZE = 2;
async function exportOpenApiSpec(): Promise<void> {
const config: ApplicationConfig = {
rest: {
port: +(process.env.PORT ?? 3000),
port: +(process.env.PORT ?? PORT),
host: process.env.HOST ?? 'localhost',
},
};
const outFile = process.argv[2] ?? '';
const outFile = process.argv[FILESIZE] ?? '';
const app = new PubnubExampleApplication(config);
await app.boot();
await app.exportOpenApiSpec(outFile);
}

exportOpenApiSpec().catch(err => {
console.error('Fail to export OpenAPI spec from the application.', err);
console.error('Fail to export OpenAPI spec from the application.', err); //NOSONAR
process.exit(1);
});

0 comments on commit 7f4e9a6

Please sign in to comment.