1

In my hyperledger-composer app with angular front-end I want to send a query to the REST server.

query selectEmployeesByProject {
    description: "Select all employees with access to the specified project"
    statement:
        SELECT org.comp.app.Employee
            WHERE (projects CONTAINS [_$project])
                ORDER BY [lastName, firstName]
}

Employee is defined as follows:

participant Employee {
  o String lastName
  o String firstName
  --> Project[] projects optional
}

The http-request that is sent is the following:

this.httpClient.get<any[]>(requestURL, {withCredentials: true});

whereby the request url is the following:

http://localhost:4200/api/queries/selectEmployeesByProject?projects=resource:org.comp.app.Project#project1ID

In the console I get the following error message:

Failed to load resource http://localhost:4200/api/queries/selectEmployeesByProject?projects=resource:org.comp.app.Project#project1ID the server responded with a status of 400 (Bad Request)

Why is the query not working?


In general, httpRequests to the REST-server work in my app. Even other queries work. However, queries with the "CONTAINS" operator (such as the one above) do not work.

Tommy
  • 699
  • 4
  • 11
  • 26

1 Answers1

0

more likely to be

query selectClientsByProjects {
    description: "Select all clients with access to a certain project"
    statement:
        SELECT org.myComp.myApp.Client
            WHERE (projects CONTAINS [_$project])
                ORDER BY [lastName ASC, firstName ASC]
}

Note: At the time of writing - CouchDB does not allow the ORDER BY clause to contain multiple items of different sort direction (obviously not the case above).

Also - not tested but your http call may need to be:

this.http.get('http://localhost:4200/api/queries/selectClientsByProjects?projects=resource:org.myComp.myApp.Project%231')

(%23 is the ASCII for '#')

You can try it out your definition first anyway (eg. without ORDER BY maybe) etc etc. Note: CONTAINS must match one entry ('array contains an element, with complete string match (above), in any element, in that array)

Paul O'Mahony
  • 6,740
  • 1
  • 10
  • 15
  • Thank you for your answer ... I tried all of your tips but, unfortunately, it didn't make a difference – Tommy Jul 09 '18 at 18:04