Skip to content

Commit 7dccaa0

Browse files
show creds for customer who lastemailsent is credentials or expiring
1 parent a1c557e commit 7dccaa0

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

src/pages/hackshack/f2fhelper/template.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { SEO } from '../../../components';
1010

1111
const Student = (props) => {
1212
const getStudentsApi = `${process.env.GATSBY_WORKSHOPCHALLENGE_API_ENDPOINT}/api/students`;
13+
const getCustomerApi = `${process.env.GATSBY_WORKSHOPCHALLENGE_API_ENDPOINT}/api/customers`;
1314
const [students, setstudents] = useState([]);
1415
const [error, setError] = useState('');
1516
const arr = [];
@@ -20,7 +21,7 @@ const Student = (props) => {
2021
const getToken = () => {
2122
AuthService.login().then(
2223
() => {
23-
getStudents(AuthService.getCurrentUser().accessToken);
24+
getCustomers(AuthService.getCurrentUser().accessToken);
2425
},
2526
(err) => {
2627
console.log('Error: ', err);
@@ -31,18 +32,46 @@ const Student = (props) => {
3132
);
3233
};
3334

34-
const getStudents = (token) => {
35+
// get the details from customers table where lastEmailSent = 'credentials' or 'expiring'
36+
// this customer data will have a studentId
37+
// Make getStudents API call by studentId and display the username and password.
38+
const getCustomers = (token) => {
3539
axios({
3640
method: 'GET',
37-
url: getStudentsApi,
41+
url: getCustomerApi,
3842
headers: { 'x-access-token': token },
3943
})
4044
.then((response) => {
41-
// Map created
42-
response.data.forEach((student) => {
43-
// Check is student is assigned
44-
if (student.assigned) arr.push({ ...student });
45-
});
45+
if (response.data.length) {
46+
response.data.forEach((item) => {
47+
if (
48+
item.lastEmailSent === 'credentials' ||
49+
item.lastEmailSent === 'expiring'
50+
) {
51+
getStudents(token, item.studentId);
52+
}
53+
});
54+
}
55+
})
56+
.catch((err) => {
57+
if (err.response.status === 401) {
58+
AuthService.login().then(() => getToken());
59+
} else {
60+
setError(
61+
'Oops..something went wrong. The HPE Developer team is addressing the problem. Please try again later!',
62+
);
63+
}
64+
});
65+
};
66+
67+
const getStudents = (token, studentId) => {
68+
axios({
69+
method: 'GET',
70+
url: `${getStudentsApi}/${studentId}`,
71+
headers: { 'x-access-token': token },
72+
})
73+
.then((response) => {
74+
arr.push({ ...response.data });
4675
if (arr.length <= 0)
4776
setError('There are currently no active students. Stay tuned!');
4877
setstudents(arr);
@@ -51,7 +80,6 @@ const Student = (props) => {
5180
if (err.response.status === 401) {
5281
AuthService.login().then(() => getToken());
5382
} else {
54-
console.log('catch error', err);
5583
setError(
5684
'Oops..something went wrong. The HPE Developer team is addressing the problem. Please try again later!',
5785
);

0 commit comments

Comments
 (0)