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(BE): 백엔드 리팩토링 #139

Merged
merged 33 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d7dd255
refactor: 폴더 구조 및 네이밍 변경
eeseung Sep 15, 2024
ceda7a6
refactor: 메모 생성/수정 API service 구분
yeeezae Sep 22, 2024
160e75b
refactor: 의과 예진 생성 API service 구분
yeeezae Sep 22, 2024
747513f
refactor: 한의과 예진 생성 API service 구분
yeeezae Sep 22, 2024
f411c2e
refactor: 참여자 히스토리 생성 service 구분
yeeezae Sep 22, 2024
34e1cc5
refactor: 의과 약품 히스토리 API service 구분
eeseung Sep 22, 2024
4a8a61d
refactor: 한의과 약품 히스토리 API service 구분
eeseung Sep 22, 2024
827723c
refactor: 메모 생성/수정 로직 수정
yeeezae Sep 22, 2024
6bd50f9
feat: JoinColumn chartId -> chartNumber 변경 및 컬럼 comment 추가
eeseung Sep 22, 2024
9b624b2
refactor: chartId -> chartNumber 수정
yeeezae Sep 22, 2024
27fdfd9
refactor: chartId -> chartNumber 수정 & 접수 로직 변경
eeseung Sep 22, 2024
b92b9d8
fix: generateChartNumber 메서드 null 에러 수정
eeseung Sep 26, 2024
439d4f7
refactor: 히스토리, C.C API service 구분
yeeezae Sep 26, 2024
2164d90
refactor: 약국 수정 API path 변경 & postDiagnosis 파라미터 수정
eeseung Sep 26, 2024
5ffe696
refactor: 처방 생성 API service 구분
eeseung Sep 26, 2024
e5d0b1b
feat: prescriptions 컨트롤러 차트 검증 미들웨어 적용
eeseung Sep 26, 2024
ef43176
refactor: 메서드 네이밍 통일
yeeezae Sep 29, 2024
093804e
refactor: controller 이동
yeeezae Oct 2, 2024
8d634dd
refactor: id 불러오는 값 수정
yeeezae Oct 2, 2024
7feb1fb
feat: chartNumber 9자리 & number 타입으로 변경
eeseung Nov 19, 2024
f819311
feat: chartNumber 변경사항 적용
eeseung Nov 28, 2024
a8feb0c
refactor: 각 모듈 exports 추가
eeseung Dec 3, 2024
7ee2c18
refactor: 폴더 구조 및 네이밍 변경 & tsconfig 절대경로 설정
eeseung Dec 15, 2024
9dd235a
remove: app.controller.ts, app.service.ts 안쓰는 파일 삭제
eeseung Dec 16, 2024
f6473ba
refactor: 모듈 구조 개선
eeseung Jan 10, 2025
8efe31e
feat: 의과 약품 대분류 삭제 API 제거
eeseung Jan 10, 2025
1d4f312
feat: Entity relations 옵션, 컬럼 수정
eeseung Feb 20, 2025
323899e
feat: Entity 변경사항 dto, service, constant 적용
eeseung Feb 20, 2025
d76f341
feat: 의과/한의과 예진 조회 API 수정
eeseung Feb 20, 2025
70db5d1
refactor: 의과/한의과 prescriptions 히스토리 컨트롤러 분리
eeseung Feb 20, 2025
70a0085
feat: convertDoseFrequency 네이밍 변경 및 prn 추가
eeseung Feb 20, 2025
701aac7
feat: 의과/한의과 예진 완료 API 수정
eeseung Feb 20, 2025
bd61a01
feat: 의과 prescriptions isQuantityBased 적용 및 bundle 정렬 추가
eeseung Feb 20, 2025
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
22 changes: 0 additions & 22 deletions backend/src/app.controller.spec.ts

This file was deleted.

12 changes: 0 additions & 12 deletions backend/src/app.controller.ts

This file was deleted.

98 changes: 48 additions & 50 deletions backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,46 @@
import { ClassSerializerInterceptor, Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule } from '@nestjs/config';
import { CommonModule } from './common/common.module';
import { MMedicinesModule } from './m-medicines/m-medicines.module';
import { M_Medicines } from './m-medicines/entity/m-medicines.entity';
import { MMedicineCategoriesModule } from './m-medicine-categories/m-medicine-categories.module';
import { M_Medicine_Categories } from './m-medicine-categories/entity/m_medicine_categories.entity';
import { MChartsModule } from './m-charts/m-charts.module';
import { M_Charts } from './m-charts/entity/m-charts.entity';
import { MComplaintsModule } from './m-complaints/m-complaints.module';
import { M_Complaints } from './m-complaints/entity/m-complaints.entity';
import { MPrescriptionsModule } from './m-prescriptions/m-prescriptions.module';
import { M_Prescriptions } from './m-prescriptions/entity/m-prescriptions.entity';
import { HistoriesModule } from './patients/histories/histories.module';
import { Histories } from './patients/histories/entity/histories.entity';
import { Users } from './users/entity/users.entity';
import { UsersModule } from './users/users.module';
import { Patients } from './patients/entity/patients.entity';
import { PatientsModule } from './patients/patients.module';
import { Orders } from './orders/entity/orders.entity';
import { OrdersModule } from './orders/orders.module';
import { Memos } from './patients/memos/entity/memos.entity';
import { MemosModule } from './patients/memos/memos.module';
import { KM_Charts } from './km-charts/entity/km-charts.entity';
import { KmChartsModule } from './km-charts/km-charts.module';
import { KmComplaintsModule } from './km-complaints/km-complaints.module';
import { KmPrescriptionsModule } from './km-prescriptions/km-prescriptions.module';
import { KmMedicinesModule } from './km-medicines/km-medicines.module';
import { KM_Complaints } from './km-complaints/entity/km-complaints.entity';
import { KM_Prescriptions } from './km-prescriptions/entity/km-prescriptions.entity';
import { KM_Medicines } from './km-medicines/entity/km-medicines.entity';
import { CommonModule } from '@/common/common.module';
import { MMedicinesModule } from '@/m/medicines/medicines.module';
import { MMedicine } from '@/m/medicines/entities/medicine.entity';
import { MMedicineCategoriesModule } from '@/m/medicine-categories/medicine-categories.module';
import { MMedicineCategory } from '@/m/medicine-categories/entities/medicine-categories.entity';
import { MChartsModule } from '@/m/charts/charts.module';
import { MChart } from '@/m/charts/entities/chart.entity';
import { MComplaintsModule } from '@/m/complaints/complaints.module';
import { MComplaint } from '@/m/complaints/entities/complaints.entity';
import { MPrescriptionsModule } from '@/m/prescriptions/prescriptions.module';
import { MPrescription } from '@/m/prescriptions/entities/prescription.entity';
import { HistoriesModule } from '@/patients/histories/histories.module';
import { History } from '@/patients/entities/history.entity';
import { User } from '@/users/entities/user.entity';
import { UsersModule } from '@/users/users.module';
import { Patient } from '@/patients/entities/patient.entity';
import { PatientsModule } from '@/patients/patients.module';
import { Order } from '@/orders/entities/order.entity';
import { OrdersModule } from '@/orders/orders.module';
import { Memo } from '@/patients/entities/memo.entity';
import { MemosModule } from '@/patients/memos/memos.module';
import { KmChart } from '@/km/charts/entities/chart.entity';
import { KmChartsModule } from '@/km/charts/charts.module';
import { KmComplaintsModule } from '@/km/complaints/complaints.module';
import { KmPrescriptionsModule } from '@/km/prescriptions/prescriptions.module';
import { KmMedicinesModule } from '@/km/medicines/medicines.module';
import { KmComplaint } from '@/km/complaints/entities/complaint.entity';
import { KmPrescription } from '@/km/prescriptions/entities/prescription.entity';
import { KmMedicine } from '@/km/medicines/entities/medicine.entity';
import {
ENV_DB_DATABASE_KEY,
ENV_DB_HOST_KEY,
ENV_DB_PASSWORD_KEY,
ENV_DB_PORT_KEY,
ENV_DB_USERNAME_KEY,
} from './common/const/env-keys.const';
} from '@/common/constants/env-keys.constant';
import { APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
import { AuthModule } from './auth/auth.module';
import { AccessTokenGuard } from './auth/guard/access-token.guard';
import { AuthModule } from '@/auth/auth.module';
import { AccessTokenGuard } from '@/auth/guards/access-token.guard';

@Module({
imports: [
ConfigModule.forRoot({
Expand All @@ -63,20 +62,20 @@ import { AccessTokenGuard } from './auth/guard/access-token.guard';
database: process.env[ENV_DB_DATABASE_KEY],
timezone: '+09:00',
entities: [
M_Charts,
M_Complaints,
M_Prescriptions,
M_Medicines,
M_Medicine_Categories,
Patients,
Histories,
Memos,
Orders,
Users,
KM_Charts,
KM_Complaints,
KM_Prescriptions,
KM_Medicines,
MChart,
MComplaint,
MPrescription,
MMedicine,
MMedicineCategory,
KmChart,
KmComplaint,
KmPrescription,
KmMedicine,
User,
Order,
Patient,
History,
Memo,
],
synchronize: false,
}),
Expand All @@ -97,9 +96,8 @@ import { AccessTokenGuard } from './auth/guard/access-token.guard';
KmMedicinesModule,
AuthModule,
],
controllers: [AppController],
controllers: [],
providers: [
AppService,
{
provide: APP_INTERCEPTOR,
useClass: ClassSerializerInterceptor,
Expand Down
8 changes: 0 additions & 8 deletions backend/src/app.service.ts

This file was deleted.

2 changes: 1 addition & 1 deletion backend/src/auth/auth.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthController } from './auth.controller';
import { AuthController } from '@/auth/auth.controller';

describe('AuthController', () => {
let controller: AuthController;
Expand Down
22 changes: 11 additions & 11 deletions backend/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { Controller, Post, UseGuards, HttpStatus, Res } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthService } from '@/auth/auth.service';
import {
ApiBasicAuth,
ApiOperation,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import { User } from 'src/users/decorator/user.decorator';
import { Users } from 'src/users/entity/users.entity';
import { CurrentUser } from '@/users/decorators/current-user.decorator';
import { Response } from 'express';
import { RefreshTokenGuard } from './guard/refresh-token.guard';
import { BasicAuthGuard } from './guard/basic.guard';
import { RefreshTokenGuard } from '@/auth/guards/refresh-token.guard';
import { BasicAuthGuard } from '@/auth/guards/basic.guard';
import { ConfigService } from '@nestjs/config';
import {
ENV_ACCESS_TOKEN_EXPIRE_SECONDS,
ENV_REFRESH_TOKEN_EXPIRE_SECONDS,
} from 'src/common/const/env-keys.const';
import { AccessTokenGuard } from './guard/access-token.guard';
import { Public } from 'src/common/decorator/public.decorator';
} from '@/common/constants/env-keys.constant';
import { AccessTokenGuard } from '@/auth/guards/access-token.guard';
import { Public } from '@/common/decorators/public.decorator';
import { User } from '@/users/entities/user.entity';

@ApiTags('Auth')
@Controller('auth')
Expand All @@ -38,7 +38,7 @@ export class AuthController {
status: HttpStatus.UNAUTHORIZED,
description: '존재하지 않는 사용자입니다. / 비밀번호가 틀렸습니다.',
})
async postLoginAccount(@User() user: Users, @Res() res: Response) {
async postLoginAccount(@CurrentUser() user: User, @Res() res: Response) {
const { accessToken, refreshToken } =
await this.authService.loginUser(user);

Expand All @@ -60,7 +60,7 @@ export class AuthController {
@ApiOperation({
summary: '로그인 테스트',
})
async postTest(@User() user: Users) {
async postTest(@CurrentUser() user: User) {
return user;
}

Expand All @@ -75,7 +75,7 @@ export class AuthController {
description:
"(저장된) Refresh Token이 존재하지 않습니다. / (저장된) Refresh Token이 유효하지 않습니다. <small>redis 토큰 에러인 경우 '저장된~' 표시</small>",
})
async postRefresh(@User() user: Users, @Res() res: Response) {
async postRefresh(@CurrentUser() user: User, @Res() res: Response) {
const { accessToken, refreshToken } =
await this.authService.loginUser(user);

Expand Down
14 changes: 7 additions & 7 deletions backend/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Module } from '@nestjs/common';
import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { UsersModule } from 'src/users/users.module';
import { AuthService } from '@/auth//auth.service';
import { AuthController } from '@/auth/auth.controller';
import { UsersModule } from '@/users/users.module';
import { PassportModule } from '@nestjs/passport';
import { JwtModule } from '@nestjs/jwt';
import { BasicStrategy } from './strategy/basic.strategy';
import { BasicStrategy } from '@/auth/strategies/basic.strategy';
import { CacheModule } from '@nestjs/cache-manager';
import { redisStore } from 'cache-manager-redis-yet';
import {
ENV_HOST_KEY,
ENV_REDIS_BINDING_PORT_KEY,
ENV_REDIS_PASSWORD_KEY,
} from 'src/common/const/env-keys.const';
import { AccessTokenStrategy } from './strategy/access-token.strategy';
import { RefreshTokenStrategy } from './strategy/refresh-token.strategy';
} from '@/common/constants/env-keys.constant';
import { AccessTokenStrategy } from '@/auth/strategies/access-token.strategy';
import { RefreshTokenStrategy } from '@/auth/strategies/refresh-token.strategy';

@Module({
imports: [
Expand Down
2 changes: 1 addition & 1 deletion backend/src/auth/auth.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AuthService } from './auth.service';
import { AuthService } from '@/auth/auth.service';

describe('AuthService', () => {
let service: AuthService;
Expand Down
14 changes: 7 additions & 7 deletions backend/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {
ENV_ACCESS_TOKEN_EXPIRE_SECONDS,
ENV_JWT_SECRET_KEY,
ENV_REFRESH_TOKEN_EXPIRE_SECONDS,
} from 'src/common/const/env-keys.const';
import { Users } from 'src/users/entity/users.entity';
import { UsersService } from 'src/users/users.service';
} from '@/common/constants/env-keys.constant';
import { User } from '@/users/entities/user.entity';
import { UsersService } from '@/users/users.service';

@Injectable()
export class AuthService {
Expand All @@ -21,7 +21,7 @@ export class AuthService {
private cacheManager: Cache,
) {}

async authenticateUser(user: Pick<Users, 'account' | 'password'>) {
async authenticateUser(user: Pick<User, 'account' | 'password'>) {
const existingUser = await this.usersService.getUserWithPasswordByAccount(
user.account,
);
Expand All @@ -41,7 +41,7 @@ export class AuthService {
return existingUser;
}

async loginUser(user: Pick<Users, 'id' | 'account'>) {
async loginUser(user: Pick<User, 'id' | 'account'>) {
const accessToken = await this.signAccessToken(user);
const refreshToken = await this.signRefreshToken(user);

Expand All @@ -50,7 +50,7 @@ export class AuthService {
return { accessToken, refreshToken };
}

signAccessToken(user: Pick<Users, 'id' | 'account'>) {
signAccessToken(user: Pick<User, 'id' | 'account'>) {
const payload = {
id: user.id,
account: user.account,
Expand All @@ -65,7 +65,7 @@ export class AuthService {
});
}

signRefreshToken(user: Pick<Users, 'id'>) {
signRefreshToken(user: Pick<User, 'id'>) {
const payload = {
id: user.id,
type: 'refresh',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
UnauthorizedException,
} from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { IS_PUBLIC_KEY } from 'src/common/decorator/public.decorator';
import { IS_PUBLIC_KEY } from '@/common/decorators/public.decorator';

@Injectable()
export class AccessTokenGuard extends AuthGuard('jwt-access') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ENV_JWT_SECRET_KEY } from 'src/common/const/env-keys.const';
import { UsersService } from 'src/users/users.service';
import { Payload } from './jwt.payload';
import { ENV_JWT_SECRET_KEY } from '@/common/constants/env-keys.constant';
import { UsersService } from '@/users/users.service';
import { Payload } from '@/auth/strategies/jwt.payload';

@Injectable()
export class AccessTokenStrategy extends PassportStrategy(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { BasicStrategy as HttpBasicStrategy } from 'passport-http';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { AuthService } from '../auth.service';
import { Users } from 'src/users/entity/users.entity';
import { AuthService } from '@/auth/auth.service';
import { User } from '@/users/entities/user.entity';

@Injectable()
export class BasicStrategy extends PassportStrategy(HttpBasicStrategy) {
constructor(private readonly authService: AuthService) {
super();
}

async validate(account: string, password: string): Promise<Users> {
async validate(account: string, password: string): Promise<User> {
const loginUser = await this.authService.authenticateUser({
account,
password,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { ENV_JWT_SECRET_KEY } from 'src/common/const/env-keys.const';
import { AuthService } from '../auth.service';
import { UsersService } from 'src/users/users.service';
import { Payload } from './jwt.payload';
import { ENV_JWT_SECRET_KEY } from '@/common/constants/env-keys.constant';
import { AuthService } from '@/auth/auth.service';
import { UsersService } from '@/users/users.service';
import { Payload } from '@/auth/strategies/jwt.payload';

@Injectable()
export class RefreshTokenStrategy extends PassportStrategy(
Expand Down
4 changes: 2 additions & 2 deletions backend/src/common/common.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Test, TestingModule } from '@nestjs/testing';
import { CommonController } from './common.controller';
import { CommonService } from './common.service';
import { CommonController } from '@/common/common.controller';
import { CommonService } from '@/common/common.service';

describe('CommonController', () => {
let controller: CommonController;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/common/common.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Controller } from '@nestjs/common';
import { CommonService } from './common.service';
import { CommonService } from '@/common/common.service';

@Controller('common')
export class CommonController {
Expand Down
Loading