From b14e48ea8b65bdd0713b4f9a88e91e752ae99197 Mon Sep 17 00:00:00 2001 From: static Date: Tue, 26 Nov 2024 23:28:53 +0900 Subject: [PATCH] Refactor: convention 2 --- src/modules/auths/login.ts | 2 +- src/modules/ban.ts | 5 --- src/modules/fcm.ts | 72 ++++++++++++++++---------------- src/modules/populates/chats.ts | 4 +- src/modules/populates/reports.ts | 2 +- src/modules/populates/rooms.ts | 31 +++++++------- src/modules/slackNotification.ts | 2 +- src/routes/index.ts | 2 +- src/schedules/index.ts | 5 ++- 9 files changed, 60 insertions(+), 65 deletions(-) diff --git a/src/modules/auths/login.ts b/src/modules/auths/login.ts index a55677b6..962c260f 100644 --- a/src/modules/auths/login.ts +++ b/src/modules/auths/login.ts @@ -1,4 +1,4 @@ -import { type Request } from "express"; +import type { Request } from "express"; import { session as sessionConfig } from "@/loadenv"; import logger from "@/modules/logger"; diff --git a/src/modules/ban.ts b/src/modules/ban.ts index 2a404f27..366e5c54 100644 --- a/src/modules/ban.ts +++ b/src/modules/ban.ts @@ -1,12 +1,7 @@ import type { Request } from "express"; - import logger from "@/modules/logger"; import { banModel } from "./stores/mongo"; -/** - * @param {*} req - * @param {String} service - */ export const validateServiceBanRecord = async ( req: Request, service: string diff --git a/src/modules/fcm.ts b/src/modules/fcm.ts index ae5abf5b..50ee26db 100644 --- a/src/modules/fcm.ts +++ b/src/modules/fcm.ts @@ -7,7 +7,7 @@ import { notificationOptionModel, topicSubscriptionModel, } from "@/modules/stores/mongo"; -import { type ChatType } from "@/types/mongo"; +import type { ChatType } from "@/types/mongo"; /** * credential을 등록합니다. @@ -26,14 +26,14 @@ export const initializeApp = () => { /** * 사용자의 ObjectId와 FCM device token이 주어졌을 때, 해당 deviceToken을 사용자의 토큰으로 DB에 등록합니다. - * @param {string} userId - 사용자의 ObjectId입니다. - * @param {string} deviceToken - 등록하려는 FCM device token입니다. - * @return {Promise>} 변경된 사용자의 deviceToken의 목록 Array를 반환합니다. 오류가 발생하면 빈 배열을 반환합니다. + * @param userId - 사용자의 ObjectId입니다. + * @param deviceToken - 등록하려는 FCM device token입니다. + * @return 변경된 사용자의 deviceToken의 목록 Array를 반환합니다. 오류가 발생하면 빈 배열을 반환합니다. */ export const registerDeviceToken = async ( userId: string, deviceToken: string -): Promise => { +) => { try { // 디바이스 토큰을 다른 사용자가 사용하고 있는지 확인 및 삭제합니다. await deviceTokenModel.updateMany( @@ -67,8 +67,8 @@ export const registerDeviceToken = async ( /** * 사용자의 ObjectId와 FCM device token이 주어졌을 때, 해당 사용자의 해당 deviceToken을 DB에서 삭제합니다. - * @param {string} deviceToken - 삭제하려는 FCM device token입니다. - * @return {Promise} 해당 deviceToken을 가진 모든 사용자로부터 해당 deviceToken을 삭제하는 데 성공하면 true, 하나 이상의 사용자에게서 해당 deviceToken을 삭제하는 데 실패하면 false를 반환합니다. 삭제할 deviceToken이 존재하지 않는 경우에는 true를 반환합니다. + * @param deviceToken - 삭제하려는 FCM device token입니다. + * @return 해당 deviceToken을 가진 모든 사용자로부터 해당 deviceToken을 삭제하는 데 성공하면 true, 하나 이상의 사용자에게서 해당 deviceToken을 삭제하는 데 실패하면 false를 반환합니다. 삭제할 deviceToken이 존재하지 않는 경우에는 true를 반환합니다. */ export const unregisterDeviceToken = async (deviceToken: string) => { try { @@ -95,9 +95,9 @@ export const unregisterDeviceToken = async (deviceToken: string) => { /** * 메시지 전송에 실패한 deviceToken을 DB에서 삭제합니다. - * @param {Array} deviceTokens - 사용자의 ObjectId입니다. - * @param {Array} fcmResponses - 등록하려는 FCM device token입니다. - * @return {Promise>} 각각의 토큰들의 삭제 성공 여부가 저장된 Array를 반환합니다. 해당 토큰을 DB에서 삭제하는 데 성공했으면 true, 아니면 false가 포함됩니다. + * @param deviceTokens - 사용자의 ObjectId입니다. + * @param fcmResponses - 등록하려는 FCM device token입니다. + * @return 각각의 토큰들의 삭제 성공 여부가 저장된 Array를 반환합니다. 해당 토큰을 DB에서 삭제하는 데 성공했으면 true, 아니면 false가 포함됩니다. */ const removeExpiredTokens = async ( deviceTokens: string[], @@ -131,8 +131,8 @@ const removeExpiredTokens = async ( /** * 사용자의 FCM device token이 현재 사용 가능한지 검증합니다. * @summary 해당 디바이스에 dry-run 방식으로 메시지 전송을 시험함으로써 해당 deviceToken이 사용 가능한지 검증합니다. dry-run 시 FCM 서버에는 메시지 전송 요청이 전송되지만, 실제 기기에는 알림이 전송되지 않습니다. - * @param {string} deviceToken - 사용 가능 여부를 확인하려고 하는 FCM device token입니다. - * @return {Promise} 해당 디바이스에 알림을 보낸다는 요청을 FCM 서버에 성공적으로 보냈으면 true, 아니면 false를 반환합니다. + * @param deviceToken - 사용 가능 여부를 확인하려고 하는 FCM device token입니다. + * @return 해당 디바이스에 알림을 보낸다는 요청을 FCM 서버에 성공적으로 보냈으면 true, 아니면 false를 반환합니다. */ export const validateDeviceToken = async (deviceToken: string) => { try { @@ -152,14 +152,14 @@ export const validateDeviceToken = async (deviceToken: string) => { /** * 사용자들의 ObjectId의 배열이 주어졌을 때, 해당 사용자들의 모든 deviceToken을 하나의 Array로 반환합니다. - * @param {Array} userIds - 사용자의 ObjectId로 이루어진 Array입니다. - * @param {Object?} notificationOptions - 특정 알림 설정을 비활성화한 사용자를 필터링하기 위해 사용되는 Object입니다. + * @param userIds - 사용자의 ObjectId로 이루어진 Array입니다. + * @param notificationOptions - 특정 알림 설정을 비활성화한 사용자를 필터링하기 위해 사용되는 Object입니다. * @param {Boolean?} notificationOptions.chatting - true 또는 false로 주어진 경우, 채팅 알림 설정이 각각 true 또는 false로 설정된 사용자들의 deviceToken만 반환합니다. - * @return {Promise>} deviceToken의 Array를 반환합니다. 오류가 발생하면 빈 배열을 반환합니다. + * @return deviceToken의 Array를 반환합니다. 오류가 발생하면 빈 배열을 반환합니다. */ export const getTokensOfUsers = async ( userIds: string[], - notificationOptions: Object = {} + notificationOptions: object = {} ) => { const deviceTokensOfUsers = ( await Promise.all( @@ -187,13 +187,13 @@ export const getTokensOfUsers = async ( /** * 주어진 token들에 메시지 알림을 전송합니다. * TODO: 알림 전송 실패한 토큰 삭제하기 - * @param {Array} tokens - 메시지 알림을 받을 기기의 deviceToken들로 구성된 Array입니다. - * @param {ChatType} type - 메시지 유형으로, "text" | "in" | "out" | "s3img" | "payment" | "settlement" 입니다. - * @param {string} title - 보낼 메시지의 제목입니다. - * @param {string} body - 보낼 메시지의 본문입니다. - * @param {string?} icon - 메시지를 보낸 사람의 프로필 사진 주소입니다. - * @param {string?} link - 메시지 알림 팝업을 클릭했을 때 이동할 주소입니다. - * @return {Promise} 메시지 알림 전송에 실패한 기기의 수를 반환합니다. 오류가 발생하면 -1을 반환합니다. + * @param tokens - 메시지 알림을 받을 기기의 deviceToken들로 구성된 Array입니다. + * @param type - 메시지 유형으로, "text" | "in" | "out" | "s3img" | "payment" | "settlement" 입니다. + * @param title - 보낼 메시지의 제목입니다. + * @param body - 보낼 메시지의 본문입니다. + * @param icon - 메시지를 보낸 사람의 프로필 사진 주소입니다. + * @param link - 메시지 알림 팝업을 클릭했을 때 이동할 주소입니다. + * @return 메시지 알림 전송에 실패한 기기의 수를 반환합니다. 오류가 발생하면 -1을 반환합니다. */ export const sendMessageByTokens = async ( tokens: string[], @@ -237,13 +237,13 @@ export const sendMessageByTokens = async ( /** * 주어진 topic을 구독하고 있는 모든 기기에 메시지 알림을 전송합니다. - * @param {string} topic - 메시지 알림을 보낼 기기들이 구독하고 있는 topic입니다. - * @param {ChatType} type - 메시지 유형으로, "text" | "in" | "out" | "s3img" | "payment" | "settlement" 입니다. - * @param {string} title - 보낼 메시지의 제목입니다. - * @param {string} body - 보낼 메시지의 본문입니다. - * @param {string?} icon - 메시지를 보낸 사람의 프로필 사진 주소입니다. - * @param {string?} link - 메시지 알림 팝업을 클릭했을 때 이동할 주소입니다. - * @return {Promise} 메시지 알림 전송에 성공했으면 true, 아니면 false를 반환합니다. + * @param topic - 메시지 알림을 보낼 기기들이 구독하고 있는 topic입니다. + * @param type - 메시지 유형으로, "text" | "in" | "out" | "s3img" | "payment" | "settlement" 입니다. + * @param title - 보낼 메시지의 제목입니다. + * @param body - 보낼 메시지의 본문입니다. + * @param icon - 메시지를 보낸 사람의 프로필 사진 주소입니다. + * @param link - 메시지 알림 팝업을 클릭했을 때 이동할 주소입니다. + * @return 메시지 알림 전송에 성공했으면 true, 아니면 false를 반환합니다. */ export const sendMessageByTopic = async ( topic: string, @@ -278,9 +278,9 @@ export const sendMessageByTopic = async ( /** * 주어진 사용자를 특정한 topic에 구독시킵니다. - * @param {string} userId - topic을 구독할 사용자의 ObjectId입니다. - * @param {string} topic - 구독할 topic입니다. - * @return {Promise} 토픽 구독에 실패한 기기의 수를 반환합니다. 오류가 발생하면 -1을 반환합니다. + * @param userId - topic을 구독할 사용자의 ObjectId입니다. + * @param topic - 구독할 topic입니다. + * @return 토픽 구독에 실패한 기기의 수를 반환합니다. 오류가 발생하면 -1을 반환합니다. */ export const subscribeUserToTopic = async (userId: string, topic: string) => { try { @@ -329,9 +329,9 @@ export const subscribeUserToTopic = async (userId: string, topic: string) => { /** * 주어진 사용자를 특정한 topic으로부터 구독 해제시킵니다. - * @param {string} userId - topic을 구독 해제할 사용자의 id입니다. - * @param {string} topic - 구독을 해제할 topic입니다. - * @return {Promise} 토픽 구독 해제에 실패한 기기의 수를 반환합니다. 오류가 발생하면 -1을 반환합니다. + * @param userId - topic을 구독 해제할 사용자의 id입니다. + * @param topic - 구독을 해제할 topic입니다. + * @return 토픽 구독 해제에 실패한 기기의 수를 반환합니다. 오류가 발생하면 -1을 반환합니다. */ export const unsubscribeUserFromTopic = async ( userId: string, diff --git a/src/modules/populates/chats.ts b/src/modules/populates/chats.ts index 633dd174..077f7dad 100644 --- a/src/modules/populates/chats.ts +++ b/src/modules/populates/chats.ts @@ -1,6 +1,6 @@ -import { type User, type Chat } from "@/types/mongo"; +import type { User, Chat } from "@/types/mongo"; -/** @constant {{path: string, select: string}[]} +/** * 쿼리를 통해 얻은 Chat Document를 populate할 설정값을 정의합니다. */ export const chatPopulateOption = [ diff --git a/src/modules/populates/reports.ts b/src/modules/populates/reports.ts index a9fe3c9e..6fcf60f3 100644 --- a/src/modules/populates/reports.ts +++ b/src/modules/populates/reports.ts @@ -1,4 +1,4 @@ -import { type User, type Report } from "@/types/mongo"; +import type { User, Report } from "@/types/mongo"; export const reportPopulateOption = [ { diff --git a/src/modules/populates/rooms.ts b/src/modules/populates/rooms.ts index 15f39338..6eb87461 100644 --- a/src/modules/populates/rooms.ts +++ b/src/modules/populates/rooms.ts @@ -1,14 +1,13 @@ -import { - type User, - type SettlementStatus, - type Participant, - type Room, - type Location, +import type { + User, + SettlementStatus, + Participant, + Room, + Location, } from "@/types/mongo"; /** * 쿼리를 통해 얻은 Room Document를 populate할 설정값을 정의합니다. - * @constant {{path: string, select: string, populate?: {path: string, select: string}}[]} */ export const roomPopulateOption = [ { path: "from", select: "_id koName enName" }, @@ -49,12 +48,12 @@ export interface FormattedRoom /** * Room Object가 주어졌을 때 room의 part array의 각 요소를 API 명세에서와 같이 {userId: String, ... , isSettlement: String}으로 가공합니다. * 또한, 방이 현재 출발했는지 유무인 isDeparted 속성을 추가합니다. - * @param {PopulatedRoom} roomObject - 정산 정보를 가공할 room Object로, Mongoose Document가 아닌 순수 Javascript Object여야 합니다. - * @param {Object} options - 추가 파라미터로, 기본값은 {}입니다. - * @param {Boolean} options.includeSettlement - 반환 결과에 정산 정보를 포함할 지 여부로, 기본값은 true입니다. - * @param {Date} options.timestamp - 방의 출발 여부(isDeparted)를 판단하는 기준이 되는 시각입니다. - * @param {Boolean} options.isOver - 방의 완료 여부(isOver)로, 기본값은 false입니다. includeSettlement가 false인 경우 roomDocument의 isOver 속성은 undefined로 설정됩니다. - * @return {FormattedRoom} 정산 여부가 위와 같이 가공되고 isDeparted 속성이 추가된 Room Object가 반환됩니다. + * @param roomObject - 정산 정보를 가공할 room Object로, Mongoose Document가 아닌 순수 Javascript Object여야 합니다. + * @param options - 추가 파라미터로, 기본값은 {}입니다. + * @param options.includeSettlement - 반환 결과에 정산 정보를 포함할 지 여부로, 기본값은 true입니다. + * @param options.timestamp - 방의 출발 여부(isDeparted)를 판단하는 기준이 되는 시각입니다. + * @param options.isOver - 방의 완료 여부(isOver)로, 기본값은 false입니다. includeSettlement가 false인 경우 roomDocument의 isOver 속성은 undefined로 설정됩니다. + * @return 정산 여부가 위와 같이 가공되고 isDeparted 속성이 추가된 Room Object가 반환됩니다. */ export const formatSettlement = ( roomObject: PopulatedRoom, @@ -83,9 +82,9 @@ export const formatSettlement = ( /** * roomPopulateOption을 사용해 populate된 Room Object와 사용자의 id(userId)가 주어졌을 때, 해당 사용자의 정산 상태를 반환합니다. - * @param {PopulatedRoom} roomObject - roomPopulateOption을 사용해 populate된 변환한 Room Object입니다. - * @param {String} userId - 방 완료 상태를 확인하려는 사용자의 id(user.id)입니다. - * @return {Boolean | undefined} 사용자의 해당 방에 대한 완료 여부(true | false)를 반환합니다. 사용자가 참여중인 방이 아닐 경우 undefined를 반환합니다. + * @param roomObject - roomPopulateOption을 사용해 populate된 변환한 Room Object입니다. + * @param userId - 방 완료 상태를 확인하려는 사용자의 id(user.id)입니다. + * @return 사용자의 해당 방에 대한 완료 여부(true | false)를 반환합니다. 사용자가 참여중인 방이 아닐 경우 undefined를 반환합니다. **/ export const getIsOver = (roomObject: PopulatedRoom, userId: string) => { // room document의 part subdoocument에서 사용자 id와 일치하는 정산 정보를 찾습니다. diff --git a/src/modules/slackNotification.ts b/src/modules/slackNotification.ts index bd3b9837..c70cfdb6 100644 --- a/src/modules/slackNotification.ts +++ b/src/modules/slackNotification.ts @@ -1,7 +1,7 @@ import axios from "axios"; import { nodeEnv, slackWebhookUrl as slackUrl } from "@/loadenv"; import logger from "@/modules/logger"; -import { type Report } from "@/types/mongo"; +import type { Report } from "@/types/mongo"; export const sendTextToReportChannel = (text: string) => { if (!slackUrl.report) return; diff --git a/src/routes/index.ts b/src/routes/index.ts index ddbe083a..83bc81dc 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -2,10 +2,10 @@ export { default as adminRouter } from "./admin"; export { default as authRouter } from "./auth"; export { default as chatRouter } from "./chats"; export { default as docsRouter } from "./docs"; +export { default as fareRouter } from "./fare"; export { default as locationRouter } from "./locations"; export { default as logininfoRouter } from "./logininfo"; export { default as notificationRouter } from "./notifications"; export { default as reportRouter } from "./reports"; export { default as roomRouter } from "./rooms"; export { default as userRouter } from "./users"; -export { default as fareRouter } from "./fare"; diff --git a/src/schedules/index.ts b/src/schedules/index.ts index 1908fadd..f714dd61 100644 --- a/src/schedules/index.ts +++ b/src/schedules/index.ts @@ -1,14 +1,15 @@ -import { type Express } from "express"; +import type { Express } from "express"; import cron from "node-cron"; +import { naverMap } from "@/loadenv"; import notifyBeforeDepart from "./notifyBeforeDepart"; import notifyAfterArrival from "./notifyAfterArrival"; import updateMajorTaxiFare from "./updateMajorTaxiFare"; import updateMinorTaxiFare from "./updateMinorTaxiFare"; -import { naverMap } from "@/loadenv"; const registerSchedules = (app: Express) => { cron.schedule("*/5 * * * *", notifyBeforeDepart(app)); cron.schedule("*/10 * * * *", notifyAfterArrival(app)); + if (naverMap.apiId && naverMap.apiKey) { cron.schedule("0,30 * * * * ", updateMajorTaxiFare(app)); cron.schedule("0 18 * * *", updateMinorTaxiFare(app));