Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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: 2 additions & 2 deletions src/controllers/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ export type ResultBuildingContext = QueryBuildingContext;
// approach that the express typings seem to use, so I imagine it's safe enough.
export type QueryTransformNoReq = {
// tslint:disable-next-line callable-types
(first: RunnableQuery): RunnableQuery;
(first: RunnableQuery): RunnableQuery | Promise<RunnableQuery>;
};

export type QueryTransformWithReq = {
// tslint:disable-next-line callable-types
(first: ServerReq, second: RunnableQuery): RunnableQuery;
(first: ServerReq, second: RunnableQuery): RunnableQuery | Promise<RunnableQuery>;
};

export type RequestOpts = {
Expand Down
11 changes: 11 additions & 0 deletions test/app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ export default database.then(function(dbModule) {
})
);

app.get('/request-with-async-transform/:type(people)/:id(42)',
Front.customAPIRequest({
queryTransform: (query: RunnableQuery) =>
Promise.resolve(
query.resultsIn(undefined, () => ({
document: new Document({})
}))
)
})
);

// Apply a query transform that returns a custom error
app.get('/request-that-errors/:type(people)/:id(42)',
Front.customAPIRequest({
Expand Down
8 changes: 8 additions & 0 deletions test/integration/custom-query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ describe("Customizing the Query", () => {
});
});

it("should rceive an empty response from an async query transform without error", () => {
return Agent.request("GET", "/request-with-async-transform/people/42")
.accept("application/vnd.api+json")
.then((res) => {
expect(res).to.be.ok
});
});

it("should run the resultingIn transform to create a custom error", () => {
return Agent.request("GET", "/request-that-errors/people/42")
.accept("application/vnd.api+json")
Expand Down