Skip to content

Commit c7e0899

Browse files
Favourokerrivinit717iamitprakash
authored
fixed getUserApplications to-fetch-latest-application (#2097)
* fixed getUserApplications to-fetch-latest-application * fixed getUserApplications to return most recent --------- Co-authored-by: Vinit khandal <111434418+vinit717@users.noreply.github.com> Co-authored-by: Amit Prakash <34869115+iamitprakash@users.noreply.github.com>
1 parent b00831d commit c7e0899

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

models/applications.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,18 @@ const getApplicationsBasedOnStatus = async (status: string, limit: number, lastD
9191
const getUserApplications = async (userId: string) => {
9292
try {
9393
const applicationsResult = [];
94-
const applications = await ApplicationsModel.where("userId", "==", userId).get();
94+
const applications = await ApplicationsModel.where("userId", "==", userId)
95+
.orderBy("createdAt", "desc")
96+
.limit(1)
97+
.get();
9598

9699
applications.forEach((application) => {
97100
applicationsResult.push({
98101
id: application.id,
99102
...application.data(),
100103
});
101104
});
105+
102106
return applicationsResult;
103107
} catch (err) {
104108
logger.log("error in getting user intro", err);

test/unit/models/application.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe("applications", function () {
4848
});
4949

5050
describe("getUserApplications", function () {
51-
it("should return all the user applications", async function () {
51+
it("should return users most recent application", async function () {
5252
const applications = await ApplicationModel.getUserApplications("kfasdjfkdlfjkasdjflsdjfk");
5353
expect(applications).to.be.a("array");
5454
expect(applications.length).to.be.equal(1);

0 commit comments

Comments
 (0)