# 16th August Report
## Progress
Time: **09:10**
Event: Entering the lab
*Note*: Sorry I'm late, I overslept this time _ _"
---
### Functions update on Repairman App's dispenser API service
Time: **11:30**
- To perform login in Login page and reset account's password through Forgot Password page and Reset Password page, we have known that repairman can use either email address or employee ID.
- Previously we defined two functions: one is for using email address, and the other one is for using employee ID.
- Turns out that if both is defined together, the system still return `true` value means it works even both email address and employee ID were defined.
- For example, the body data form has:
```json=
{
"Email": input__email_or_id,
"EmployeeID": input__email_or_id,
"Password": input__password
}
```
- If `Email` was filled but `EmployeeID` has no value (just "" string) it will works.
- Above is same for `Email` is empty.
- If both input has been filled, even using same value, one of them will be checked as **true** as long as both not invalid.
- So if we put the `Email` with correct email but put the `EmployeeID` with uncorrect ID, and vice versa, it will works.
- But if we put both attributes with incorrect value, like empty or unregistered data, it will return `false` or not works.
- For this, we should combine both functions which using email address and using employee ID for do login on Login page, generate verification code on Forgot Password page, and reset account's password on Reset Password.
- In **dispenser-api.service.ts** for Repairman App:
```typescript=
async loginRepairman (credential: string, password: string) {
let url = this.urlLoginRepairman;
const postBody = {
"Email": credential,
"EmployeeID": credential,
"Password": password
};
return await this.http.post(url, postBody).toPromise()
.then((result) => {
if (result['code'] === 200) {
return 1;
} else {
console.error("Error while log in: " + result['msg']);
return 0;
}
}, () => {
console.error("Promise rejected: unable to login!");
return 0;
})
.catch((e) => {
console.error("Function error: on loginRepairmanUsingEmployeeId => " + e);
return -1;
});
}
async forgotPassword (credential: string) {
let url = this.urlForgotPassword;
const postBody = {
"Email": credential,
"EmployeeID": credential
};
return await this.http.post(url, postBody).toPromise()
.then((result) => {
if (result['code'] === 200) {
return 1;
} else {
console.error("Error while send reset password request: " + result['msg']);
return 0;
}
}, () => {
console.error("Promise rejected: unable to send reset password request!");
return 0;
})
.catch((e) => {
console.error("Function error: on forgotPasswordUsingEmployeeId => " + e);
return -1;
});
}
async resetPassword (credential: string, newPassword: string, reNewPassword: string, verifCode: string) {
let url = this.urlResetPassowrd;
let token: string = "";
let returnValue = {
"RepsondNum": -1,
"Message": "Null message."
}
try {
token = await this.getToken();
} catch (e) {
console.error("Function error: on resetPassword while getToken => " + e);
returnValue = {
"RepsondNum": -1,
"Message": "There is an error from server, please try again later!"
};
}
if (newPassword !== reNewPassword) {
returnValue = {
"RepsondNum": 0,
"Message": "Password not match!"
};
} else {
const postBody = {
"Email": credential,
"EmployeeID": credential,
"Password": newPassword,
"VerificationCode": verifCode
};
let httpOption = await {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': token
})
};
await this.http.post(url, postBody, httpOption).toPromise()
.then((result) => {
if (result['code'] === 200) {
returnValue = {
"RepsondNum": 1,
"Message": "Your account password has successfully reset!"
};
} else {
returnValue = {
"RepsondNum": -1,
"Message": "There is an error from server, please try again later!"
};
}
}, () => {
console.error("Promise rejected: unable to reset password!");
returnValue = {
"RepsondNum": -1,
"Message": "The Email/Employee ID does not exist or Verification Code is not valid"
};
})
.catch((e) => {
console.error("Function error: on resetPassword => " + e);
returnValue = {
"RepsondNum": -1,
"Message": "There is an error from server, please try again later!"
};
});
}
return returnValue;
}
```
- For example in **line 5-9**, we can see that both `Email` and `EmployeeID` attribute are present and both using the same value, named `credential`.
- This `credential` is input from page which only using one input but can handle both parameters.
- We can see the other example in **line 33-36** and **line 82-87**.
---
### Add documentations and functions to Repairman App's services and classes
Time: **15:28**
- Add functions into dispenser API service:
- Get repairman missions which hasn't done or still on going.
- Get repairman missions which has DONE.
- Post when the repairment has done with result and pictures.
- Post when repairman has arrived in place and ready to fix the problem.
- In **dispenser-api.service.ts**:
```typescript=
async getRepairmanMissions (employee_id: string) {
let url = this.urlGetRepairmanTask + employee_id;
let returnValue = [{}];
await this.http.get(url).toPromise()
.then((result) => {
returnValue = result['Data'];
}, () => {
console.error("Promise rejected: unable to get repairman missions!");
})
.catch((e) => {
console.error("Function error: on getRepairmanMissions => " + e);
});
return returnValue;
}
async getRepairmanDoneMissions (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 repairmanHasArrived (mission_num: number) {
let url = this.urlRepairmanArrived;
const postBody = {
"MissionNumber": mission_num
};
return await this.http.post(url, postBody).toPromise()
.then((success) => {
return 1;
}, () => {
console.error("Promise rejected: unable to update repairman arrived status!");
return 0;
})
.catch((e) => {
console.error("Function error: on repairmanHasArrived => " + e);
return -1;
});
}
async repairmentCompleteReport (file: any, mission_num: number, description: string) {
let url = this.urlCompleteMission;
let formdataOnComplete = new FormData();
for (let i = 0; i < file.length; i++) {
formdataOnComplete.append('File', file[i]);
}
formdataOnComplete.append('MissionNumber', String(mission_num));
formdataOnComplete.append('Result', description);
return await this.http.post<any>(url, formdataOnComplete).toPromise()
.then((result) => {
if (result['code'] === 200) {
return true;
} else {
console.error("Error while sending report: " + result['msg']);
return false;
}
}, () => {
console.error("Promise rejected: unable to sending report!");
return false;
})
.catch((e) => {
console.error("Function error: on repairmentCompleteReport => " + e);
return false;
});
}
```
- The API itself has been tested using Postman and works.
- Ian who works on Report Repair page will test the `repairmentCompleteReport()` function.
---
## Conclusion
- Update the functions for Login page, Forgot Password page, and Reset Password page in dispenser API service so using either email address or employee ID will using the same function.
- Add more functions into dispenser api service: 1) to get repairman on going missions, 2) get repairman done missions, 3) post done repairment, and 4) post repairman has arrived.
---
Time: **18:03**
Event: Leaving the lab
###### tags: `on-intern`