@@ -3,7 +3,6 @@ import { SeatType } from "../models/seats.model.js";
33import { components } from "@octokit/openapi-types" ;
44import mongoose from 'mongoose' ;
55import { MemberActivityType , MemberType } from 'models/teams.model.js' ;
6- import fs from 'fs' ;
76import adoptionService from './adoption.service.js' ;
87import logger from './logger.js' ;
98
@@ -77,7 +76,7 @@ class SeatsService {
7776 $lte ?: Date ;
7877 } ;
7978 }
80-
79+
8180 const query : SeatQuery = {
8281 assignee : member . _id // This is the MongoDB ObjectId that links to the Member document
8382 } ;
@@ -150,42 +149,32 @@ class SeatsService {
150149 async getSeat ( identifier : string | number , params : { since ?: string ; until ?: string ; org ?: string } = { } ) {
151150 const Seats = mongoose . model ( 'Seats' ) ;
152151 const Member = mongoose . model ( 'Member' ) ;
153-
152+
154153 try {
155- //console.log('========== SEAT LOOKUP START ==========');
156- //console.log(`Looking up seat for identifier: ${identifier}, params:`, JSON.stringify(params));
157-
158- // Force console output to appear immediately
159- process . stdout . write ( '' ) ;
160-
161154 // Determine if identifier is numeric
162155 const isNumeric = ! isNaN ( Number ( identifier ) ) && String ( Number ( identifier ) ) === String ( identifier ) ;
163156 let numericId : number | null = null ;
164-
157+
165158 // If it's a login, look up the ID first
166159 if ( ! isNumeric ) {
167160 // Ensure identifier is treated as string before calling replace
168161 const identifierString = String ( identifier ) ;
169-
162+
170163 try {
171164 // Find the member by login - exact match with explicit type casting
172165 const member = await Member . findOne ( { login : identifierString } ) . lean ( ) as MemberDocument | null ;
173-
166+
174167 if ( ! member ) {
175168 // Try case-insensitive search as a fallback
176169 const regex = new RegExp ( `^${ identifierString . replace ( / [ - / \\ ^ $ * + ? . ( ) | [ \] { } ] / g, '\\$&' ) } $` , 'i' ) ;
177- const memberCaseInsensitive = await Member . findOne ( {
170+ const memberCaseInsensitive = await Member . findOne ( {
178171 login : regex
179172 } ) . lean ( ) as MemberDocument | null ;
180-
181- // Check if we got a document and then safely access properties
182- console . log ( `Case-insensitive search result:` ,
183- memberCaseInsensitive ? `Found ${ memberCaseInsensitive . login } ` : 'Not found' ) ;
184-
173+
185174 if ( ! memberCaseInsensitive ) {
186175 return [ ] ; // Return empty array if no member found
187176 }
188-
177+
189178 // Now TypeScript knows memberCaseInsensitive has these properties
190179 numericId = memberCaseInsensitive . id ;
191180 } else {
@@ -198,29 +187,24 @@ class SeatsService {
198187 } else {
199188 numericId = Number ( identifier ) ;
200189 }
201-
190+
202191 const query : mongoose . FilterQuery < SeatType > = { assignee_id : numericId } ;
203-
192+
204193 if ( params . org ) {
205194 query . org = params . org ;
206195 }
207-
196+
208197 if ( params . since || params . until ) {
209198 query . createdAt = { } ;
210199 if ( params . since ) {
211200 query . createdAt . $gte = new Date ( params . since ) ;
212- // console.log(`Added since filter: ${params.since}`);
213201 }
214202 if ( params . until ) {
215203 query . createdAt . $lte = new Date ( params . until ) ;
216- // console.log(`Added until filter: ${params.until}`);
217204 }
218205 }
219-
220- // console.log(`Final query:`, JSON.stringify(query));
221-
206+
222207 // Execute the query
223- //console.log(`Executing Seats.find() with query`);
224208 const results = await Seats . find ( query )
225209 . sort ( { createdAt : 1 } )
226210 . populate ( {
@@ -230,19 +214,17 @@ class SeatsService {
230214 } )
231215 . lean ( )
232216 . exec ( ) ; // Explicitly call exec()
233-
217+
234218 logger . debug ( `Query complete. Found ${ results ?. length || 0 } seat records` ) ;
235- //console.log('========== SEAT LOOKUP END ==========');
236-
219+
237220 return results || [ ] ;
238-
239221 } catch ( error : unknown ) {
240222 console . error ( '========== SEAT LOOKUP ERROR ==========' ) ;
241223 console . error ( `Error retrieving seat data for ${ identifier } :` , error ) ;
242224 // Safe access to stack property
243225 console . error ( `Stack trace:` , error instanceof Error ? error . stack : 'No stack trace available' ) ;
244226 console . error ( '=======================================' ) ;
245-
227+
246228 // Return empty results rather than throwing error
247229 return [ ] ;
248230 }
@@ -541,8 +523,6 @@ class SeatsService {
541523 . sort ( ( [ dateA ] , [ dateB ] ) => new Date ( dateA ) . getTime ( ) - new Date ( dateB ) . getTime ( ) )
542524 ) ;
543525
544- fs . writeFileSync ( 'sortedActivityDays.json' , JSON . stringify ( sortedActivityDays , null , 2 ) , 'utf-8' ) ;
545-
546526 return sortedActivityDays ;
547527 }
548528
@@ -609,7 +589,7 @@ class SeatsService {
609589 const { org, since, until } = params ;
610590 const limit = typeof params . limit === 'string' ? parseInt ( params . limit ) : ( params . limit || 100 ) ;
611591
612- const match : mongoose . FilterQuery < MemberActivityType > = { } ;
592+ const match : mongoose . FilterQuery < MemberActivityType > = { } ;
613593 if ( org ) match . org = org ;
614594 if ( since || until ) {
615595 match . date = {
0 commit comments