Skip to content

Commit

Permalink
refactor: ♻️ service 에서 model 의 type 을 반환하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jpham005 committed Nov 10, 2023
1 parent 3d7fe54 commit acfca3b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
11 changes: 0 additions & 11 deletions app/src/dailyActivity/dailyActivity.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,3 @@ export type FindDailyActivityRecordInput = {
export type FindDailyActivityRecordOutput =
| DailyLogtimeRecord
| DailyDefaultRecord;

export type FindUserDailyActivityByDateInput = {
userId: number;
start: Date;
end: Date;
};

export type FindUserDailyActivityByDateOutput = {
date: Date;
records: (Omit<DailyLogtimeRecord, 'date'> | DailyDefaultRecord)[];
};
17 changes: 11 additions & 6 deletions app/src/dailyActivity/dailyActivity.service.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { Injectable } from '@nestjs/common';
import type { DateRange } from 'src/dateRange/dtos/dateRange.dto';
import { DateWrapper } from 'src/dateWrapper/dateWrapper';
import type { DailyActivity } from 'src/page/personal/general/models/personal.general.dailyActivity.model';
import { DailyActivityDaoImpl } from './dailyActivity.dao';
import {
DailyActivityType,
type DailyDefaultRecord,
type DailyLogtimeRecord,
type FindUserDailyActivityByDateInput,
type FindUserDailyActivityByDateOutput,
} from './dailyActivity.dto';

@Injectable()
export class DailyActivityService {
constructor(private readonly dailyActivityDao: DailyActivityDaoImpl) {}

async findAllUserDailyActivityByDate(
args: FindUserDailyActivityByDateInput,
): Promise<FindUserDailyActivityByDateOutput[]> {
const records = await this.dailyActivityDao.findAllRecordByDate(args);
userId: number,
{ start, end }: DateRange,
): Promise<DailyActivity[]> {
const records = await this.dailyActivityDao.findAllRecordByDate({
userId,
start,
end,
});

const recordMapByDate = records.reduce((recordMap, record) => {
if (isDailyLogtimeRecord(record)) {
Expand Down Expand Up @@ -44,7 +49,7 @@ export class DailyActivityService {
]);

return recordMap;
}, new Map<number, FindUserDailyActivityByDateOutput['records']>());
}, new Map<number, DailyActivity['records']>());

return Array.from(recordMapByDate.entries())
.sort(([a], [b]) => a - b)
Expand Down
9 changes: 4 additions & 5 deletions app/src/page/personal/general/personal.general.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,10 @@ export class PersonalGeneralResolver {
}

const dailyActivities =
await this.dailyActiviyService.findAllUserDailyActivityByDate({
userId: root.userProfile.id,
start,
end,
});
await this.dailyActiviyService.findAllUserDailyActivityByDate(
root.userProfile.id,
{ start, end },
);

await this.cacheUtilService.set(cacheKey, dailyActivities);

Expand Down

0 comments on commit acfca3b

Please sign in to comment.