fix: Make sure we get slug to decide things (#9727)

Co-authored-by: zomars <[email protected]>
This commit is contained in:
Leo Giovanettiandzomars authored and GitHub committed 2023-06-27 20:45:18 +00:00
1 parent b799fdcb7e
commit 467cacb8da
1 file changed
+19 -18
@@ -66,26 +66,27 @@ export const updateHandler = async ({ ctx, input }: UpdateOptions) => {
timeFormat: input.timeFormat,
};
if (
input.slug &&
IS_TEAM_BILLING_ENABLED &&
/** If the team doesn't have a slug we can assume that it hasn't been published yet. */
!prevOrganisation.slug
) {
// Save it on the metadata so we can use it later
data.metadata = {
requestedSlug: input.slug,
};
} else {
data.slug = input.slug;
// If we save slug, we don't need the requestedSlug anymore
const metadataParse = teamMetadataSchema.safeParse(prevOrganisation.metadata);
if (metadataParse.success) {
const { requestedSlug: _, ...cleanMetadata } = metadataParse.data || {};
if (input.slug) {
if (
IS_TEAM_BILLING_ENABLED &&
/** If the team doesn't have a slug we can assume that it hasn't been published yet. */
!prevOrganisation.slug
) {
// Save it on the metadata so we can use it later
data.metadata = {
...cleanMetadata,
requestedSlug: input.slug,
};
} else {
data.slug = input.slug;
// If we save slug, we don't need the requestedSlug anymore
const metadataParse = teamMetadataSchema.safeParse(prevOrganisation.metadata);
if (metadataParse.success) {
const { requestedSlug: _, ...cleanMetadata } = metadataParse.data || {};
data.metadata = {
...cleanMetadata,
};
}
}
}