From b11a010b9f6d92d79d2469048db74cf8cbc32b60 Mon Sep 17 00:00:00 2001 From: Viet Nguyen <3805254+vnugent@users.noreply.github.com> Date: Fri, 29 Nov 2024 19:23:21 -0800 Subject: [PATCH] feat: sort ticks by most recent --- src/model/TickDataSource.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/model/TickDataSource.ts b/src/model/TickDataSource.ts index 0444a04..e380be9 100644 --- a/src/model/TickDataSource.ts +++ b/src/model/TickDataSource.ts @@ -103,7 +103,10 @@ export default class TickDataSource extends MongoDataSource { throw new Error('No such user') } // Unfortunately, userIds on ticks are stored as strings not MUUIDs. - return await this.tickModel.find({ userId: userIdObject._id.toUUID().toString() }) + return await this.tickModel + .find({ userId: userIdObject._id.toUUID().toString() }) + .sort({ dateClimbed: -1 }) + .lean() } /** @@ -112,7 +115,10 @@ export default class TickDataSource extends MongoDataSource { * @param climbId climb uuid */ async ticksByUserIdAndClimb (climbId: string, userId?: string): Promise { - return await this.tickModel.find({ ...(userId != null && { userId }), climbId }).sort({ dateClimbed: -1 }).lean() + return await this.tickModel + .find({ ...(userId != null && { userId }), climbId }) + .sort({ dateClimbed: -1 }) + .lean() } static instance: TickDataSource