Skip to content

Commit

Permalink
Put the similar logic to a util function for now to resolve duplicati…
Browse files Browse the repository at this point in the history
…on error
  • Loading branch information
Ronaldo Macapobre committed Dec 6, 2024
1 parent 2a90be3 commit f7aa722
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 121 deletions.
71 changes: 7 additions & 64 deletions web/src/components/criminal/CriminalFutureAppearances.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,20 @@

<script lang="ts">
import CriminalAppearanceDetails from '@/components/criminal/CriminalAppearanceDetails.vue';
import { beautifyDate } from '@/filters';
import { useCommonStore, useCriminalFileStore } from '@/stores';
import { useCriminalFileStore } from '@/stores';
import { criminalAppearancesListType } from '@/types/criminal';
import { criminalApprDetailType } from '@/types/criminal/jsonTypes';
import { extractCriminalAppearanceInfo } from '@/utils/utils';
import * as _ from 'underscore';
import { computed, defineComponent, onMounted, ref } from 'vue';
import CriminalFutureAppearancesTable from './CriminalFutureAppearancesTable.vue';
enum appearanceStatus {
UNCF = 'Unconfirmed',
CNCL = 'Canceled',
SCHD = 'Scheduled',
}
export default defineComponent({
components: {
CriminalAppearanceDetails,
CriminalFutureAppearancesTable,
},
setup() {
const commonStore = useCommonStore();
const criminalFileStore = useCriminalFileStore();
const futureAppearancesList = ref<criminalAppearancesListType[]>([]);
Expand Down Expand Up @@ -85,67 +78,17 @@
const appearanceDate = jApp.appearanceDt.split(' ')[0];
if (new Date(appearanceDate) < currentDate) return;
const appInfo: criminalAppearancesListType = {
index: index.toString(),
date: appearanceDate,
formattedDate: beautifyDate(appearanceDate),
time: getTime(jApp.appearanceTm.split(' ')[1].substring(0, 5)),
reason: jApp.appearanceReasonCd,
reasonDescription: jApp.appearanceReasonDsc || '',
duration: getDuration(
jApp.estimatedTimeHour,
jApp.estimatedTimeMin
),
location: jApp.courtLocation || '',
room: jApp.courtRoomCd,
firstName: jApp.givenNm || '',
lastName: jApp.lastNm || jApp.orgNm,
accused: getNameOfParticipant(
jApp.lastNm || jApp.orgNm,
jApp.givenNm || ''
),
status: jApp.appearanceStatusCd
? appearanceStatus[jApp.appearanceStatusCd]
: '',
statusStyle: getStatusStyle(
jApp.appearanceStatusCd
? appearanceStatus[jApp.appearanceStatusCd]
: ''
),
presider: jApp.judgeInitials || '',
judgeFullName: jApp.judgeInitials ? jApp.judgeFullNm : '',
appearanceId: jApp.appearanceId,
partId: jApp.partId,
supplementalEquipment: jApp.supplementalEquipmentTxt,
securityRestriction: jApp.securityRestrictionTxt,
outOfTownJudge: jApp.outOfTownJudgeTxt,
profSeqNo: jApp.profSeqNo,
};
const appInfo = extractCriminalAppearanceInfo(
jApp,
index,
appearanceDate
);
futureAppearancesList.value.push(appInfo);
}
);
};
const fetchStoreData = (store, methodName, data) => {
store[methodName](data);
return store[methodName.replace('update', '').toLowerCase()];
};
const getStatusStyle = (status) =>
fetchStoreData(commonStore, 'updateStatusStyle', status);
const getNameOfParticipant = (lastName, givenName) =>
fetchStoreData(commonStore, 'updateDisplayName', {
lastName: lastName,
givenName: givenName,
});
const getTime = (time) => fetchStoreData(commonStore, 'updateTime', time);
const getDuration = (hr, min) =>
fetchStoreData(commonStore, 'updateDuration', { hr: hr, min: min });
const SortedFutureAppearances = computed(
(): criminalAppearancesListType[] => {
if (criminalFileStore.showSections['Future Appearances']) {
Expand Down
64 changes: 7 additions & 57 deletions web/src/components/criminal/CriminalPastAppearances.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@

<script lang="ts">
import CriminalAppearanceDetails from '@/components/criminal/CriminalAppearanceDetails.vue';
import { beautifyDate } from '@/filters';
import { useCommonStore, useCriminalFileStore } from '@/stores';
import { useCriminalFileStore } from '@/stores';
import { criminalAppearancesListType } from '@/types/criminal';
import { criminalApprDetailType } from '@/types/criminal/jsonTypes';
import { extractCriminalAppearanceInfo } from '@/utils/utils';
import * as _ from 'underscore';
import { computed, defineComponent, onMounted, ref } from 'vue';
import CriminalPastAppearancesTable from './CriminalPastAppearancesTable.vue';
Expand All @@ -55,7 +55,6 @@
CriminalPastAppearancesTable,
},
setup() {
const commonStore = useCommonStore();
const criminalFileStore = useCriminalFileStore();
const pastAppearancesList = ref<criminalAppearancesListType[]>([]);
Expand Down Expand Up @@ -86,66 +85,17 @@
const appearanceDate = jApp.appearanceDt.split(' ')[0];
if (new Date(appearanceDate) >= currentDate) return;
const appInfo: criminalAppearancesListType = {
index: index.toString(),
date: appearanceDate,
formattedDate: beautifyDate(appearanceDate),
time: getTime(jApp.appearanceTm.split(' ')[1].substring(0, 5)),
reason: jApp.appearanceReasonCd,
reasonDescription: jApp.appearanceReasonDsc || '',
duration: getDuration(
jApp.estimatedTimeHour,
jApp.estimatedTimeMin
),
location: jApp.courtLocation || '',
room: jApp.courtRoomCd,
firstName: jApp.givenNm || '',
lastName: jApp.lastNm || jApp.orgNm,
accused: getNameOfParticipant(
jApp.lastNm || jApp.orgNm,
jApp.givenNm || ''
),
status: jApp.appearanceStatusCd
? appearanceStatus[jApp.appearanceStatusCd]
: '',
statusStyle: getStatusStyle(
jApp.appearanceStatusCd
? appearanceStatus[jApp.appearanceStatusCd]
: ''
),
presider: jApp.judgeInitials || '',
judgeFullName: jApp.judgeInitials ? jApp.judgeFullNm : '',
appearanceId: jApp.appearanceId,
partId: jApp.partId,
supplementalEquipment: jApp.supplementalEquipmentTxt,
securityRestriction: jApp.securityRestrictionTxt,
outOfTownJudge: jApp.outOfTownJudgeTxt,
profSeqNo: jApp.profSeqNo,
};
const appInfo = extractCriminalAppearanceInfo(
jApp,
index,
appearanceDate
);
pastAppearancesList.value.push(appInfo);
}
);
};
const fetchStoreData = (store, methodName, data) => {
store[methodName](data);
return store[methodName.replace('update', '').toLowerCase()];
};
const getStatusStyle = (status) =>
fetchStoreData(commonStore, 'updateStatusStyle', status);
const getNameOfParticipant = (lastName, givenName) =>
fetchStoreData(commonStore, 'updateDisplayName', {
lastName: lastName,
givenName: givenName,
});
const getTime = (time) => fetchStoreData(commonStore, 'updateTime', time);
const getDuration = (hr, min) =>
fetchStoreData(commonStore, 'updateDuration', { hr: hr, min: min });
const SortedPastAppearances = computed(
(): criminalAppearancesListType[] => {
if (criminalFileStore.showSections['Past Appearances']) {
Expand Down
72 changes: 72 additions & 0 deletions web/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { beautifyDate } from '@/filters';
import { AuthService } from '@/services/AuthService';
import { useCommonStore } from '@/stores';
import { criminalAppearancesListType } from '@/types/criminal';
import { criminalApprDetailType } from '@/types/criminal/jsonTypes';
import { inject } from 'vue';

export const SessionManager = {
Expand Down Expand Up @@ -52,3 +55,72 @@ export const splunkLog = (message) => {
export const getSingleValue = (value: string | string[]): string => {
return Array.isArray(value) ? value[0] : value;
};

export const fetchStoreData = (store, methodName, data) => {
store[methodName](data);
return store[methodName.replace('update', '').toLowerCase()];
};

// This helper function is created to solve duplication errors found by SonarCloud
// Include this as part of refactoring efforts once the pages is re-written
export const extractCriminalAppearanceInfo = (
jApp: criminalApprDetailType,
index: number,
appearanceDate: string
): criminalAppearancesListType => {
enum appearanceStatus {
UNCF = 'Unconfirmed',
CNCL = 'Canceled',
SCHD = 'Scheduled',
}

const commonStore = useCommonStore();

const getStatusStyle = (status) =>
fetchStoreData(commonStore, 'updateStatusStyle', status);

const getNameOfParticipant = (lastName, givenName) =>
fetchStoreData(commonStore, 'updateDisplayName', {
lastName: lastName,
givenName: givenName,
});

const getTime = (time) => fetchStoreData(commonStore, 'updateTime', time);

const getDuration = (hr, min) =>
fetchStoreData(commonStore, 'updateDuration', { hr: hr, min: min });

const appInfo: criminalAppearancesListType = {
index: index.toString(),
date: appearanceDate,
formattedDate: beautifyDate(appearanceDate),
time: getTime(jApp.appearanceTm.split(' ')[1].substring(0, 5)),
reason: jApp.appearanceReasonCd,
reasonDescription: jApp.appearanceReasonDsc ?? '',
duration: getDuration(jApp.estimatedTimeHour, jApp.estimatedTimeMin),
location: jApp.courtLocation ?? '',
room: jApp.courtRoomCd,
firstName: jApp.givenNm || '',
lastName: jApp.lastNm || jApp.orgNm,
accused: getNameOfParticipant(
jApp.lastNm || jApp.orgNm,
jApp.givenNm || ''
),
status: jApp.appearanceStatusCd
? appearanceStatus[jApp.appearanceStatusCd]
: '',
statusStyle: getStatusStyle(
jApp.appearanceStatusCd ? appearanceStatus[jApp.appearanceStatusCd] : ''
),
presider: jApp.judgeInitials || '',
judgeFullName: jApp.judgeInitials ? jApp.judgeFullNm : '',
appearanceId: jApp.appearanceId,
partId: jApp.partId,
supplementalEquipment: jApp.supplementalEquipmentTxt,
securityRestriction: jApp.securityRestrictionTxt,
outOfTownJudge: jApp.outOfTownJudgeTxt,
profSeqNo: jApp.profSeqNo,
};

return appInfo;
};

0 comments on commit f7aa722

Please sign in to comment.