JackHaK / TMF

0 stars 0 forks source link

Proposed Response from webUser API Endpoint #31

Open seanthepottingshed opened 5 years ago

seanthepottingshed commented 5 years ago

@PeteHaK @joshgosselin

When a match is found when registering a user via the api/webUsers API endpoint it would be really helpful if this could then return the following object as the response:

{
    ok            : true, // Server response 200
    webUserExists : true, // Does the webUser exist in Administrate? If so return the following companies array
    companies     : [
        {
            id      : 413,  // Administrate Company Id
            canBook : true, // This webUser can book a course as an employee of the company
            isHr    : true  // This webUser can book a course on behalf of other company employees
        },
        {
            id      : 25,   // Administrate Company Id
            canBook : true, // This webUser can book a course as an employee of the company
            isHr    : false // This webUser can't book a course on behalf of other company employees
        },
       {
            id      : 111,   // Administrate Company Id
            canBook : false, // This webUser can't book a course as an employee of the company
            isHr    : false  // This webUser can't book a course on behalf of other company employees
        }
    ]
}

...if there is an error then return:

{
    ok           : false,                    // Server response 500, or data validation error
    errorMessage : 'Lorem ipsum lorem ipsum' // Error message
}

If the above response can't be provided in realtime ( ie: there is step of validation required in Administrate which then needs to be feed back to the Integration Tier ), then I could provide an API endpoint on the website which would allow this information to be passed to the site using a similar method, eg:

$request = new HttpRequest();
$request->setUrl('http://gta.tps.digital/api/webUsers');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders([
    'Postman-Token' => 'f3a0981d-8428-46e1-9571-4dc24ca82118',
    'cache-control' => 'no-cache',
    'Content-Type'  => 'application/json'
]);

$request->setBody('{
    webUserID : 56,
    companies : [
        {
            id      : 413, 
            canBook : true, 
            isHr    : true
        },
       {
            id      : 25,  
            canBook : true, 
            isHr    : false
       },
       {
            id      : 111,   
            canBook : false, 
            isHr    : false
       }
    ]
}');

try {
    $response = $request->send();
    echo $response->getBody();
} catch (HttpException $ex) {
    echo $ex;
}

Maybe the above call could be performed when inflating the relevant part of the Integration Tier? This would be helpful as I would be able to trigger it myself.

In the above case the webUser would only be able to book Courses as a Private user until such cases as the validation is complete.