Skip to content

Commit

Permalink
fix: integrate swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
Kpoke committed May 6, 2023
1 parent 4ed4356 commit b766460
Show file tree
Hide file tree
Showing 16 changed files with 506 additions and 90 deletions.
Binary file added assets/greenstand.webp
Binary file not shown.
53 changes: 53 additions & 0 deletions database/migrations/20230504224144-app-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
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) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};

exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20230504224144-app-config-up.sql');
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) {
return db.runSql(data);
});
};

exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20230504224144-app-config-down.sql');
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) {
return db.runSql(data);
});
};

exports._meta = {
"version": 1
};
53 changes: 53 additions & 0 deletions database/migrations/20230506070828-app-installation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
'use strict';

var dbm;
var type;
var seed;
var fs = require('fs');
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) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};

exports.up = function(db) {
var filePath = path.join(__dirname, 'sqls', '20230506070828-app-installation-up.sql');
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) {
return db.runSql(data);
});
};

exports.down = function(db) {
var filePath = path.join(__dirname, 'sqls', '20230506070828-app-installation-down.sql');
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) {
return db.runSql(data);
});
};

exports._meta = {
"version": 1
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE app_config;
10 changes: 10 additions & 0 deletions database/migrations/sqls/20230504224144-app-config-up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE app_config (
id uuid NOT NULL PRIMARY KEY DEFAULT uuid_generate_v4(),
config_code text NOT NULL UNIQUE,
stakeholder_id uuid NOT NULL REFERENCES stakeholder(id),
capture_flow,
capture_setup_flow,
active boolean DEFAULT true,
created_at timestamptz NOT NULL DEFAULT now(),
updated_at timestamptz NOT NULL DEFAULT now()
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE app_installation;
10 changes: 10 additions & 0 deletions database/migrations/sqls/20230506070828-app-installation-up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CREATE TABLE app_installation(
id uuid NOT NULL PRIMARY KEY DEFAULT uuid_generate_v4(),
wallet varchar NOT NULL,
app_config_id uuid NOT NULL REFERENCES app_config(id),
created_at timestamptz NOT NULL DEFAULT now(),
latest_login_at timestamptz NOT NULL DEFAULT now()
);

CREATE UNIQUE INDEX wallet_app_config
ON app_installation(wallet, app_config_id);
58 changes: 57 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
"express-async-handler": "^1.1.4",
"express-validator": "^6.4.0",
"joi": "^17.4.2",
"joi-to-swagger": "^6.2.0",
"knex": "^0.95.13",
"loglevel": "^1.6.8",
"pg": "^8.7.1",
"swagger-ui-express": "^4.6.3",
"uuid": "^8.2.0"
},
"devDependencies": {
Expand Down
18 changes: 17 additions & 1 deletion server/app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const express = require('express');
const cors = require('cors');
const log = require('loglevel');
const swaggerUi = require('swagger-ui-express');
const { join } = require('path');

const HttpError = require('./utils/HttpError');
const { handlerWrapper, errorHandler } = require('./utils/utils');
const swaggerDocument = require('./handlers/swaggerDoc');
const router = require('./routes');

const app = express();
Expand All @@ -12,7 +16,6 @@ if (process.env.NODE_ENV === 'development') {
app.use(cors());
}


/*
* Check request
*/
Expand All @@ -34,6 +37,19 @@ app.use(
}),
);

const options = {
customCss: `
.topbar-wrapper img {
content:url('../assets/greenstand.webp');
width:80px;
height:auto;
}
`,
explorer: true,
};

app.use('/assets', express.static(join(__dirname, '..', '/assets')));
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options));
app.use(express.urlencoded({ extended: false }));

app.use(express.json());
Expand Down
File renamed without changes.
Loading

0 comments on commit b766460

Please sign in to comment.