Skip to content

fix: update template with noop returned undefined template #11688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 19, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
use null over undefined
null is more explicit, and harder to make occur by mistake.
  • Loading branch information
Emyrk committed Jan 19, 2024
commit 799f4a9596bf78152cf0be44155ff5206da21a49
11 changes: 7 additions & 4 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,19 @@ export const unarchiveTemplateVersion = async (templateVersionId: string) => {
return response.data;
};

// updateTemplateMeta will return "undefined" if there is no change to the template.
// A noop returns a "Not Modified" (304) response.
export const updateTemplateMeta = async (
templateId: string,
data: TypesGen.UpdateTemplateMeta,
): Promise<TypesGen.Template | undefined> => {
const response = await axios.patch<TypesGen.Template | undefined>(
): Promise<TypesGen.Template | null> => {
const response = await axios.patch<TypesGen.Template>(
`/api/v2/templates/${templateId}`,
data,
);
// On 304 response there is no data payload.
if (response.status === 304) {
return null;
}

return response.data;
};

Expand Down