File tree 2 files changed +11
-9
lines changed
2 files changed +11
-9
lines changed Original file line number Diff line number Diff line change @@ -138,9 +138,14 @@ export default class PenisCommand implements MessageCommand {
138
138
}
139
139
140
140
async #getOrCreateMeasurement( userToMeasure : User ) : Promise < Penis > {
141
- const recentMeasurement = await penis . fetchRecentMeasurement ( userToMeasure ) ;
142
- if ( recentMeasurement !== undefined ) {
143
- return recentMeasurement ;
141
+ const lastMeasurement = await penis . fetchLastMeasurement ( userToMeasure ) ;
142
+ if ( lastMeasurement !== undefined ) {
143
+ const now = new Date ( ) ;
144
+ const measurement = new Date ( `${ lastMeasurement . measuredAt } Z` ) ;
145
+ // TODO: Make use of temporal lol
146
+ if ( measurement . toISOString ( ) . split ( "T" ) [ 0 ] === now . toISOString ( ) . split ( "T" ) [ 0 ] ) {
147
+ return lastMeasurement ;
148
+ }
144
149
}
145
150
146
151
log . debug ( `No recent measuring of ${ userToMeasure . id } found. Creating Measurement.` ) ;
Original file line number Diff line number Diff line change @@ -26,15 +26,12 @@ export function insertMeasurement(
26
26
. executeTakeFirstOrThrow ( ) ;
27
27
}
28
28
29
- export function fetchRecentMeasurement ( user : User , ctx = db ( ) ) : Promise < Penis | undefined > {
30
- const now = Temporal . Now . instant ( ) ;
31
- const { startOfToday, startOfTomorrow } = getStartAndEndDay ( now ) ;
32
-
29
+ export function fetchLastMeasurement ( user : User , ctx = db ( ) ) : Promise < Penis | undefined > {
33
30
return ctx
34
31
. selectFrom ( "penis" )
35
32
. where ( "userId" , "=" , user . id )
36
- . where ( "measuredAt ", ">=" , startOfToday . toString ( ) )
37
- . where ( "measuredAt" , "<" , startOfTomorrow . toString ( ) )
33
+ . orderBy ( "id ", "desc" )
34
+ . limit ( 1 )
38
35
. selectAll ( )
39
36
. executeTakeFirst ( ) ;
40
37
}
You can’t perform that action at this time.
0 commit comments