Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor(#424): 강사 - 결제 리팩터링 완료 #514

Merged
merged 3 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,19 @@
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"rootDir": "./test",
"testRegex": "^.*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
"testEnvironment": "node",
"moduleNameMapper": {
"^@src/(.*)$": "<rootDir>/../src/$1",
"^src/(.*)$": "<rootDir>/../src/$1"
}
}
}
5 changes: 5 additions & 0 deletions src/common/interface/common-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@ export interface IPushNotificationMessage {
data: { title: string; body: string; chatRoomId?: string };
token: string;
}

export interface IConvertedDate {
convertedStartDate: Date;
convertedEndDate: Date;
}
6 changes: 6 additions & 0 deletions src/common/types/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ export type ApiOperator<M extends string> = {
ApiOperationOptions,
) => PropertyDecorator;
};

export type PaginatedResponse<T, K extends string = 'items'> = {
[key in K]: T[];
} & {
totalItemCount: number;
};
41 changes: 41 additions & 0 deletions src/common/utils/date.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { IConvertedDate } from '../interface/common-interface';

export class DateUtils {
/**
* 시작 시간과 종료 시간을 반환.
* 빈 값을 넣으면 현재 날짜를 기준으로 00시, 23:59:59:999반환
* @param startDate 시작 시간
* @param endDate 종료 시간
* @returns 시작 시간, 종료 시간
*/
static getUTCStartAndEndOfRange(
startDate?: Date,
endDate?: Date,
): IConvertedDate {
const convertedStartDate = startDate ? new Date(startDate) : new Date();
convertedStartDate.setUTCHours(0, 0, 0, 0); // UTC 기준 시작 시간 설정

const convertedEndDate = endDate
? new Date(endDate)
: new Date(convertedStartDate);
convertedEndDate.setUTCHours(23, 59, 59, 999); // UTC 기준 종료 시간 설정

return { convertedStartDate, convertedEndDate };
}

/**
* 특정 달의 1일과 마지막 일을 반환.
* @param year 연도
* @param month 월 (1월은 0, 12월은 11)
* @returns 시작 시간, 종료 시간
*/
static getUTCStartAndEndOfMonth(year: number, month: number): IConvertedDate {
const convertedStartDate = new Date(Date.UTC(year, month, 1));
convertedStartDate.setUTCHours(0, 0, 0, 0); // UTC 기준 시작 시간 설정

const convertedEndDate = new Date(Date.UTC(year, month + 1, 0));
convertedEndDate.setUTCHours(23, 59, 59, 999); // UTC 기준 종료 시간 설정

return { convertedStartDate, convertedEndDate };
}
}
109 changes: 55 additions & 54 deletions src/payments/controllers/lecturer-payments.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,23 @@ import {
} from '@nestjs/common';
import { LecturerPaymentsService } from '@src/payments/services/lecturer-payments.service';
import { ApiTags } from '@nestjs/swagger';
import { ApiCreateLecturerBankAccount } from '@src/payments/swagger-decorators/create-lecturer-bank-account.decorator';
import { SetResponseKey } from '@src/common/decorator/set-response-meta-data.decorator';
import { GetAuthorizedUser } from '@src/common/decorator/get-user.decorator';
import { ValidateResult } from '@src/common/interface/common-interface';
import { CreateBankAccountDto } from '@src/payments/dtos/create-bank-account.dto';
import { LecturerBankAccountDto } from '@src/payments/dtos/lecturer-bank-account.dto';
import { LecturerAccessTokenGuard } from '@src/common/guards/lecturer-access-token.guard';
import { ApiGetLecturerRecentBankAccount } from '@src/payments/swagger-decorators/get-lecturer-recent-bank-account.decorator';
import { ApiGetPaymentRequestList } from '@src/payments/swagger-decorators/get-payment-request-list.decorator';
import { PaymentRequestDto } from '@src/payments/dtos/payment-request.dto';
import { UpdatePaymentRequestStatusDto } from '@src/payments/dtos/update-payment-request.dto';
import { ApiUpdatePaymentRequestStatus } from '@src/payments/swagger-decorators/update-payment-request-status.decorator';
import { ApiGetPaymentRequestCount } from '@src/payments/swagger-decorators/get-lecturer-payment-request-count.decorator';
import { PassSituationDto } from '@src/payments/dtos/response/pass-situation.dto';
import { ApiGetMyPassSituation } from '@src/payments/swagger-decorators/get-my-pass-situation.decorator';
import { GetRevenueStatisticsDto } from '../dtos/request/get-revenue-statistics.dto';
import { ApiGetRevenueStatistics } from '../swagger-decorators/get-revenue-statistics.decorator';
import { plainToInstance } from 'class-transformer';
import { RevenueStatisticDto } from '../dtos/response/revenue-statistic.dto';
import { GetLecturerPaymentListDto } from '../dtos/request/get-lecturer-payment-list.dto';
import { LecturerPaymentItemDto } from '../dtos/response/lecturer-payment-item.dto';
import { ApiGetLecturerPaymentList } from '../swagger-decorators/get-lecturer-payment-list.decorator';
import { GetTotalRevenueDto } from '../dtos/request/get-total-revenue.dto';
import { ApiGetTotalRevenue } from '../swagger-decorators/get-total-revenue.decorator';
import { ApiLecturerPayments } from './swagger/lecturer-payments.swagger';
import { UpdatePaymentRequestStatusDto } from '../dtos/update-payment-request.dto';
import { PaginatedResponse } from '@src/common/types/type';

@ApiTags('강사-결제')
@UseGuards(LecturerAccessTokenGuard)
Expand All @@ -44,15 +37,12 @@ export class LecturerPaymentsController {
private readonly lecturerPaymentsService: LecturerPaymentsService,
) {}

@ApiGetLecturerPaymentList()
@ApiLecturerPayments.GetLecturerPaymentList({ summary: '판매 내역' })
@Get()
async getLecturerPaymentList(
@GetAuthorizedUser() authorizedData: ValidateResult,
@Query() getLecturerPaymentListDto: GetLecturerPaymentListDto,
): Promise<{
totalItemCount: Number;
lecturerPaymentList: LecturerPaymentItemDto[];
}> {
): Promise<PaginatedResponse<LecturerPaymentItemDto, 'lecturerPaymentList'>> {
const { totalItemCount, lecturerPaymentList } =
await this.lecturerPaymentsService.getLecturerPaymentList(
authorizedData.lecturer.id,
Expand All @@ -68,7 +58,7 @@ export class LecturerPaymentsController {
};
}

@ApiGetTotalRevenue()
@ApiLecturerPayments.GetTotalRevenue({ summary: '총 매출액' })
@SetResponseKey('totalRevenue')
@Get('/total-revenue')
async getTotalRevenue(
Expand All @@ -81,7 +71,7 @@ export class LecturerPaymentsController {
);
}

@ApiGetRevenueStatistics()
@ApiLecturerPayments.GetRevenueStatistics({ summary: '매출 통계' })
@SetResponseKey('revenueStatistics')
@Get('/revenue-statistics')
async getRevenueStatistics(
Expand All @@ -97,7 +87,9 @@ export class LecturerPaymentsController {
return plainToInstance(RevenueStatisticDto, revenueStatistics);
}

@ApiGetLecturerRecentBankAccount()
@ApiLecturerPayments.GetUserRecentBankAccount({
summary: '강사가 최근 등록(사용)한 계좌 조회',
})
@SetResponseKey('lecturerRecentBankAccount')
@Get('/recent-bank-account')
async getUserRecentBankAccount(
Expand All @@ -108,7 +100,9 @@ export class LecturerPaymentsController {
);
}

@ApiCreateLecturerBankAccount()
@ApiLecturerPayments.CreateLecturerBankAccount({
summary: '강사 계좌 등록',
})
@SetResponseKey('createdLecturerBankAccount')
@Post('/bank-account')
async createLecturerBankAccount(
Expand All @@ -121,41 +115,7 @@ export class LecturerPaymentsController {
);
}

@ApiGetPaymentRequestList()
@SetResponseKey('requestList')
@Get('/requests')
async getPaymentRequestList(
@GetAuthorizedUser() authorizedData: ValidateResult,
): Promise<PaymentRequestDto[]> {
return await this.lecturerPaymentsService.getPaymentRequestList(
authorizedData.lecturer.id,
);
}

@ApiGetPaymentRequestCount()
@SetResponseKey('requestCount')
@Get('/requests/count')
async getPaymentRequestCount(
@GetAuthorizedUser() authorizedData: ValidateResult,
): Promise<number> {
return await this.lecturerPaymentsService.getPaymentRequestCount(
authorizedData.lecturer.id,
);
}

@ApiUpdatePaymentRequestStatus()
@Patch('/request')
async updatePaymentRequestStatus(
@GetAuthorizedUser() authorizedData: ValidateResult,
@Body() updatePaymentRequestStatusDto: UpdatePaymentRequestStatusDto,
): Promise<void> {
await this.lecturerPaymentsService.updatePaymentRequestStatus(
authorizedData.lecturer.id,
updatePaymentRequestStatusDto,
);
}

@ApiGetMyPassSituation()
@ApiLecturerPayments.GetMyPassSituation({ summary: '패스권 판매 현황' })
@SetResponseKey('passSituationList')
@Get('passes/:passId')
async getMyPassSituation(
Expand All @@ -167,4 +127,45 @@ export class LecturerPaymentsController {
passId,
);
}

//todo 사용 여부 확이
// @ApiLecturerPayments.GetPaymentRequestList({
// summary: '입금 대기 중인 결제내역 조회',
// })
// @SetResponseKey('requestList')
// @Get('/requests')
// async getPaymentRequestList(
// @GetAuthorizedUser() authorizedData: ValidateResult,
// ): Promise<PaymentRequestDto[]> {
// return await this.lecturerPaymentsService.getPaymentRequestList(
// authorizedData.lecturer.id,
// );
// }

// @ApiLecturerPayments.GetPaymentRequestCount({
// summary: '입금 대기 중인 결제 건수 조회',
// })
// @SetResponseKey('requestCount')
// @Get('/requests/count')
// async getPaymentRequestCount(
// @GetAuthorizedUser() authorizedData: ValidateResult,
// ): Promise<number> {
// return await this.lecturerPaymentsService.getPaymentRequestCount(
// authorizedData.lecturer.id,
// );
// }

// @ApiLecturerPayments.UpdatePaymentRequestStatus({
// summary: '결제 요청 상태 변경',
// })
// @Patch('/request')
// async updatePaymentRequestStatus(
// @GetAuthorizedUser() authorizedData: ValidateResult,
// @Body() updatePaymentRequestStatusDto: UpdatePaymentRequestStatusDto,
// ): Promise<void> {
// await this.lecturerPaymentsService.updatePaymentRequestStatus(
// authorizedData.lecturer.id,
// updatePaymentRequestStatusDto,
// );
// }
}
2 changes: 0 additions & 2 deletions src/payments/controllers/payments.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { ApiTags } from '@nestjs/swagger';
import { UserAccessTokenGuard } from '@src/common/guards/user-access-token.guard';
import { GetAuthorizedUser } from '@src/common/decorator/get-user.decorator';
import { ValidateResult } from '@src/common/interface/common-interface';
import { ApiCreateLecturePaymentInfo } from '../swagger-decorators/ApiCreateLecturePaymentInfo';
import { ConfirmLecturePaymentDto } from '@src/payments/dtos/confirm-lecture-payment.dto';
import { CreatePassPaymentDto } from '@src/payments/dtos/create-pass-payment.dto';
import { CreateLecturePaymentWithPassDto } from '@src/payments/dtos/create-lecture-payment-with-pass.dto';
Expand Down Expand Up @@ -60,7 +59,6 @@ export class PaymentsController {
summary: '토스-강의 결제를 위한 기본 결제 정보 생성',
})
@SetResponseKey('pendingPaymentInfo')
@ApiCreateLecturePaymentInfo()
@Post('/toss/lecture')
@UseGuards(UserAccessTokenGuard)
createLecturePaymentWithToss(
Expand Down
Loading
Loading