Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Update to master (#182)
Browse files Browse the repository at this point in the history
* Fix types error for api-controller and demoDataSetup (#169)

* fix types error for api-controller and demoDataSetup

* handle undefined connectionPromise

* Fix compilation error
  • Loading branch information
paolobueno committed Nov 8, 2017
1 parent 8a6366e commit 384f5b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion cloud/wfm-rest-api/src/impl/ApiController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as express from 'express';
import { NextFunction, Request, RequestHandler, Response, Router } from 'express';
import { ApiError } from '../data-api/ApiError';
import { defaultPaginationEngine } from '../data-api/MongoPaginationEngine';
import { PageResponse } from '../data-api/PageResponse';
import { PagingDataRepository } from '../data-api/PagingDataRepository';
import * as errorCodes from './ErrorCodes';

Expand Down Expand Up @@ -172,7 +173,8 @@ export class ApiController<T> {
return router;
}

private buildExpressHandler(handlerFn: (this: this, req: Request) => Bluebird<T | T[] | undefined>): RequestHandler {
private buildExpressHandler(handlerFn: (this: this, req: Request) =>
Bluebird<PageResponse<T> | T | T[] | undefined| null>): RequestHandler {
return (req, res, next) => handlerFn.bind(this)(req)
.then((data: T | T[] | undefined) => data ? res.json(data) : res.status(204).end())
.catch(next);
Expand Down
22 changes: 13 additions & 9 deletions demo/server/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { connect as syncConnector } from './datasync/Connector';
import { init as initKeycloak } from './keycloak';
import { init as authInit } from './passport-auth';
import globalSessionOptions from './session/RedisSession';
import {StaticUsersRepository} from './wfm-user/StaticUsersRepository';
import { StaticUsersRepository } from './wfm-user/StaticUsersRepository';

const config = appConfig.getConfig();

Expand Down Expand Up @@ -58,11 +58,11 @@ function userApiSetup(app: express.Router) {
}

function setupPassportSecurity(app: express.Router, sessionOptions?: SessionOptions) {
return authInit(app, sessionOptions);
return authInit(app, sessionOptions);
}

function setupKeycloakSecurity(app: express.Router) {
return initKeycloak(app);
return initKeycloak(app);
}

function syncSetup(app: express.Router) {
Expand All @@ -79,8 +79,6 @@ function syncSetup(app: express.Router) {
return syncConnector().then(function(connections: { mongo: Db, redis: any }) {
getLogger().info('Sync started');
return connections.mongo;
}).catch(function(err: any) {
getLogger().error('Failed to initialize sync', err);
});
}

Expand All @@ -90,10 +88,14 @@ function wfmApiSetup(app: express.Router, connectionPromise: Promise<any>) {
const role = config.security.adminRole;
app.use('/api', portalsecurityMiddleware.protect(role));
app.use('/api', api.createWFMRouter());
connectionPromise.then(function(mongo: Db) {
// Fix compilation problem with different version of Db.
api.setDb(mongo as any);
});
if (!connectionPromise) {
getLogger().error('Failed to connect to a database');
} else {
connectionPromise.then(function(mongo: Db) {
// Fix compilation problem with different version of Db.
api.setDb(mongo as any);
});
}
}

function fileStoreSetup(app: express.Router, securityMiddleware: EndpointSecurity) {
Expand All @@ -107,5 +109,7 @@ function demoDataSetup(connectionPromise: Promise<Db>) {
if (config.seedDemoData) {
initData(mongo);
}
}).catch(function() {
getLogger().error('Failed to connect to a database');
});
}

0 comments on commit 384f5b8

Please sign in to comment.