-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ daily logtime module 추가를 통해 logtimeRecords 의 last 지원 범위 증가
- #392
- Loading branch information
Showing
9 changed files
with
167 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { DateRange } from 'src/dateRange/dtos/dateRange.dto'; | ||
|
||
export type UserLogtimeRecordsByDateRangeInput = { | ||
userId: number; | ||
} & DateRange; | ||
|
||
export type UserLogtimeRecordByDateRangeOutput = { | ||
/** | ||
* | ||
* @description %Y-%m Date 형식 | ||
*/ | ||
at: string; | ||
value: number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { DailyLogtimeService } from './dailyLogtime.service'; | ||
import { DailyLogtimeDaoImpl } from './db/dailyLogtime.database.dao'; | ||
import { | ||
dailyLogtimeSchema, | ||
daily_logtimes, | ||
} from './db/dailyLogtime.database.schema'; | ||
|
||
@Module({ | ||
imports: [ | ||
MongooseModule.forFeature([ | ||
{ name: daily_logtimes.name, schema: dailyLogtimeSchema }, | ||
]), | ||
], | ||
providers: [DailyLogtimeService, DailyLogtimeDaoImpl], | ||
exports: [DailyLogtimeService], | ||
}) | ||
// eslint-disable-next-line @typescript-eslint/no-extraneous-class | ||
export class DailyLogtimeModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import type { IntRecord } from 'src/common/models/common.valueRecord.model'; | ||
import type { DateRange } from 'src/dateRange/dtos/dateRange.dto'; | ||
import { DailyLogtimeDaoImpl } from './db/dailyLogtime.database.dao'; | ||
|
||
@Injectable() | ||
export class DailyLogtimeService { | ||
constructor(private readonly dailyLogtimeDao: DailyLogtimeDaoImpl) {} | ||
|
||
async userLogtimeRecordsByDateRange( | ||
userId: number, | ||
{ start, end }: DateRange, | ||
): Promise<IntRecord[]> { | ||
const userLogtimeRecords = | ||
await this.dailyLogtimeDao.userLogtimeRecordsByDateRange({ | ||
userId, | ||
start, | ||
end, | ||
}); | ||
|
||
return userLogtimeRecords.map(({ at, value }) => ({ | ||
at: new Date(at), | ||
value, | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import type { | ||
UserLogtimeRecordsByDateRangeInput, | ||
UserLogtimeRecordByDateRangeOutput, | ||
} from '../dailyLogtime.dto'; | ||
import { InjectModel } from '@nestjs/mongoose'; | ||
import { daily_logtimes } from './dailyLogtime.database.schema'; | ||
import type { Model } from 'mongoose'; | ||
|
||
export type DailyLogtimeDao = { | ||
userLogtimeRecordsByDateRange: ( | ||
args: UserLogtimeRecordsByDateRangeInput, | ||
) => Promise<UserLogtimeRecordByDateRangeOutput[]>; | ||
}; | ||
|
||
@Injectable() | ||
export class DailyLogtimeDaoImpl implements DailyLogtimeDao { | ||
constructor( | ||
@InjectModel(daily_logtimes.name) | ||
private readonly dailyLogtime: Model<daily_logtimes>, | ||
) {} | ||
|
||
async userLogtimeRecordsByDateRange({ | ||
userId, | ||
start, | ||
end, | ||
}: UserLogtimeRecordsByDateRangeInput): Promise< | ||
UserLogtimeRecordByDateRangeOutput[] | ||
> { | ||
return await this.dailyLogtime | ||
.aggregate<UserLogtimeRecordByDateRangeOutput>() | ||
.match({ | ||
userId, | ||
date: { | ||
$gte: start, | ||
$lte: end, | ||
}, | ||
}) | ||
.group({ | ||
_id: { | ||
$dateToString: { | ||
date: '$date', | ||
format: '%Y-%m', | ||
timezone: 'Asia/Seoul', | ||
}, | ||
}, | ||
value: { | ||
$sum: '$value', | ||
}, | ||
}) | ||
.sort({ _id: 1 }) | ||
.project({ | ||
_id: 0, | ||
at: '$_id', | ||
value: 1, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters