Is there a way to consolidate code shared between these two JavaScript methods?
async getAllActiveRooms(ctx: ?ContextType): Promise<RoomType[]> {
//log getAllActiveRooms
return this.i.knex('users_rooms')
.transacting(ctx ? ctx.transaction : null)
.leftJoin('rooms', 'users_rooms.roomId', 'rooms.id')
.select('rooms.*')
.where('active', true);
}
async getActiveRoomsBySessionId(ctx: ?ContextType, sessionId: number): Promise<RoomType[]> {
//log getAllActiveRooms
return this.i.knex('users_rooms')
.transacting(ctx ? ctx.transaction : null)
.leftJoin('rooms', 'users_rooms.roomId', 'rooms.id')
.select('rooms.*')
.where('active', true)
.andWhere('sessionId',sessionId)
}
Any suggestions or advice would be greatly appreciated. Thank you