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

Fix types error for api-controller and demoDataSetup #169

Merged
merged 2 commits into from
Oct 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion demo/server/src/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function wfmApiSetup(app: express.Router, connectionPromise: Promise<any>) {
});
}

function demoDataSetup(connectionPromise: Promise<Db>) {
function demoDataSetup(connectionPromise: Promise<any>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the promise that's being passed here is really Db | undefined from line 31 I think we should look into where the undefined is coming from, might introduce a bug.

Copy link
Contributor Author

@JameelB JameelB Oct 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's due to the function that's giving back the connectionPromise as that may be void. https://github.com/feedhenry-raincatcher/raincatcher-core/blob/master/demo/server/src/modules/index.ts#L66-L83

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, might be worth it to handle that case in this function, even if it's just erroing out and printing it to the user.

connectionPromise.then(function(mongo: Db) {
if (config.seedDemoData) {
initData(mongo);
Expand Down