# 19th August 2019
## Progress
Time: **09:20**
Event: Entering the lab
*Note*: Sorry for late, I overslept again on Sunday because two days on Saturday and Sunday the campus had lights out so it hard to do daily activities.
---
### Giving documentation to dispenser API service
Time: **11:30**
- To help my PWA team member and future developer understand our code, I add comment lines for documentation in dispenser API service.
- Why this necessary to be discussed because dispenser API take a core role on project as handler to smart dispenser API other than any services or classes.
- The example of comment lines documentation
- **registerRepairman ()** function
<center>
<img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/47-01.JPG" style="max-width: 400px" />
</center>
<br>
- **repairmentCompleteReport ()** function
<center>
<img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/47-02.JPG" style="max-width: 400px" />
</center>
<br>
- We can see the green code is the comment lines for documentation, in here we put documentation both on function header as briefly description and between the code to explain what happen on this code.
- For function header documentation it should has short description and parameters needed (`@param`), for `@return` and `@example` is optional.
- We can see the full documentation on our Github.
---
### Implement new API to get done, today, and future missions on Home page
Time: **15:36**
- There are changes on API for Home page to get data for each type of missions, or we said about three fragments which they are done mission, today mission, and future mission.
- Before: We get from **getDispenserRepairProblem** API, it still raw and we must filter into same employee ID and has several condition like timestamp.
- After: The API has filtered the data on **Get Repairman Missions API** with employee ID and with some condition, like in **Get Repairman Done Missions API** only fetch data where status is 5 or up means the missions has done.
- In **dispenser-api.service.ts**:
```typescript=
async getAssignmentDone (employee_id: string) {
let url = this.urlGetRepairmanDoneTask + employee_id;
let returnValue = [{}];
await this.http.get(url).toPromise()
.then((result) => {
returnValue = result['Data'];
}, () => {
console.error("Promise rejected: unable to get repairman done missions!");
})
.catch((e) => {
console.error("Function error: on getRepairmanDoneMissions => " + e);
});
return returnValue;
}
async getAssignmentToday (employee_id: string, nowTime: string) {
// get data from RepairCondition
let data = await this.getRepairmanMissions(employee_id);
let returnArray = [];
// for every data will be filtered to get what have been done
for (let i = 0 ; i < data.length ; i++) {
let missionTime = UnitConverter.convertApiTimeToJson(data[i]['RepairCallTime']);
let currentTime = UnitConverter.convertApiTimeToJson(nowTime);
// if data has same day as mission deadline
if (
missionTime['Year'] === currentTime['Year'] &&
missionTime['Month'] === currentTime['Month'] &&
missionTime['DateOfMonth'] === currentTime['DateOfMonth']
) {
let dateCurrentTime = UnitConverter.convertApiTimeToDate(nowTime).getTime();
let dateMissionTime = UnitConverter.convertApiTimeToDate(data[i]['RepairCallTime']).getTime();
// if data is under the deadline time
if (dateCurrentTime <= dateMissionTime) {
// put into data will be returned
returnArray.push(data[i]);
}
}
}
return returnArray;
}
async getAssignmentNext (employee_id: string, nowTime: string) {
// get data from RepairCondition
let data = await this.getRepairmanMissions(employee_id);
let returnArray = [];
// for every data will be filtered to get what have been done
for (let i = 0 ; i < data.length ; i++) {
let missionTime = UnitConverter.convertApiTimeToJson(data[i]['RepairCallTime']);
let currentTime = UnitConverter.convertApiTimeToJson(nowTime);
if (missionTime['Year'] >= currentTime['Year']) {
if (missionTime['Month'] >= currentTime['Month']) {
if (missionTime['DateOfMonth'] > currentTime['DateOfMonth']) {
returnArray.push(data[i]);
}
}
}
}
return returnArray;
}
```
- The main changes is we remove the filter which filtering the data with same employee ID and has status 4 or 5 and up for done missions.
- System for filter by date, like same date for today mission, is still there because Get Repairman Missions not filter for today or future mission.
- Both today and future mission using the same API but different time.
- Tested in Home page result:
<center>
<img src="https://raw.githubusercontent.com/aru1702/images/master/ntust-documentation/47-03.gif" style="max-width: 250px" />
</center>
<br>
- The advantages of this new API for Home page:
- There is API for currently on goind and already done missions.
- The data has been filtered using employee ID and without need to define the device ID, like Get Dispenser Repair Condition.
- Add more attributes:
- Client name
- Client phone number
- Client address
- What are still missing:
- Client contact person, it's different from client name, based on Ms. Annie's mockup:
- Client name: NTUST
- Client contact person: Ms. Fang
- Dispenser number, it's different from the ID or the type, this is still unknown if it's needed to be displayed to repairman or not.
- The rest of work today is keep continue giving the documentation for back end codes.
---
## Conclusion
- Write the documentation for back end code as comment lines, both as function's header and between lines of code, it can help our team member and next developer to understand easier.
- Using the new API which Johnny has created for Home page to fetch repairman's currently on going and already done missions, now Home page has update beside using new API also the system code to adjust with the data.
- Keep continue giving comment lines as documentation on back end code.
---
Time: **18:00**
Event: Leaving the lab
###### tags: `on-intern`