Commit dd987d7 1 parent 5c0538e commit dd987d7 Copy full SHA for dd987d7
File tree 4 files changed +20
-20
lines changed
4 files changed +20
-20
lines changed Original file line number Diff line number Diff line change 55
55
inner join " exif" on " a" ." id" = " exif" ." assetId"
56
56
)
57
57
select
58
- (
59
- (now() at time zone ' UTC' )::date - (" localDateTime" at time zone ' UTC' )::date
60
- ) / 365 as " yearsAgo" ,
58
+ date_part(
59
+ ' year' ,
60
+ (" localDateTime" at time zone ' UTC' )::date
61
+ )::int as " year" ,
61
62
json_agg(" res" ) as " assets"
62
63
from
63
64
" res"
Original file line number Diff line number Diff line change @@ -192,7 +192,7 @@ export class AssetRepository {
192
192
}
193
193
194
194
@GenerateSql ( { params : [ DummyValue . UUID , { day : 1 , month : 1 } ] } )
195
- getByDayOfYear ( ownerIds : string [ ] , { day, month } : MonthDay ) : Promise < DayOfYearAssets [ ] > {
195
+ getByDayOfYear ( ownerIds : string [ ] , { day, month } : MonthDay ) {
196
196
return this . db
197
197
. with ( 'res' , ( qb ) =>
198
198
qb
@@ -239,16 +239,12 @@ export class AssetRepository {
239
239
. select ( ( eb ) => eb . fn . toJson ( eb . table ( 'exif' ) ) . as ( 'exifInfo' ) ) ,
240
240
)
241
241
. selectFrom ( 'res' )
242
- . select (
243
- sql < number > `((now() at time zone 'UTC')::date - ("localDateTime" at time zone 'UTC')::date) / 365` . as (
244
- 'yearsAgo' ,
245
- ) ,
246
- )
242
+ . select ( sql < number > `date_part('year', ("localDateTime" at time zone 'UTC')::date)::int` . as ( 'year' ) )
247
243
. select ( ( eb ) => eb . fn . jsonAgg ( eb . table ( 'res' ) ) . as ( 'assets' ) )
248
244
. groupBy ( sql `("localDateTime" at time zone 'UTC')::date` )
249
245
. orderBy ( sql `("localDateTime" at time zone 'UTC')::date` , 'desc' )
250
246
. limit ( 10 )
251
- . execute ( ) as any as Promise < DayOfYearAssets [ ] > ;
247
+ . execute ( ) ;
252
248
}
253
249
254
250
@GenerateSql ( { params : [ [ DummyValue . UUID ] ] } )
Original file line number Diff line number Diff line change @@ -38,12 +38,15 @@ export class AssetService extends BaseService {
38
38
const userIds = [ auth . user . id , ...partnerIds ] ;
39
39
40
40
const groups = await this . assetRepository . getByDayOfYear ( userIds , dto ) ;
41
- return groups . map ( ( { yearsAgo, assets } ) => ( {
42
- yearsAgo,
43
- // TODO move this to clients
44
- title : `${ yearsAgo } year${ yearsAgo > 1 ? 's' : '' } ago` ,
45
- assets : assets . map ( ( asset ) => mapAsset ( asset , { auth } ) ) ,
46
- } ) ) ;
41
+ return groups . map ( ( { year, assets } ) => {
42
+ const yearsAgo = DateTime . utc ( ) . year - year ;
43
+ return {
44
+ yearsAgo,
45
+ // TODO move this to clients
46
+ title : `${ yearsAgo } year${ yearsAgo > 1 ? 's' : '' } ago` ,
47
+ assets : assets . map ( ( asset ) => mapAsset ( asset as AssetEntity , { auth } ) ) ,
48
+ } ;
49
+ } ) ;
47
50
}
48
51
49
52
async getStatistics ( auth : AuthDto , dto : AssetStatsDto ) {
Original file line number Diff line number Diff line change @@ -45,18 +45,18 @@ export class MemoryService extends BaseService {
45
45
for ( const [ userId , userIds ] of Object . entries ( userMap ) ) {
46
46
const memories = await this . assetRepository . getByDayOfYear ( userIds , target ) ;
47
47
48
- for ( const memory of memories ) {
49
- const data : OnThisDayData = { year : target . year - memory . yearsAgo } ;
48
+ for ( const { year , assets } of memories ) {
49
+ const data : OnThisDayData = { year } ;
50
50
await this . memoryRepository . create (
51
51
{
52
52
ownerId : userId ,
53
53
type : MemoryType . ON_THIS_DAY ,
54
54
data,
55
- memoryAt : target . minus ( { years : memory . yearsAgo } ) . toISO ( ) ,
55
+ memoryAt : target . set ( { year } ) . toISO ( ) ,
56
56
showAt,
57
57
hideAt,
58
58
} ,
59
- new Set ( memory . assets . map ( ( { id } ) => id ) ) ,
59
+ new Set ( assets . map ( ( { id } ) => id ) ) ,
60
60
) ;
61
61
}
62
62
}
You can’t perform that action at this time.
0 commit comments