-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
external 분리와 함께 필요한 모듈만 import 하도록 수정했습니다. - #189
- Loading branch information
Showing
15 changed files
with
180 additions
and
169 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
This file was deleted.
Oops, something went wrong.
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,70 @@ | ||
import { | ||
Controller, | ||
Get, | ||
Logger, | ||
ParseIntPipe, | ||
Query, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { | ||
ApiBearerAuth, | ||
ApiOperation, | ||
ApiQuery, | ||
ApiResponse, | ||
ApiTags, | ||
} from '@nestjs/swagger'; | ||
import { UserSessionDto } from 'src/auth/dto/user.session.dto'; | ||
import { ExtAuthGuard } from 'src/auth/guard/ext-auth.guard'; | ||
import { User } from 'src/auth/user.decorator'; | ||
import { Cabi42Service } from './cabi42.service'; | ||
import { Cabi42ResponseDto } from './dto/cabi42.response.dto'; | ||
|
||
@ApiTags('Cabi42 전용 API') | ||
@Controller('ext/cabi42') | ||
@ApiBearerAuth() | ||
@UseGuards(ExtAuthGuard) | ||
export class Cabi42Controller { | ||
private logger = new Logger(Cabi42Controller.name); | ||
|
||
constructor(private cabi42Service: Cabi42Service) {} | ||
|
||
/** | ||
* 모든 이용자의 월별 누적 출입시간을 반환합니다. | ||
* | ||
* @returns Cabi42ResponseDto[] | ||
*/ | ||
@ApiOperation({ | ||
summary: '모든 이용자의 월별 체류시간 조회', | ||
description: '모든 이용자의 월별 체류시간을 조회합니다.', | ||
}) | ||
@ApiResponse({ | ||
status: 200, | ||
type: [Cabi42ResponseDto], | ||
description: '조회 성공', | ||
}) | ||
@ApiResponse({ status: 400, description: '잘못된 날짜 입력' }) | ||
@ApiResponse({ status: 401, description: '접근 권한 없음' }) | ||
@ApiResponse({ | ||
status: 500, | ||
description: '서버 내부 에러 (백앤드 관리자 문의 필요)', | ||
}) | ||
@ApiQuery({ | ||
name: 'year', | ||
description: '년도', | ||
required: true, | ||
}) | ||
@ApiQuery({ | ||
name: 'month', | ||
description: '월', | ||
required: true, | ||
}) | ||
@Get('permonth') | ||
async getPerMonth( | ||
@User() user: UserSessionDto, | ||
@Query('year', ParseIntPipe) year: number, | ||
@Query('month', ParseIntPipe) month: number, | ||
): Promise<Cabi42ResponseDto[]> { | ||
this.logger.debug(`@getPerMonth) ${year}-${month} by ${user.login}`); | ||
return await this.cabi42Service.cabi42(year, month); | ||
} | ||
} |
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,23 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { TagLog } from 'src/entities/tag-log.entity'; | ||
import { TagLogRepository } from 'src/tag-log-v1/repository/mysql/tag-log.repository'; | ||
import { TagLogModule2 } from 'src/tag-log-v2/tag-log-v2.module'; | ||
import { UserModule } from 'src/user/user.module'; | ||
import { Cabi42Controller } from './cabi42.controller'; | ||
import { Cabi42Service } from './cabi42.service'; | ||
|
||
const tagLogRepo = { | ||
provide: 'ITagLogRepository', | ||
useClass: TagLogRepository, | ||
}; | ||
|
||
/** | ||
* 24Hane 기능 외 다른 서비스에서 사용하는 외부 API 모듈 | ||
*/ | ||
@Module({ | ||
imports: [UserModule, TagLogModule2, TypeOrmModule.forFeature([TagLog])], | ||
controllers: [Cabi42Controller], | ||
providers: [tagLogRepo, Cabi42Service], | ||
}) | ||
export class Cabi42Module {} |
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, Logger } from '@nestjs/common'; | ||
import { TagLogService } from 'src/tag-log-v2/tag-log-v2.service'; | ||
import { UserService } from 'src/user/user.service'; | ||
import { Cabi42ResponseDto } from './dto/cabi42.response.dto'; | ||
|
||
@Injectable() | ||
export class Cabi42Service { | ||
private logger = new Logger(Cabi42Service.name); | ||
|
||
constructor( | ||
private userService: UserService, | ||
private tagLogService: TagLogService, | ||
) {} | ||
|
||
async cabi42(year: number, month: number): Promise<Cabi42ResponseDto[]> { | ||
this.logger.debug(`@cabi42) check all user of ${year}-${month}`); | ||
// admin을 제외한 모든 유저 | ||
const cadets = await this.userService.getAllIds(false); | ||
|
||
return await Promise.all( | ||
cadets.map((cadet) => | ||
this.getAccumulationInMonthById( | ||
cadet.user_id, | ||
cadet.login, | ||
year, | ||
month, | ||
), | ||
), | ||
); | ||
} | ||
|
||
async findIdByLogin(login: string): Promise<number> { | ||
this.logger.debug(`@findIdByLogin) ${login}`); | ||
return this.userService.findIdByLogin(login); | ||
} | ||
|
||
async getAccumulationInMonthById( | ||
id: number, | ||
login: string, | ||
year: number, | ||
month: number, | ||
): Promise<Cabi42ResponseDto> { | ||
this.logger.debug( | ||
`@cabi42) check user: ${login}(${id}) of ${year}-${month}`, | ||
); | ||
const date = new Date(`${year}-${month}`); | ||
const resultMonth = await this.tagLogService.getAllTagPerMonth(id, date); | ||
const monthAccumationTime = resultMonth.reduce( | ||
(prev, result) => result.durationSecond + prev, | ||
0, | ||
); | ||
return { | ||
id, | ||
login, | ||
monthAccumationTime, | ||
}; | ||
} | ||
} |
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,10 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { UserIdType } from 'src/tag-log-v2/dto/admin/user-id.type'; | ||
|
||
export class Cabi42ResponseDto extends UserIdType { | ||
@ApiProperty({ | ||
description: '월별 누적시간 (초 단위)', | ||
example: 12345, | ||
}) | ||
monthAccumationTime: number; | ||
} |
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...rface/device-info.repository.interface.ts → ...rface/device-info.repository.interface.ts
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
4 changes: 2 additions & 2 deletions
4
...epository/mysql/device-info.repository.ts → ...epository/mysql/device-info.repository.ts
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
Oops, something went wrong.