# 25th July Report
## Progress
Time: **09:00**
Event: Entering the lab
---
### Weekly meeting on T2 202 at 09:20
Time: **09:30**
The report can be seen in [here](https://hackmd.io/@muhamadaldy/ByUjX6UGS).
---
### Import services from Student/User App to Repairman App
Time: **13:00**
- List of services that we will use from student/user app to repairman app:
- Dispenser API, get the easy handler to API without define HTTP post and get in multiple page.
- Preference manager, to save/store and get data from local storage.
- Not all the functions inside the Dispenser API will be imported into new one in Repairman App.
---
### Discussion with PWA Teams
Start time: **13:45**
End time: **15:55**
Result:
- Repairman app pages:
- Register page.
- Login page.
- Dashboard page, as home page with 3 segment (next assignment, today assignment, and done).
- Assignment details page, modal page in dashboard page.
- Send report page, can upload picture up to 3.
- Repairman attributes for register:
- Full name
- Company email address
- Password
- Employee ID
- Profile picture
- Email address that repairman use must be the company domain, not allow other than this.
- The main page of Repairman app is Login Page, so after login the repairman can access the dashboard page to see the assignment can he takes.
- Registration workflow:
- Repairman register through the repairman app.
- It need fullname, employee id, email, password, and photo.
- Repaiman click register button.
- Waiting for verification from company.
- Verified by company.
- Company send an email notification to repairman email address.
- Repairman now can use the app.
- API that Mr. Johnny should create for Repairman App:
- Register API for Repairman App.
- Login API for Repairman App.
- Done assignment API.
- Today assignment API.
- Next assignment API.
- POST API for send message that repairman has arrived at location to fix the dispenser.
- POST API for send the finish report.
---
### Function inside the services
Time: **17:10**
- Dispenser API service
```typescript=
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class DispenserAPIService {
// domain used
private domain: string = 'https://smartcampus.et.ntust.edu.tw:5425/';
// constant url List
/* 01 */ private urlGetToken: string = this.domain + 'Login';
/* 02 */ private urlCreateUser: string = this.domain + 'CreateUser';
/* 03 */ private urlUserLogin: string = this.domain + 'UserLogin';
/* 04 */ private urlAssignmentDone: string = this.domain + 'Assignment/Done?Employee_ID=';
/* 05 */ private urlAssignmentNext: string = this.domain + 'Assignment/Next?Employee_ID=';
/* 06 */ private urlAssignmentToday: string = this.domain + 'Assignment/Today?Employee_ID=';
/* 07 */ private urlRepairmanArrived: string = this.domain + 'RepairmanArrived';
/* 08 */ private urlRepairComplete: string = this.domain + 'RepairComplete';
constructor(private http: HttpClient) { }
/**
* This function is for get the token from API.
*
* @returns token This return the token value
*
* @example
*
* eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NTE5NjU1NzksImlhdCI6MTU1MTk2MTk3OSwidXNlciI6InB3YV91c2VyMDAxIn0.PXnfohRsONkwct08w3mV00lHOjeb6JtK2Sje6Ofc16o
*/
async getToken () {
let url = this.urlGetToken;
const postDataToken = {
"UserName": "pwa_user001",
"Password": "password"
};
let token: string = "";
await this.http.post(url, postDataToken).toPromise()
.then((success) => {
token = success['token'];
}, () => {
console.error("Promise rejected: unable to get token!");
})
.catch((e) => {
console.error("Function error: on getToken => " + e);
});
return token;
}
async registerNewUser (fullname: string, email: string, password: string, employee_id: string, photo: any) {
let url = this.urlCreateUser;
}
async loginUser (email: string, password: string) {
let url = this.urlUserLogin;
}
async getAssignmentDone (employee_id: string) {
let url = this.urlAssignmentDone + employee_id;
}
async getAssignmentNext (employee_id: string) {
let url = this.urlAssignmentNext + employee_id;
}
async getAssignmentToday (employee_id: string) {
let url = this.urlAssignmentToday + employee_id;
}
async repairmanHasArrived (employee_id: string, assignment_num: string) {
let url = this.urlRepairmanArrived;
}
async repairmentReport (file: any, employee_id: string, assignment_num: string) {
let url = this.urlRepairComplete;
}
}
```
- This is the example of Dispenser API service for the Repairman App, because of the API still not created (except `getToken()`) so above there only initialize the function and API url need.
- **registerNewUser** function need full name, email, password, employee ID, and photo which get the data from form in front end or HTML code.
- **loginUser** function need email and password, it will take the login process.
- **getAssignmentDone** function need employee ID to get the assignment data that has been done by the corresponding employee.
- **getAssignmentNext** function need employee ID to get the assignment data which has been assigned to the corresponding employee.
- **getAssignmentToday** function need employee ID to get the assignment data which has been assigned to the corresponding employee and should be finished soon or today.
- **repairmanHasArrived** function need employee ID and assignment ID to send data to database that the repairman has arrived at the location of reported dispenser.
- **repairmentReport** function need set files of picture has been uploaded, employee ID, and assignment ID to send a report that the repairment has been completed.
- Preference Manager service
- The reason why this service is being imported to Repairman App because there is login system which need to store the email/session ID of the Repairman App.
- Because it's only need to store and get data then the function being used:
```typescript=
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
@Injectable({
providedIn: 'root'
})
export class PreferenceManagerService {
constructor(private storage: Storage) { }
async getData (key: string) {
return await this.storage.get(key).then((result) => {
return result;
}, () => {
console.error("Promise rejected: unable to get value from: " + key + "!");
return null;
})
.catch((e) => {
console.error("Function error: on getData => " + e);
return null;
});
}
async storeData (key: string, data: any) {
return await this.storage.set(key, data).then(() => {
return true;
}, () => {
console.error("Promise rejected: unable to save value to: " + key + "!");
return false;
})
.catch((e) => {
console.error("Function error: on saveData => " + e);
return false;
});
}
}
```
- When the repairman once logged out, by clicked the logout button, it will store empty string to session ID key.
- Because above so there will be not necessary to have `removeData()` function in order to get rid of the session ID from local storage.
- Local storage of preference will be saved until the browser, PWA is run under browser, is removed, uninstalled, or the storage cleared/reset by clear app data.
---
## Conclusion
- Dispenser API will have function to login, register, get repairman assignment (next, today, and done), send notification when arrived, send report when repairment has complete.
- Repairman can register through the app using company email address and will receive verified account notification by the company.
- Preference manager use to store and get data about session ID, it will store the employee ID and maybe also the email address.
- The API will be created soon and after that the Repairman App can be writen to send and get data.
---
Time: **18:00**
Event: Leaving the lab
###### tags: `on-intern`