## Description
As per the documentation the where clause must always come before the
order by clause, and the startAfter clause must come after the order by
clause i.e the recommended order : `where clause --> order by --> start
after`. However, the way code was written it applies the where clause
after the startAfter i.e as per the code : `order by --> start after -->
where clause` .
In this PR, we change the logic to make sure we follow the order `where
clause -> order by and startAfter / endBefore` when generating query.
Fixes https://github.com/appsmithorg/appsmith/issues/32604
documentation link. -
https://firebase.google.com/docs/firestore/query-data/query-cursors
Changes were taken from the PR created by @sumitsum here
https://github.com/appsmithorg/appsmith-ee/pull/4001
## Automation
/ok-to-test tags="@tag.Datasource"
### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results -->
> [!TIP]
> 🟢🟢🟢 All cypress tests have passed! 🎉🎉🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/8814737910>
> Commit: 4c7ed97cc1808a537d40682fc0e930cd0e30be70
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8814737910&attempt=1"
target="_blank">Click here!</a>
<!-- end of auto-generated comment: Cypress test results -->
## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
- **Refactor**
- Improved the order of operations in Firestore queries to enhance query
performance and reliability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->