nishiki-tech / nishiki-frontend

Nishiki is an app for tracking and sharing food inventories within groups for better pantry management.
https://nishiki.tech
MIT License
20 stars 5 forks source link

The type of API response of the generating invitation link is expected to be an object #255

Closed nick-y-ito closed 5 months ago

nick-y-ito commented 6 months ago

Description

In the following code, the data variable is being treated as a string type, although an object was expected. This issue may be attributed to the backend. Once the API issue is resolved, the corresponding frontend code should be updated accordingly.

src/lib/api/group/client/groupApiClient.client.ts

export interface IPutGenerateInvitationLink {
  invitationLinkHash: string;
}

export const putGenerateInvitationLinkHash = async (
  groupId: string,
): Promise<Result<string, string>> => {
  try {
    const data = await request<string>({
      url: BACKEND_API_DOMAIN + '/groups/' + groupId + '?Action=generateInvitationLink',
      method: 'PUT',
    });

    const parsedData = JSON.parse(data) as IPutGenerateInvitationLink;
    return Ok(parsedData.invitationLinkHash);
  } catch (err) {
    if (err instanceof Error) {
    }
    return Err('API response is invalid');
  }
};

Refereces

Notes

-

kanta1207 commented 6 months ago

@nick-y-ito @ShoeheyOt Same issue in "Get a User ID" (auth/me) API. It returns a string, so I will also resolve the problem with JSON.parse() for now. API Reference : https://nishiki-tech.github.io/nishiki-documents/web-api/index.html#tag/auth/paths/~1auth~1me/get

kanta1207 commented 5 months ago

Same issue in "Get a User" (users/{userId}) API. It returns a string, so in here also, I will use JSON.parse() for now.

In addition to that, there's another problem with this API. It's supposed to return

{
  "id": "679adc58-b03a-4fb6-993b-c72404087375",
  "name": "John"
}

but instead, its response has totally different shape from the document.

{
 "status":"OK",
 "statusCode":200,
 "body":  "userId": "679adc58-b03a-4fb6-993b-c72404087375",
  "username": "John"
}}

So not only JSON.parse(), I'm extracting the body from the original response for now.

API reference : https://nishiki-tech.github.io/nishiki-documents/web-api/index.html#tag/user/paths/~1users~1%7BuserId%7D/get