Skip to content

Commit

Permalink
Refactor filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
lakshayman committed Sep 26, 2024
1 parent fbbb090 commit 8dd9c5c
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 65 deletions.
File renamed without changes
File renamed without changes.
7 changes: 5 additions & 2 deletions profile-diff/index.html → profile-diff-details/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@
</header>
<div id="toast" class="hidden"></div>
<div class="container"></div>

<script src="/helpers/loadENV.js"></script>
<script src="/profile-diff/constants.js"></script>
<script src="/utils.js"></script>
<script src="/profile-diff/local-utils.js"></script>

<script src="/profile-diff/constants.js"></script>
<script src="/profile-diff/profileDiffDetails.utils.js"></script>
<script src="/profile-diff/profileDiffDetails.apiCalls.js"></script>
<script src="/profile-diff/script.js"></script>
</body>
</html>
40 changes: 40 additions & 0 deletions profile-diff-details/profileDiffDetails.apiCalls.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const getProfileDiff = async (id) => {
try {
const finalUrl = `${API_BASE_URL}/profileDiffs/${id}`;
const res = await fetch(finalUrl, {
credentials: 'include',
method: 'GET',
headers: {
'Content-type': 'application/json',
},
});
if (res.status === 401) {
return { notAuthorized: true };
}
if (res.status === 404) {
return { profileDiffExist: false };
}
return { profileDiffExist: true, ...(await res.json()).profileDiff };
} catch (err) {
throw err;
}
};

const fetchUser = async (userId) => {
try {
const userResponse = await fetch(`${API_BASE_URL}/users?id=${userId}`, {
method: 'GET',
credentials: 'include',
headers: {
'Content-type': 'application/json',
},
});
if (userResponse.status === 404) {
return { userExist: false };
}
const { user } = await userResponse.json();
return { ...user, userExist: true };
} catch (err) {
throw err;
}
};
Original file line number Diff line number Diff line change
@@ -1,44 +1,3 @@
const getProfileDiff = async (id) => {
try {
const finalUrl = `${API_BASE_URL}/profileDiffs/${id}`;
const res = await fetch(finalUrl, {
credentials: 'include',
method: 'GET',
headers: {
'Content-type': 'application/json',
},
});
if (res.status === 401) {
return { notAuthorized: true };
}
if (res.status === 404) {
return { profileDiffExist: false };
}
return { profileDiffExist: true, ...(await res.json()).profileDiff };
} catch (err) {
throw err;
}
};

const fetchUser = async (userId) => {
try {
const userResponse = await fetch(`${API_BASE_URL}/users?id=${userId}`, {
method: 'GET',
credentials: 'include',
headers: {
'Content-type': 'application/json',
},
});
if (userResponse.status === 404) {
return { userExist: false };
}
const { user } = await userResponse.json();
return { ...user, userExist: true };
} catch (err) {
throw err;
}
};

function getDataItem(data, itemName) {
const item = data[itemName];

Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions profile-diffs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@
<div id="profile-diffs" class="profile-diffs"></div>
<div class="virtual"></div>
</div>

<script src="/helpers/loadENV.js"></script>
<script src="/constants.js"></script>
<script src="/profile-diffs/constants.js"></script>
<script src="/utils.js"></script>
<script src="/profile-diffs/local-utils.js"></script>

<script src="/profile-diffs/constants.js"></script>
<script src="/profile-diffs/profileDiffs.utils.js"></script>
<script src="/profile-diffs/profileDiffs.apiCalls.js"></script>
<script src="/profile-diffs/script.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
// Utility functions
const parseProfileDiffParams = (uri, nextPageParamsObject) => {
const urlSearchParams = new URLSearchParams(uri);
for (const [key, value] of urlSearchParams.entries()) {
nextPageParamsObject[key] = value;
}
return nextPageParamsObject;
};

const generateProfileDiffsParams = (nextPageParams, forApi = true) => {
const urlSearchParams = new URLSearchParams();
for (const [key, value] of Object.entries(nextPageParams)) {
if (!value) continue;
urlSearchParams.append(key, value);
}
return `/${
forApi ? 'profileDiffs' : 'profile-diffs'
}?${urlSearchParams.toString()}`;
};

const getProfileDiffs = async (query = {}, nextLink) => {
const finalUrl =
API_BASE_URL +
Expand Down
19 changes: 19 additions & 0 deletions profile-diffs/profileDiffs.utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Utility functions
const parseProfileDiffParams = (uri, nextPageParamsObject) => {
const urlSearchParams = new URLSearchParams(uri);
for (const [key, value] of urlSearchParams.entries()) {
nextPageParamsObject[key] = value;
}
return nextPageParamsObject;
};

const generateProfileDiffsParams = (nextPageParams, forApi = true) => {
const urlSearchParams = new URLSearchParams();
for (const [key, value] of Object.entries(nextPageParams)) {
if (!value) continue;
urlSearchParams.append(key, value);
}
return `/${
forApi ? 'profileDiffs' : 'profile-diffs'
}?${urlSearchParams.toString()}`;
};

0 comments on commit 8dd9c5c

Please sign in to comment.