unee-t / lambda2sqs

Relays SQL triggered payloads to MEFE via a queue
https://ap-southeast-1.console.aws.amazon.com/lambda/home?region=ap-southeast-1#/applications/lambda2sqs
GNU Affero General Public License v3.0
0 stars 4 forks source link

MEFE API - Edit a user #12

Closed franck-boullier closed 5 years ago

franck-boullier commented 5 years ago

This describes the MEFE API to edit a Unee-T user. See https://github.com/unee-t/frontend/pull/735 for more details.

The Payload needed by the MEFE API:

{
    "actionType": "EDIT_USER",
    "requestorUserId": "2HPpT3FYjQ2PacskN",
    "userId": "chFmfTz34ahKcSNM9",
    "emailAddress": "nao+91210@example.com",
    "firstName": "Naor",
    "lastName": "Biton",
    "phoneNumber": "80000000",
    "creatorId": "2HPpT3FYjQ2PacskN",
    "bzfeEmailAddress": "nao+91210@example.com"
}

Example response:

{
    "timestamp": "2019-03-22T11:21:41.663Z"
}

The Payload generated by the SQL via Lambda:

{
    "updateUserRequestId": 1,
    "actionType": "EDIT_USER",
    "requestorUserId": "2HPpT3FYjQ2PacskN",
    "userId": "chFmfTz34ahKcSNM9",
    "emailAddress": "nao+91210@example.com",
    "firstName": "Naor",
    "lastName": "Biton",
    "phoneNumber": "80000000",
    "creatorId": "2HPpT3FYjQ2PacskN",
    "bzfeEmailAddress": "nao+91210@example.com"
}

The SQL to run after the API returns a success:

SET @update_user_request_id = `updateUserRequestId` ;
SET @updated_datetime = `timestamp` ;  [(the SQL formatted timestamp of the reply from the MEFE API)]
CALL `ut_update_success_mefe_user`;

@kaihendry Let me know when all is ready on your side (Golang) so I can test end to end.

kaihendry commented 5 years ago

Quickly implemented it, but I get /aws/lambda/alambda_simple {"fields":{},"level":"info","timestamp":"2019-03-26T05:26:05.186608865Z","message":"Response code 400, Body: \"No user found for requestorUserId 2HPpT3FYjQ2PacskN; No user found for user to edit userId chFmfTz34ahKcSNM9; No user found for proposed creatorId 2HPpT3FYjQ2PacskN\""} from MEFE

franck-boullier commented 5 years ago

OK this might be normal... I'll try to do the end to end test now with newly created users...

franck-boullier commented 5 years ago

The Test:

The payload was

{"userId": "tp6uQiYQPyDLFQvF3", "lastName": "Derp", "creatorId": "YYeAutqzDY3MeqbNC", "firstName": "Derpette", "actionType": "EDIT_USER", "phoneNumber": null, "emailAddress": "xxxx@gmail.com", "requestorUserId": "YYeAutqzDY3MeqbNC", "bzfeEmailAddress": "xxxx@gmail.com", "updateUserRequestId": 4}

Other Issues:

franck-boullier commented 5 years ago

Fixed issues:

The AWS notification seems to be sent twice for some reason...

This is now fixed (I updated the lambda triggers...)

Pending issue:

@kaihendry any idea?

kaihendry commented 5 years ago

Please try again

franck-boullier commented 5 years ago

The Test:

Thanks @kaihendry!

franck-boullier commented 5 years ago

I'm closing this as this works.

@nbiton what happens if the email is updated to an email that is already associate to an existing Unee-T user? The BZ side will not allow 2 different BZFE account with the same email address...

I'll open a different issue to discuss what will be the best strategy to handle that.