Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Add missing API types#62797

Merged
chrsmith merged 2 commits into
mainfrom
chrsmith/add-api-types
May 20, 2024
Merged

Add missing API types#62797
chrsmith merged 2 commits into
mainfrom
chrsmith/add-api-types

Conversation

@chrsmith

@chrsmith chrsmith commented May 20, 2024

Copy link
Copy Markdown
Contributor

Adds the REST API types for the Team Invites and Team Members sections. This isn't used by anything yet, but will be part of updating the Mange AuthenticatedCodyManageTeamPage page to use the API client hook.

NOTE: I didn't add this in this PR because I'm trying to tease out my local branch into separate PRs. But here's the relevant update to the Client type, so that you can call the endpoints that read/write these data types.

...
export module Client {
    // Invites

    export function getTeamInvites(): Call<types.ListTeamInvitesResponse> {
        return { method: 'GET', urlSuffix: '/team/current/invites' }
    }

    export function createTeamInvite(requestBody: types.CreateTeamInviteRequest): Call<types.TeamInvite> {
        return { method: 'POST', urlSuffix: '/team/current/invites', requestBody }
    }

    // This endpoint is to be called by a team admin, for convenience since the
    // current team ID may not be known.
    export function cancelCurrentTeamInvite(inviteId: string): Call<void> {
        return { method: 'POST', urlSuffix: `/team/current/invites/${inviteId}/cancel` }
    }

    export function getInvite(teamId: string, inviteId: string): Call<types.TeamInvite> {
        return { method: 'GET', urlSuffix: `/team/${teamId}/invites/${inviteId}` }
    }

    export function acceptInvite(teamId: string, inviteId: string): Call<void> {
        return { method: 'GET', urlSuffix: `/team/${teamId}/invites/${inviteId}/accept` }
    }

    export function cancelTeamInvite(teamId: string, inviteId: string): Call<void> {
        return { method: 'GET', urlSuffix: `/team/${teamId}/invites/${inviteId}/cancel` }
    }

    // Members

    export function getCurrentTeamMembers(): Call<types.ListTeamMembersResponse> {
        return { method: 'GET', urlSuffix: '/team/current/members' }
    }

    export function updateTeamMembers(requestBody: types.UpdateTeamMembersRequest): Call<void> {
        return { method: 'PATCH', urlSuffix: '/team/current/members', requestBody }
    }

    ...

Test Plan

CI/CD

@vdavid vdavid left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@chrsmith chrsmith enabled auto-merge (squash) May 20, 2024 19:00
@chrsmith chrsmith merged commit 49b99e6 into main May 20, 2024
@chrsmith chrsmith deleted the chrsmith/add-api-types branch May 20, 2024 19:01
error?: string

sentAt: Date
acceptedAt?: Date

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we going parse API response as JSON to TeamInvite (or structure including it), should this and other similar fields be of type string, WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these should be string. This was a mistake on my part.

On the Golang side these are time.Time, which end up getting marshaled as an ISO-8601 string. So the types defined here are just wrong.

When using the GraphQL / Apollo library, IIRC it converts times to Dates automatically. (Or maybe it was an extension or custom configuration step or something?)

Anyways, it seems like we would want these data types to match 100% what is sent across the wire. (And not introduce any shim or wrapper later that will automatically convert string to Date.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants