Implementation of API

Last week, I finished integrating the API into the React website. This API will establish a data link between the database and the system. At first, I didn’t realize the APIprovided by my colleagues had many methods such as getByIdAsync, getListAsync, updateAsync, deleteAsync, and createAsync. In my development, I only used getListAsync for displaying purposes. I did not concentrate on using the API to create, update, and delete entities. However, the getListAsync method will not return information about a specific customer. I need to use getByIdAsync to view all of the data for a single customer. For example, the addresses types were missing from getAsync but were present in getByIdAsync. Thus, I need to use all the methods for the customer page.

When the system was first being developed, I struggled with the create new customer and modify an existing customer. It’s because they’ll be using the same module to display the data. I used to just pass the length of the array as the ID of a new customer, but I changed my mind. When setting the value, I will now pass the ID as undefined to the module and/or method. Because the react hook form requires the use of setValue when passing data to the module, I used the “||” to determine the data’s existence. When getByIdAsync returns an undefined Id, I setValue to null and convert this file into a create customer form.

Aside from that, the provided API lacks of customer types yet includes the address name and address remark. Following Mr. Peter’s clarification, I should revise the customer page prototype to include the address name and address remark instead. Fortunately, these minor changes are straightforward; I only need to add two new text boxes to the address column. Furthermore, I successfully  eliminate the duplicate code. The code was now shorter, and fewer files were required for each page.

By the end of the week, I couldn’t connect to the API’s POST function. I informed Mr. Peter and will resolve the issue within the next week. I believe that the customer page will be completed within the next week, at which point I will embark on the journey of creating the main page. I only have one month to finish the main pages, and I’m hoping to finish them before the internship ends.

Leave a Reply