vignesh-gupta / jira-clone

https://jira-clone-seven-murex.vercel.app
0 stars 0 forks source link

Task fetching issue with new user #2

Closed vignesh-gupta closed 2 hours ago

vignesh-gupta commented 2 hours ago

Scenario: When a new user logged in, and create a workspace we are seeing below error in terminal.

Route: GET /api/tasks?workspaceId=671b3a70002f53bcfc45 500 in 2324ms

Error:

 [AppwriteException: User with the requested ID could not be found.] {
  name: 'AppwriteException',
  code: 404,
  type: 'user_not_found',
  response: {
  message: 'User with the requested ID could not be found.',
  code: 404,
  type: 'user_not_found',
  version: '1.6.0'
}
}
vignesh-gupta commented 2 hours ago

The project count is 4 even when there is no project in the workspace so seems like it's fetching all the project and members

Log:

{ projects: 4, projectIds: 0, tasks: 0, assigneeIds: 0 }
vignesh-gupta commented 2 hours ago

Code:

      const projects = await databases.listDocuments<Project>(
        DATABASE_ID,
        PROJECTS_ID,
        projectIds.length > 0 ? [Query.contains("$id", projectIds)] : []
      );

Issue: the projectIds length is 0 so there is no query at all and fetch all the project and same goes for members

Solution

      let projects: Models.DocumentList<Project> = {
        documents: [],
        total: 0,
      };

      if (projectIds.length > 0)
        projects = await databases.listDocuments<Project>(
          DATABASE_ID,
          PROJECTS_ID,
          [Query.contains("$id", projectIds)]
        );