From 44bc81329541991eee8fce7c52a49e735ce3d4d9 Mon Sep 17 00:00:00 2001 From: niamu01 Date: Wed, 3 Jul 2024 20:31:27 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A0=84=EC=B2=B4=20=EC=9E=85=EC=8B=A4?= =?UTF-8?q?=EC=97=AC=EB=B6=80=20=EC=A1=B0=ED=9A=8C=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=A4=91=20db=EC=A1=B0=ED=9A=8C=20=EB=B0=A9=EB=B2=95=EC=97=90?= =?UTF-8?q?=20=EB=94=B0=EB=A5=B8=20=EC=86=8D=EB=8F=84=20=EB=B9=84=EA=B5=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/external/where42/where42.controller.ts | 6 +++ src/external/where42/where42.service.ts | 63 ++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/src/external/where42/where42.controller.ts b/src/external/where42/where42.controller.ts index 537c2cd..d63c7bf 100644 --- a/src/external/where42/where42.controller.ts +++ b/src/external/where42/where42.controller.ts @@ -64,4 +64,10 @@ export class Where42Controller { this.logger.debug(`@where42All) where42All`); return this.where42Service.where42All(logins); } + + @Post('where42All2') + async where42All2(@Body() logins: string[]): Promise { + this.logger.debug(`@where42All) where42All`); + return this.where42Service.where42All2(logins); + } } diff --git a/src/external/where42/where42.service.ts b/src/external/where42/where42.service.ts index ff14578..fa4c594 100644 --- a/src/external/where42/where42.service.ts +++ b/src/external/where42/where42.service.ts @@ -8,6 +8,7 @@ import { Post, } from '@nestjs/common'; import { ITagLogRepository } from 'src/tag-log/repository/interface/tag-log-repository.interface'; +import { IdLoginDto } from 'src/user/dto/id-login.dto'; import { UserService } from 'src/user/user.service'; import { Where42ResponseDto } from './dto/where42.response.dto'; import { IDeviceInfoRepository } from './repository/interface/device-info.repository.interface'; @@ -72,4 +73,66 @@ export class Where42Service { } return res; } + + @Post('where42All2') + async where42All2(@Body() logins: string[]): Promise { + const users = await this.userService.findUsersByLogins(logins); + const userMap = new Map( + users.map((user) => [user.login, user]), + ); + + const res = []; + + for (const login of logins) { + try { + const user = userMap.get(login); + if (!user) { + throw new BadRequestException('존재하지 않는 유저 ID입니다.'); + } + + const isAdmin = user.is_admin; + + if (isAdmin) { + res.push({ + login, + inoutState: null, + }); + continue; + } + + const cards = await this.userService.findCardsByUserId( + user.user_id, + new Date('2019-01-01 00:00:00'), + new Date(), // NOTE: 대략 42 클러스터 오픈일부터 지금까지 조회 + ); + + const last = await this.tagLogRepository.findLatestTagLog(cards); + if (last === null) { + throw new ForbiddenException('태그 기록이 존재하지 않습니다.'); + } + + const device = await this.deviceInfoRepository.getDeviceInfo( + last.device_id, + ); + if (device === null) { + throw new ForbiddenException( + '등록되지 않은 기기에 태그하였습니다. 관리자에게 문의하세요.', + ); + } + + res.push({ + login, + inoutState: device.inoutState, + }); + } catch (e) { + this.logger.error(`정상적인 조회가 아님: ${login}`); + res.push({ + login, + inoutState: null, + }); + } + } + + return res; + } }