Skip to content

Commit 5e51776

Browse files
committed
🧹
1 parent 6348fd2 commit 5e51776

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

site/src/api/api.ts

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,17 @@ const BASE_CONTENT_TYPE_JSON = {
300300
"Content-Type": "application/json",
301301
} as const satisfies HeadersInit;
302302

303-
export type GetTemplateOptions = Readonly<{
303+
export type GetTemplatesOptions = Readonly<{
304304
readonly deprecated?: boolean;
305305
}>;
306306

307+
function normalizeGetTemplatesOptions(
308+
options: GetTemplatesOptions = {},
309+
): Record<string, string> {
310+
const { deprecated = false } = options;
311+
return { deprecated: String(deprecated) };
312+
}
313+
307314
type SearchParamOptions = TypesGen.Pagination & {
308315
q?: string;
309316
};
@@ -626,16 +633,9 @@ class ApiMethods {
626633
};
627634

628635
getTemplates = async (
629-
options?: GetTemplateOptions,
636+
options?: GetTemplatesOptions,
630637
): Promise<TypesGen.Template[]> => {
631-
const params: Record<string, string> = {};
632-
if (options?.deprecated !== undefined) {
633-
// Just want to check if it isn't undefined. If it has
634-
// a boolean value, convert it to a string and include
635-
// it as a param.
636-
params["deprecated"] = String(options.deprecated);
637-
}
638-
638+
const params = normalizeGetTemplatesOptions(options);
639639
const response = await this.axios.get<TypesGen.Template[]>(
640640
`/api/v2/templates`,
641641
{ params },
@@ -649,16 +649,9 @@ class ApiMethods {
649649
*/
650650
getTemplatesByOrganization = async (
651651
organization: string,
652-
options?: GetTemplateOptions,
652+
options?: GetTemplatesOptions,
653653
): Promise<TypesGen.Template[]> => {
654-
const params: Record<string, string> = {};
655-
if (options?.deprecated !== undefined) {
656-
// Just want to check if it isn't undefined. If it has
657-
// a boolean value, convert it to a string and include
658-
// it as a param.
659-
params["deprecated"] = String(options.deprecated);
660-
}
661-
654+
const params = normalizeGetTemplatesOptions(options);
662655
const response = await this.axios.get<TypesGen.Template[]>(
663656
`/api/v2/organizations/${organization}/templates`,
664657
{ params },

0 commit comments

Comments
 (0)