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

Issue/168/update best review #169

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 0 additions & 5 deletions .dockerignore

This file was deleted.

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# compiled output
/dist
/node_modules
/src/common/node_modules
/apps/server/src/common/node_modules

#
/env/*
Expand Down Expand Up @@ -39,5 +39,5 @@ lerna-debug.log*
!.vscode/launch.json
!.vscode/extensions.json

volumes
apps/server/volumes
.clinic
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.17.0
v20.17.0
7 changes: 6 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
"semi": true,
"trailingComma": "all",
"singleQuote": true,
"trailingComma": "all"
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"plugins": ["prettier-plugin-tailwindcss"]
}
57 changes: 57 additions & 0 deletions apps/scholar-sync/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# compiled output
/dist
/node_modules
/build

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# dotenv environment variable files
/env/*
.env
.env.development.local
.env.test.local
.env.production.local
.env.local

# temp directory
.temp
.tmp

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
66 changes: 66 additions & 0 deletions apps/scholar-sync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# OTL Plus Sync-server

[![CI](https://github.com/sparcs-kaist/otlplus-server/actions/workflows/ci.yml/badge.svg?branch=dev)](https://github.com/sparcs-kaist/otlplus-server/actions/workflows/ci.yml)

## How to run

### 환경변수 설정

`env/.env.example`을 복사하여 `env/.env.local`을 만들고 적절하게 입력합니다.

### DB 설정

다음과 같이 `.env` 파일을 만들어 포트와 비밀번호를 설정할 수 있습니다.
아래 값들은 기본값입니다.

```env
OTLPLUS_DB_PORT=43306
OTLPLUS_DB_PASSWORD=password
```

아래 명령어로 DB를 도커로 띄웁니다.

```sh
sudo docker compose up
```

또는 로컬에서 MySQL 5.7을 설치하여 연결할 수 있습니다.

### Node.js 설치 및 버전 관리

Node.js v20 을 설치합니다.

버전 체크

```bash
node -v # v20.17.0
npm -v # v9.x.x
```

```bash
brew install nvm
brew install yarn ## 없다면 npm install -g yarn
brew install npm
```

(Tip) [nvm](https://github.com/nvm-sh/nvm) 설치 후, nvm을 이용하여 로컬 개발 환경의 node.js 버전을 설정하는 것을 권장합니다!

```bash
nvm install 20
nvm use 20
```

아래 명령어를 사용하면 `.nvmrc` 설정 파일에 따라 자동으로 버전이 변경됩니다.

```bash
nvm use # uses v20
```

### NestJS 서버 실행

```sh
yarn
# or
yarn install
yarn workspace @otlplus/scholar-sync run start:local
```
60 changes: 60 additions & 0 deletions apps/scholar-sync/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { FlatCompat } from '@eslint/eslintrc';
import js from '@eslint/js';
import typescriptEslintEslintPlugin from '@typescript-eslint/eslint-plugin';
import tsParser from '@typescript-eslint/parser';
import globals from 'globals';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all,
});

export default [
{
ignores: ['**/.eslintrc.js', '**/eslint.config.mjs', '**/dist'],
},
...compat.extends('eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'),
{
plugins: {
'@typescript-eslint': typescriptEslintEslintPlugin,
},

languageOptions: {
globals: {
...globals.node,
...globals.jest,
},

parser: tsParser,
ecmaVersion: 5,
sourceType: 'module',

parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: './',
},
},

rules: {
'@typescript-eslint/interface-name-prefix': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/no-inferrable-types': 'off',
'no-irregular-whitespace': 'off',
'no-extra-boolean-cast': 'off',
'no-inner-declarations': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-empty-interface': 'off',
},
},
];
102 changes: 102 additions & 0 deletions apps/scholar-sync/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{
"name": "@otl/scholar-sync",
"version": "0.0.1",
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"scripts": {
"build": "nest build --config src/bootstrap/nest-cli.json",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start:local": "cross-env NODE_ENV=local nest start --watch --config src/bootstrap/nest-cli.json",
"start:dev": "cross-env NODE_ENV=dev nest start --watch --config src/bootstrap/nest-cli.json",
"start:prod": "cross-env NODE_ENV=prod node dist/src/bootstrap/bootstrap.js",
"start": "nest start",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"prepare": "husky",
"ts-node": "cross-env NODE_ENV=local node -r ts-node/register -r tsconfig-paths/register "
},
"dependencies": {
"@nestjs/common": "^10.4.15",
"@nestjs/config": "^3.3.0",
"@nestjs/core": "^10.4.15",
"@nestjs/jwt": "^10.2.0",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.4.15",
"@nestjs/schedule": "^4.1.2",
"@nestjs/swagger": "^8.1.0",
"@prisma/client": "^6.1.0",
"@slack/web-api": "^7.8.0",
"@types/cookie-parser": "^1.4.8",
"axios": "^1.7.9",
"bcrypt": "^5.1.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"cookie-parser": "^1.4.7",
"cron-validator": "^1.3.1",
"dotenv": "^16.4.7",
"dotenv-cli": "^8.0.0",
"moment-timezone": "^0.5.47",
"qs": "^6.14.0",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@otl/api-interface": "*",
"@types/csurf": "^1.11.5",
"@types/express": "^5.0.0",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^6.0.0",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"cross-env": "^7.0.3",
"eslint": "^9.17.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.0.0",
"husky": "^9.1.7",
"jest": "^29.5.0",
"lint-staged": "^15.3.0",
"prettier": "^3.0.0",
"prisma": "^6.1.0",
"source-map-support": "^0.5.21",
"supertest": "^7.0.0",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
},
"lint-staged": {
"*.ts": "eslint --fix",
"*": "prettier --ignore-unknown --write"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"moduleNameMapper": {
"^@src(.*)$": "<rootDir>/src$1"
},
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
22 changes: 22 additions & 0 deletions apps/scholar-sync/src/app.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing';
import { AppController } from './app.controller';
import { AppService } from './app.service';

describe('AppController', () => {
let appController: AppController;

beforeEach(async () => {
const app: TestingModule = await Test.createTestingModule({
controllers: [AppController],
providers: [AppService],
}).compile();

appController = app.get<AppController>(AppController);
});

describe('root', () => {
it('should return "Hello World!"', () => {
expect(appController.getHello()).toBe('Hello World!');
});
});
});
12 changes: 12 additions & 0 deletions apps/scholar-sync/src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Get()
getHello(): string {
return this.appService.getHello();
}
}
14 changes: 14 additions & 0 deletions apps/scholar-sync/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { SyncModule } from '@otl/scholar-sync/modules/sync/sync.module';
import { SlackModule } from '@otl/scholar-sync/clients/slack/slack.module';
import { ScholarModule } from '@otl/scholar-sync/clients/scholar/scholar.module';
import { PrismaModule } from '@otl/scholar-sync/prisma/prisma.module';

@Module({
imports: [PrismaModule, SyncModule],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
8 changes: 8 additions & 0 deletions apps/scholar-sync/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}
Loading