Commit 6f931de1 authored by Jean-Philippe Steinmetz's avatar Jean-Philippe Steinmetz
Browse files

ModelRoute.doCount always returns a value

parent cbcb247a
......@@ -27,7 +27,7 @@ export interface RequestWS extends Request {
* @param wss The WebSocketServer server that will be configured for Express.
*/
export default function addWebSocket(app: Application, wss: WebSocketServer): any {
wss.on("connection", (socket: WebSocket, request: RequestWS) => {
wss.on("connection", async (socket: WebSocket, request: RequestWS) => {
// Set the socket onto the request so that the Express handler has access to it
request.websocket = socket;
// We add `.websocket` to the url to let Express know this is a websocket specific request. Any handlers
......@@ -37,7 +37,7 @@ export default function addWebSocket(app: Application, wss: WebSocketServer): an
const response: ServerResponse = new ServerResponse(request);
// Shouldn't need to cast `response` as any here but for some reason compiler isn't liking it
// despite the function declaration clearly accepting the `ServerResponse` type.
app(request, response as any, (err: any) => {
await app(request, response as any, (err: any) => {
// If `wsHandled` is not set to true or an error was thrown then we did not handle the WebSocket request properly.
// Close the connection and exit.
if (err || !request.wsHandled) {
......
......@@ -211,7 +211,7 @@ abstract class ModelRoute<T extends BaseEntity | SimpleEntity> {
if (this.repo instanceof MongoRepository && Array.isArray(searchQuery)) {
searchQuery.push({ $count: "count" });
const result: AggregationCursorResult = await (this.repo as MongoRepository<T>).aggregate(searchQuery).next();
return result;
return result ? result : { count: 0 };
} else {
const result: number = await this.repo.count(searchQuery);
return { count: result };
......
......@@ -82,7 +82,7 @@ describe("Server Tests", () => {
.expectClosed();
});
it.skip("Cannot connect via secured WebSocket [anonymous]", async () => {
it("Cannot connect via secured WebSocket [anonymous]", async () => {
expect(server.isRunning()).toBe(true);
await requestws(server.getServer()).ws('/connect-secure')
.expectClosed();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment