Skip to content

Commit a8ef7b6

Browse files
committed
chore: refactor custom field filter schemas for improved clarity and maintainability
1 parent 26c4a50 commit a8ef7b6

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

src/backlog/customFields.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,20 @@ export type CustomFieldFilterInput =
3333
*/
3434
export function customFieldsToPayload(
3535
customFields: CustomFieldInput[] | undefined
36-
): Record<string, string | number | string[] | number[]| undefined> {
36+
): Record<string, string | number | string[] | number[] | undefined> {
3737
if (customFields == null) {
3838
return {};
3939
}
40-
const result: Record<string, string | number | string[] | number[] | undefined> = {};
40+
const result: Record<
41+
string,
42+
string | number | string[] | number[] | undefined
43+
> = {};
4144

4245
for (const field of customFields) {
43-
if(field.value !== undefined){
46+
if (field.value !== undefined) {
4447
result[`customField_${field.id}`] = field.value;
45-
}
46-
if(field.otherValue !== undefined) {
48+
}
49+
if (field.otherValue !== undefined) {
4750
result[`customField_${field.id}_otherValue`] = field.otherValue;
4851
}
4952
}
@@ -101,11 +104,12 @@ export function customFieldFiltersToPayload(
101104
}
102105
default: {
103106
const exhaustiveCheck: never = field;
104-
throw new Error(`Unsupported custom field filter type: ${exhaustiveCheck}`);
107+
throw new Error(
108+
`Unsupported custom field filter type: ${exhaustiveCheck}`
109+
);
105110
}
106111
}
107112
}
108113

109114
return result;
110115
}
111-

src/tools/addIssue.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,13 @@ const addIssueSchema = buildToolSchema((t) => ({
7979
'The ID of the custom field (e.g., 12345)'
8080
)
8181
),
82-
value: z.union([z.number(), z.array(z.number())]).optional()
83-
.describe("The ID(s) of the custom field item. For single-select fields, provide a number. For multi-select fields, provide an array of numbers representing the selected item IDs."),
84-
otherValue: z
82+
value: z
83+
.union([z.number(), z.array(z.number())])
84+
.optional()
85+
.describe(
86+
'The ID(s) of the custom field item. For single-select fields, provide a number. For multi-select fields, provide an array of numbers representing the selected item IDs.'
87+
),
88+
otherValue: z
8589
.string()
8690
.optional()
8791
.describe(

src/tools/shared/customFieldFiltersSchema.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { z, ZodIssueCode } from 'zod';
22
import { TranslationHelper } from '../../createTranslationHelper.js';
33

4-
export const buildCustomFieldFilterSchema = (
5-
t: TranslationHelper['t']
6-
) => {
4+
export const buildCustomFieldFilterSchema = (t: TranslationHelper['t']) => {
75
const schema = z.discriminatedUnion('type', [
86
z
97
.object({
@@ -66,19 +64,13 @@ export const buildCustomFieldFilterSchema = (
6664
.string()
6765
.optional()
6866
.describe(
69-
t(
70-
'TOOL_CUSTOM_FIELD_FILTER_DATE_MIN',
71-
'Start date (yyyy-MM-dd)'
72-
)
67+
t('TOOL_CUSTOM_FIELD_FILTER_DATE_MIN', 'Start date (yyyy-MM-dd)')
7368
),
7469
max: z
7570
.string()
7671
.optional()
7772
.describe(
78-
t(
79-
'TOOL_CUSTOM_FIELD_FILTER_DATE_MAX',
80-
'End date (yyyy-MM-dd)'
81-
)
73+
t('TOOL_CUSTOM_FIELD_FILTER_DATE_MAX', 'End date (yyyy-MM-dd)')
8274
),
8375
})
8476
.describe(t('TOOL_CUSTOM_FIELD_FILTER_DATE', 'Date custom field filter')),
@@ -103,7 +95,11 @@ export const buildCustomFieldFilterSchema = (
10395
]);
10496

10597
return schema.superRefine((data, ctx) => {
106-
if (data.type === 'numeric' && data.min === undefined && data.max === undefined) {
98+
if (
99+
data.type === 'numeric' &&
100+
data.min === undefined &&
101+
data.max === undefined
102+
) {
107103
ctx.addIssue({
108104
code: ZodIssueCode.custom,
109105
message: t(
@@ -127,4 +123,6 @@ export const buildCustomFieldFilterSchema = (
127123
});
128124
};
129125

130-
export type CustomFieldFilterSchema = ReturnType<typeof buildCustomFieldFilterSchema>;
126+
export type CustomFieldFilterSchema = ReturnType<
127+
typeof buildCustomFieldFilterSchema
128+
>;

src/tools/updateIssue.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,13 @@ const updateIssueSchema = buildToolSchema((t) => ({
112112
'The ID of the custom field (e.g., 12345)'
113113
)
114114
),
115-
value: z.union([z.number(), z.array(z.number())]).optional()
116-
.describe("The ID(s) of the custom field item. For single-select fields, provide a number. For multi-select fields, provide an array of numbers representing the selected item IDs."),
117-
otherValue: z
115+
value: z
116+
.union([z.number(), z.array(z.number())])
117+
.optional()
118+
.describe(
119+
'The ID(s) of the custom field item. For single-select fields, provide a number. For multi-select fields, provide an array of numbers representing the selected item IDs.'
120+
),
121+
otherValue: z
118122
.string()
119123
.optional()
120124
.describe(

0 commit comments

Comments
 (0)