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 unit #13

Open franck-boullier opened 5 years ago

franck-boullier commented 5 years ago

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

The Payload needed by the MEFE API:

{
    "actionType": "EDIT_UNIT",
    "requestorUserId": "R4vBD6BZRCNx8JwnM",
    "unitId": "FuFMO1O1ISXPmwtMB",
    "creatorId": "R4vBD6BZRCNx8JwnM",
    "type": "Hotel",
    "name": "Unit test yyyyyy",
    "moreInfo": "More info",
    "streetAddress": "123 asdjdsj",
    "city": "Singapore",
    "state": "---",
    "zipCode": "11111111",
    "country": "Singapore"
}

Example response:

{
    "timestamp": "2019-03-28T02:54:02.345Z"
}

The Payload generated by the SQL via Lambda:

{
    "updateUnitRequestId": 1,
    "actionType": "EDIT_UNIT",
    "requestorUserId": "R4vBD6BZRCNx8JwnM",
    "unitId": "FuFMO1O1ISXPmwtMB",
    "creatorId": "R4vBD6BZRCNx8JwnM",
    "type": "Hotel",
    "name": "Unit test yyyyyy",
    "moreInfo": "More info",
    "streetAddress": "123 asdjdsj",
    "city": "Singapore",
    "state": "---",
    "zipCode": "11111111",
    "country": "Singapore"
}

The SQL to run after the API returns a success:

SET @update_unit_request_id = `updateUnitRequestId` ;
SET @updated_datetime = `timestamp` ;  [(the SQL formatted timestamp of the reply from the MEFE API)]
CALL `ut_update_success_mefe_unit`;

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

kaihendry commented 5 years ago

I'm getting from @nbiton MEFE Unrecognized actionType EDIT_UNIT btw in the dev environment.

kaihendry commented 5 years ago

This depends on https://github.com/unee-t/frontend/commit/613354464d5c3d2dbc8bf85f5b5b2cd4465bd2ff and it's not deployed yet due to my mistake.

kaihendry commented 5 years ago

There is an issue with https://github.com/unee-t/frontend/commit/613354464d5c3d2dbc8bf85f5b5b2cd4465bd2ff in the sense that is doesn't allow updateUnitRequestId.

kaihendry commented 5 years ago

Ok, it should now be working, the error is "No unit found for unitId FuFMO1O1ISXPmwtMB, but I am assuming that's because of the payload.

franck-boullier commented 5 years ago

This does not work as intended - Re-opening

The test:

The payload:

{"city": "Singapore", "name": "Seahill - 119 - Updated", "type": "Condominium", "state": null, "unitId": "ytso09kIqPu9wON64", "country": "Singapore", "zipCode": "126777", "moreInfo": "Seahill is a 99-Year Leasehold Condominium located at 119, West Coast Crescent, 126777 in District 05. It comprises of 338 Units. Seahill is close to Clementi MRT (EW23). It is completed in 2016. Schools close to Seahill include Farrer Park Primary School, Saint Joseph’s Institution Junior and Stamford Primary School.\r\n\r\nFacilities in Seahill\r\n\r\nFacilities at Seahill include Sky Pool, Water Feature with Sunken Planter, 50M Lap Pool, Spa Island, Kids Pool, Dining Pavilion, Spa Pool, Massage Pavilion and Lounge Deck, Aqua Gym, Sea Mist Spa Pool, Function Deck, Meeting Pavilion, Jogging Track, Outdoor Fitness, Children Playground, Viewing Pavilion, Fitness Balcony and Plunge Pool.\r\n\r\nAmenities near Seahill\r\n\r\nResidents at Seahill can get to nearby supermarkets or shopping mall within the area for an array of amenities such as grocery and retail shopping, bank, eateries and more.\r\n\r\nSeahill is near to NTUC Fairprice, Cold Storage and Sheng Siong Supermarket. It is also close to West Coast Plaza.\r\n\r\nVehicle owners can take West Coast Highway, Clementi Road and Ayer Rajah Expressway (AYE) to get to the business hub or shopping district in the city. ", "creatorId": "hF4AxDx6r6ue2TgFD", "actionType": "EDIT_UNIT", "streetAddress": "119 West Coast Crescent  \n", "requestorUserId": "MEFE API - Create Unit", "updateUnitRequestId": 1047}

Expected result:

kaihendry commented 5 years ago

What env are you testing with? https://case.demo.unee-t.com/ ?

franck-boullier commented 5 years ago

Still not working as it should...

The test:

Expected Result:

The payload:

{"city": "Singapore", "name": "One North Updated - K", "type": "Condominium", "state": null, "unitId": "EOlSJMSdx8Hfx5D6Y", "country": "Singapore", "zipCode": "138642", "moreInfo": null, "creatorId": "YYeAutqzDY3MeqbNC", "actionType": "EDIT_UNIT", "streetAddress": "7 One North Gate Way \n", "requestorUserId": "MEFE API - Create Unit", "updateUnitRequestId": 1054}

@kaihendry, any insight?

kaihendry commented 5 years ago

Initially I had issue with the carriage return in the street address oddly. But this is the error requestorUserId MEFE API - Create Unit is not allowed to edit unit EOlSJMSdx8Hfx5D6Y from the logs:

/aws/lambda/alambda_simple {"fields":{},"level":"info","timestamp":"2019-04-01T07:56:32.454480044Z","message":"Posting to: https://case.dev.unee-t.com/api/process-api-payload?accessToken=secret, payload {\"city\":\"Singapore\",\"name\":\"One North Updated - K\",\"type\":\"Condominium\",\"state\":null,\"unitId\":\"EOlSJMSdx8Hfx5D6Y\",\"country\":\"Singapore\",\"zipCode\":\"138642\",\"moreInfo\":null,\"creatorId\":\"YYeAutqzDY3MeqbNC\",\"actionType\":\"EDIT_UNIT\",\"streetAddress\":\"7 One North Gate Way\",\"requestorUserId\":\"MEFE API - Create Unit\",\"updateUnitRequestId\":1054}"}
/aws/lambda/alambda_simple {"fields":{},"level":"info","timestamp":"2019-04-01T07:56:32.533256372Z","message":"Response code 403, Body: \"requestorUserId MEFE
API - Create Unit is not allowed to edit unit EOlSJMSdx8Hfx5D6Y\""}
nbiton commented 5 years ago

This JSON payload is messed up. "requestorUserId" shoyld be an ID. Of a user. Definitely not "MEFE API - Create Unit"

franck-boullier commented 5 years ago

This JSON payload is messed up. "requestorUserId" shoyld be an ID. Of a user. Definitely not "MEFE API - Create Unit"

Ah! yep I need to fix that...