Skip to content

Commit 35e1f7c

Browse files
committed
chore: update api, refactor get case fields
1 parent 45f0e7e commit 35e1f7c

File tree

3 files changed

+24
-49
lines changed

3 files changed

+24
-49
lines changed

packages/backend/src/apps/gathersg/actions/tag-or-untag-case/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const action: IRawAction = {
2222
description: 'Enter the case uuid you want to tag or untag',
2323
required: true,
2424
variables: true,
25+
singleVariableSelection: true,
2526
},
2627
{
2728
label: 'Tag or untag',

packages/backend/src/apps/gathersg/common/fetch-case-fields.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const fetchCaseFields = async ({
2525
caseTypeUuid: string
2626
}) => {
2727
const { data } = await $.http.get<GatherSGCaseFields>(
28-
`/admin/caseTypes/:caseTypeUuid`,
28+
`/caseTypes/:caseTypeUuid`,
2929
{
3030
urlPathParams: { caseTypeUuid },
3131
},

packages/backend/src/apps/gathersg/dynamic-data/get-case-fields.ts

Lines changed: 22 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -83,66 +83,40 @@ const dynamicData: IDynamicData = {
8383

8484
return processCaseFields(filteredFields)
8585
} else if (caseUuid) {
86+
// account that case uuid can be pasted in the frontend
87+
// and may not always be a variable
88+
let computedCaseUuid = caseUuid as string
89+
8690
if (
8791
typeof caseUuid === 'string' &&
8892
caseUuid.match(`^${VARIABLE_REGEX.source}$`)
8993
) {
9094
// if the case uuid is a variable, we need to compute the value
91-
const computedCaseUuid = await getCaseUuidFromVariable($, caseUuid)
92-
93-
// use the case uuid to fetch the case data to derive the case type uuid
94-
const { data: caseData } = await $.http.get<{ data: GatherSGCase }>(
95-
`/cases/:caseUuid`,
96-
{
97-
urlPathParams: { caseUuid: computedCaseUuid as string },
98-
},
99-
)
100-
101-
const { filteredFields } = await fetchCaseFields({
95+
computedCaseUuid = (await getCaseUuidFromVariable(
10296
$,
103-
caseTypeUuid: caseData.data.type.uuid,
104-
})
105-
return processCaseFields(filteredFields)
97+
caseUuid,
98+
)) as string
10699
}
107100

108-
return {
109-
data: [],
110-
}
111-
}
112-
113-
// BACKWARD COMPATIBILITY: this gets the case fields from the latest case in gathersg
114-
const { data: searchResult } = await $.http.post<{
115-
traceId: string
116-
total: number
117-
data: GatherSGCase[]
118-
}>('/cases/search', {
119-
page: 1,
120-
size: 1,
121-
sort: 'createdAt',
122-
order: 'desc',
123-
})
124-
125-
/**
126-
* No cases found
127-
*/
128-
if (searchResult.data.length === 0) {
129-
return {
130-
data: [],
131-
}
132-
}
101+
// use the case uuid to fetch the case data to derive the case type uuid
102+
const { data: caseData } = await $.http.get<{ data: GatherSGCase }>(
103+
`/cases/:caseUuid`,
104+
{
105+
urlPathParams: { caseUuid: computedCaseUuid },
106+
},
107+
)
133108

134-
const caseFields: object = searchResult.data[0].fields
135-
const updatedCaseFields: { name: string; value: string }[] = []
136-
for (const [field, value] of Object.entries(caseFields)) {
137-
// Right now, we cannot support adding of array of objects as a value so just going to exclude to not cause errors unnecessarily
138-
if (Array.isArray(value)) {
139-
continue
140-
}
141-
updatedCaseFields.push({ name: field, value: field })
109+
const { filteredFields } = await fetchCaseFields({
110+
$,
111+
caseTypeUuid: caseData.data.type.uuid,
112+
})
113+
return processCaseFields(filteredFields)
142114
}
143115

116+
// fallback to return empty array
117+
// user can still manually input the case field
144118
return {
145-
data: updatedCaseFields,
119+
data: [],
146120
}
147121
} catch (error) {
148122
if (error instanceof HttpError) {

0 commit comments

Comments
 (0)