Skip to content

Commit a8977e0

Browse files
authored
Merge pull request #598 from ardourApeX/bugFix/edge-case-for-self-api
Bug : Fixed crashing issue
2 parents 2aad7d0 + 8de2a0d commit a8977e0

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

extension-requests/local-utils.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,12 @@ const addSpinner = (container) => {
252252
return removeSpinner;
253253
};
254254

255+
/**
256+
Generates a formatted date-time string from milliseconds.*
257+
@param {number} milliseconds - The number of milliseconds since January 1, 1970 00:00:00 UTC.
258+
@returns {string} The formatted date-time string in the format 'YYYY-MM-DDTHH:mm'.
259+
260+
*/
255261
function dateTimeString(milliseconds) {
256262
const date = new Date(milliseconds);
257263
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(

extension-requests/script.js

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,7 @@ async function createExtensionCard(data) {
685685
});
686686
const payloadForLog = {
687687
body: {},
688-
meta: {
689-
extensionRequestId: data.id,
690-
name: `${currentUserDetails.first_name} ${currentUserDetails?.last_name}`,
691-
userId: currentUserDetails.id,
692-
},
688+
meta: {},
693689
timestamp: {
694690
_seconds: Date.now() / 1000,
695691
},
@@ -699,6 +695,11 @@ async function createExtensionCard(data) {
699695
const removeSpinner = addSpinner(rootElement);
700696
rootElement.classList.add('disabled');
701697
payloadForLog.body.status = Status.APPROVED;
698+
payloadForLog.meta = {
699+
extensionRequestId: data.id,
700+
name: `${currentUserDetails?.first_name} ${currentUserDetails?.last_name}`,
701+
userId: currentUserDetails?.id,
702+
};
702703
updateExtensionRequestStatus({
703704
id: data.id,
704705
isDev,
@@ -730,6 +731,11 @@ async function createExtensionCard(data) {
730731
const removeSpinner = addSpinner(rootElement);
731732
rootElement.classList.add('disabled');
732733
payloadForLog.body.status = Status.DENIED;
734+
payloadForLog.meta = {
735+
extensionRequestId: data.id,
736+
name: `${currentUserDetails?.first_name} ${currentUserDetails?.last_name}`,
737+
userId: currentUserDetails?.id,
738+
};
733739
updateExtensionRequestStatus({
734740
id: data.id,
735741
isDev,
@@ -881,8 +887,8 @@ async function createExtensionCard(data) {
881887
},
882888
meta: {
883889
extensionRequestId: data.id,
884-
name: `${currentUserDetails.first_name} ${currentUserDetails?.last_name}`,
885-
userId: currentUserDetails.id,
890+
name: `${currentUserDetails?.first_name} ${currentUserDetails?.last_name}`,
891+
userId: currentUserDetails?.id,
886892
},
887893
timestamp: {
888894
_seconds: Date.now() / 1000,
@@ -1061,17 +1067,21 @@ function checkIfPreviouslyRendered(id, logType, log, parentClassName) {
10611067
const alreadyRenderdLogs = renderLogRecord[id] || [];
10621068
let sentence = '';
10631069
let text = '';
1070+
let name = 'You';
1071+
if (parentClassName === 'server-log') {
1072+
name = `${
1073+
log?.meta?.userId === currentUserDetails?.id
1074+
? 'You'
1075+
: log?.meta?.name || 'Super User'
1076+
}`;
1077+
}
10641078
switch (logType) {
10651079
case 'REVIEW': {
10661080
const updationTime = dateDiff(
10671081
Date.now(),
10681082
secondsToMilliSeconds(log?.timestamp?._seconds),
10691083
);
1070-
text = `${
1071-
log?.meta?.userId === currentUserDetails.id
1072-
? 'You'
1073-
: log?.meta?.name || 'Super User'
1074-
} ${log.body.status} this request ${updationTime} ago.`;
1084+
text = `${name} ${log.body.status} this request ${updationTime} ago.`;
10751085

10761086
sentence = `
10771087
<div class="log-div ${parentClassName}">
@@ -1085,11 +1095,7 @@ function checkIfPreviouslyRendered(id, logType, log, parentClassName) {
10851095
break;
10861096
}
10871097
case 'ETA': {
1088-
text = `${
1089-
log?.meta?.userId === currentUserDetails.id
1090-
? 'You'
1091-
: log?.meta?.name || 'Super User'
1092-
} changed the ETA from ${fullDateString(
1098+
text = `${name} changed the ETA from ${fullDateString(
10931099
secondsToMilliSeconds(log.body.oldEndsOn),
10941100
)} to ${fullDateString(secondsToMilliSeconds(log.body.newEndsOn))}.`;
10951101
sentence = `
@@ -1103,13 +1109,7 @@ function checkIfPreviouslyRendered(id, logType, log, parentClassName) {
11031109
break;
11041110
}
11051111
case 'REASON': {
1106-
text = `${
1107-
log?.meta?.userId === currentUserDetails.id
1108-
? 'You'
1109-
: log?.meta?.name || 'Super User'
1110-
} changed the reason from ${log.body.oldReason} to ${
1111-
log.body.newReason
1112-
}.`;
1112+
text = `${name} changed the reason from ${log.body.oldReason} to ${log.body.newReason}.`;
11131113
sentence = `
11141114
<div class="log-div ${parentClassName}">
11151115
<img class="log-img" src="/images/edit-icon.png"></img>
@@ -1120,11 +1120,7 @@ function checkIfPreviouslyRendered(id, logType, log, parentClassName) {
11201120
}
11211121

11221122
case 'TITLE': {
1123-
text = `${
1124-
log?.meta?.userId === currentUserDetails.id
1125-
? 'You'
1126-
: log?.meta?.name || 'Super User'
1127-
} changed the title from ${log.body.oldTitle} to ${log.body.newTitle}.`;
1123+
text = `${name} changed the title from ${log.body.oldTitle} to ${log.body.newTitle}.`;
11281124
sentence = `
11291125
<div class="log-div ${parentClassName}">
11301126
<img class="log-img" src="/images/edit-icon.png"></img>

0 commit comments

Comments
 (0)