From afbf1185aedd2559a6d9c7d434ac0f73ea88d5c4 Mon Sep 17 00:00:00 2001 From: June1010 Date: Tue, 20 Dec 2022 16:46:55 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20consumer=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- noti-server/src/app.controller.ts | 10 +-- noti-server/src/app.module.ts | 9 +-- noti-worker-delayed/.env | 8 ++ noti-worker-delayed/.eslintrc.js | 25 +++++++ noti-worker-delayed/.gitignore | 35 +++++++++ noti-worker-delayed/.prettierrc | 4 + noti-worker-delayed/README.md | 73 ++++++++++++++++++ noti-worker-delayed/nest-cli.json | 5 ++ noti-worker-delayed/package.json | 75 +++++++++++++++++++ .../src/app.consumer.ts | 0 noti-worker-delayed/src/app.module.ts | 23 ++++++ .../src/common/templates/cancel.hbs | 33 ++++++++ .../src/common/templates/recruit.hbs | 38 ++++++++++ .../src/common/templates/signup.hbs | 23 ++++++ noti-worker-delayed/src/mail/mail.module.ts | 35 +++++++++ noti-worker-delayed/src/mail/mail.service.ts | 49 ++++++++++++ noti-worker-delayed/src/main.ts | 8 ++ noti-worker-delayed/tsconfig.build.json | 4 + noti-worker-delayed/tsconfig.json | 21 ++++++ noti-worker-immediate/.env | 8 ++ noti-worker-immediate/.eslintrc.js | 25 +++++++ noti-worker-immediate/.gitignore | 35 +++++++++ noti-worker-immediate/.prettierrc | 4 + noti-worker-immediate/README.md | 73 ++++++++++++++++++ noti-worker-immediate/nest-cli.json | 5 ++ noti-worker-immediate/package.json | 75 +++++++++++++++++++ .../src/app.consumer.ts | 0 noti-worker-immediate/src/app.module.ts | 23 ++++++ .../src/common/templates/cancel.hbs | 33 ++++++++ .../src/common/templates/recruit.hbs | 38 ++++++++++ .../src/common/templates/signup.hbs | 23 ++++++ noti-worker-immediate/src/mail/mail.module.ts | 35 +++++++++ .../src/mail/mail.service.ts | 49 ++++++++++++ noti-worker-immediate/src/main.ts | 8 ++ noti-worker-immediate/tsconfig.build.json | 4 + noti-worker-immediate/tsconfig.json | 21 ++++++ 36 files changed, 923 insertions(+), 14 deletions(-) create mode 100644 noti-worker-delayed/.env create mode 100644 noti-worker-delayed/.eslintrc.js create mode 100644 noti-worker-delayed/.gitignore create mode 100644 noti-worker-delayed/.prettierrc create mode 100644 noti-worker-delayed/README.md create mode 100644 noti-worker-delayed/nest-cli.json create mode 100644 noti-worker-delayed/package.json rename noti-server/src/app.delayed.consumer.ts => noti-worker-delayed/src/app.consumer.ts (100%) create mode 100644 noti-worker-delayed/src/app.module.ts create mode 100644 noti-worker-delayed/src/common/templates/cancel.hbs create mode 100644 noti-worker-delayed/src/common/templates/recruit.hbs create mode 100644 noti-worker-delayed/src/common/templates/signup.hbs create mode 100644 noti-worker-delayed/src/mail/mail.module.ts create mode 100644 noti-worker-delayed/src/mail/mail.service.ts create mode 100644 noti-worker-delayed/src/main.ts create mode 100644 noti-worker-delayed/tsconfig.build.json create mode 100644 noti-worker-delayed/tsconfig.json create mode 100644 noti-worker-immediate/.env create mode 100644 noti-worker-immediate/.eslintrc.js create mode 100644 noti-worker-immediate/.gitignore create mode 100644 noti-worker-immediate/.prettierrc create mode 100644 noti-worker-immediate/README.md create mode 100644 noti-worker-immediate/nest-cli.json create mode 100644 noti-worker-immediate/package.json rename noti-server/src/app.immediate.consumer.ts => noti-worker-immediate/src/app.consumer.ts (100%) create mode 100644 noti-worker-immediate/src/app.module.ts create mode 100644 noti-worker-immediate/src/common/templates/cancel.hbs create mode 100644 noti-worker-immediate/src/common/templates/recruit.hbs create mode 100644 noti-worker-immediate/src/common/templates/signup.hbs create mode 100644 noti-worker-immediate/src/mail/mail.module.ts create mode 100644 noti-worker-immediate/src/mail/mail.service.ts create mode 100644 noti-worker-immediate/src/main.ts create mode 100644 noti-worker-immediate/tsconfig.build.json create mode 100644 noti-worker-immediate/tsconfig.json diff --git a/noti-server/src/app.controller.ts b/noti-server/src/app.controller.ts index 1590de6..e729531 100644 --- a/noti-server/src/app.controller.ts +++ b/noti-server/src/app.controller.ts @@ -1,12 +1,4 @@ -import { - Body, - ConsoleLogger, - Controller, - Get, - Param, - Post, - Req, -} from '@nestjs/common'; +import { Body, Controller, Post } from '@nestjs/common'; import { AppService } from './app.service'; @Controller('job') diff --git a/noti-server/src/app.module.ts b/noti-server/src/app.module.ts index c6a730b..7582b39 100644 --- a/noti-server/src/app.module.ts +++ b/noti-server/src/app.module.ts @@ -4,9 +4,9 @@ import { AppService } from './app.service'; import { ConfigModule } from '@nestjs/config'; import { BullModule } from '@nestjs/bull'; -import { DelayedConsumer } from './app.delayed.consumer'; -import { ImmediateConsumer } from './app.immediate.consumer'; -import { MailModule } from './mail/mail.module'; +// import { DelayedConsumer } from './app.delayed.consumer'; +// import { ImmediateConsumer } from './app.immediate.consumer'; +// import { MailModule } from './mail/mail.module'; @Module({ imports: [ @@ -21,9 +21,8 @@ import { MailModule } from './mail/mail.module'; }), BullModule.registerQueue({ name: 'delayed' }, { name: 'immediate' }), CacheModule.register(), - MailModule, ], controllers: [AppController], - providers: [AppService, DelayedConsumer, ImmediateConsumer], + providers: [AppService], }) export class AppModule {} diff --git a/noti-worker-delayed/.env b/noti-worker-delayed/.env new file mode 100644 index 0000000..3e68015 --- /dev/null +++ b/noti-worker-delayed/.env @@ -0,0 +1,8 @@ +EMAIL_SERVICE=RunWithMe +EMAIL_HOST=smtp.worksmobile.com +EMAIL_PORT=587 +EMAIL_USER=admin@runwithme.co.kr +EMAIL_PW=2HMxdMVBXa68 + +REDIS_HOST=localhost +REDIS_PORT=6379 \ No newline at end of file diff --git a/noti-worker-delayed/.eslintrc.js b/noti-worker-delayed/.eslintrc.js new file mode 100644 index 0000000..8f5aedb --- /dev/null +++ b/noti-worker-delayed/.eslintrc.js @@ -0,0 +1,25 @@ +module.exports = { + parser: '@typescript-eslint/parser', + parserOptions: { + project: 'tsconfig.json', + tsconfigRootDir : __dirname, + sourceType: 'module', + }, + plugins: ['@typescript-eslint/eslint-plugin'], + extends: [ + 'plugin:@typescript-eslint/recommended', + 'plugin:prettier/recommended', + ], + root: true, + env: { + node: true, + jest: true, + }, + ignorePatterns: ['.eslintrc.js'], + 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', + }, +}; diff --git a/noti-worker-delayed/.gitignore b/noti-worker-delayed/.gitignore new file mode 100644 index 0000000..22f55ad --- /dev/null +++ b/noti-worker-delayed/.gitignore @@ -0,0 +1,35 @@ +# compiled output +/dist +/node_modules + +# 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 \ No newline at end of file diff --git a/noti-worker-delayed/.prettierrc b/noti-worker-delayed/.prettierrc new file mode 100644 index 0000000..dcb7279 --- /dev/null +++ b/noti-worker-delayed/.prettierrc @@ -0,0 +1,4 @@ +{ + "singleQuote": true, + "trailingComma": "all" +} \ No newline at end of file diff --git a/noti-worker-delayed/README.md b/noti-worker-delayed/README.md new file mode 100644 index 0000000..00a13b1 --- /dev/null +++ b/noti-worker-delayed/README.md @@ -0,0 +1,73 @@ +

+ Nest Logo +

+ +[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 +[circleci-url]: https://circleci.com/gh/nestjs/nest + +

A progressive Node.js framework for building efficient and scalable server-side applications.

+

+NPM Version +Package License +NPM Downloads +CircleCI +Coverage +Discord +Backers on Open Collective +Sponsors on Open Collective + + Support us + +

+ + +## Description + +[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. + +## Installation + +```bash +$ npm install +``` + +## Running the app + +```bash +# development +$ npm run start + +# watch mode +$ npm run start:dev + +# production mode +$ npm run start:prod +``` + +## Test + +```bash +# unit tests +$ npm run test + +# e2e tests +$ npm run test:e2e + +# test coverage +$ npm run test:cov +``` + +## Support + +Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). + +## Stay in touch + +- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) +- Website - [https://nestjs.com](https://nestjs.com/) +- Twitter - [@nestframework](https://twitter.com/nestframework) + +## License + +Nest is [MIT licensed](LICENSE). diff --git a/noti-worker-delayed/nest-cli.json b/noti-worker-delayed/nest-cli.json new file mode 100644 index 0000000..2566481 --- /dev/null +++ b/noti-worker-delayed/nest-cli.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://json.schemastore.org/nest-cli", + "collection": "@nestjs/schematics", + "sourceRoot": "src" +} diff --git a/noti-worker-delayed/package.json b/noti-worker-delayed/package.json new file mode 100644 index 0000000..02ba79b --- /dev/null +++ b/noti-worker-delayed/package.json @@ -0,0 +1,75 @@ +{ + "name": "noti-worker", + "version": "0.0.1", + "description": "", + "author": "", + "private": true, + "license": "UNLICENSED", + "scripts": { + "prebuild": "rimraf dist", + "build": "nest build", + "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", + "start": "nest start", + "start:dev": "nest start --watch", + "start:debug": "nest start --debug --watch", + "start:prod": "node dist/main", + "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" + }, + "dependencies": { + "@nestjs-modules/mailer": "^1.8.1", + "@nestjs/bull": "^0.6.2", + "@nestjs/common": "^9.0.0", + "@nestjs/config": "^2.2.0", + "@nestjs/core": "^9.0.0", + "@nestjs/platform-express": "^9.0.0", + "bull": "^4.10.2", + "reflect-metadata": "^0.1.13", + "rimraf": "^3.0.2", + "rxjs": "^7.2.0" + }, + "devDependencies": { + "@nestjs/cli": "^9.0.0", + "@nestjs/schematics": "^9.0.0", + "@nestjs/testing": "^9.0.0", + "@types/express": "^4.17.13", + "@types/jest": "28.1.8", + "@types/node": "^16.0.0", + "@types/supertest": "^2.0.11", + "@typescript-eslint/eslint-plugin": "^5.0.0", + "@typescript-eslint/parser": "^5.0.0", + "eslint": "^8.0.1", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-prettier": "^4.0.0", + "jest": "28.1.3", + "prettier": "^2.3.2", + "source-map-support": "^0.5.20", + "supertest": "^6.1.3", + "ts-jest": "28.0.8", + "ts-loader": "^9.2.3", + "ts-node": "^10.0.0", + "tsconfig-paths": "4.1.0", + "typescript": "^4.7.4" + }, + "jest": { + "moduleFileExtensions": [ + "js", + "json", + "ts" + ], + "rootDir": "src", + "testRegex": ".*\\.spec\\.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + }, + "collectCoverageFrom": [ + "**/*.(t|j)s" + ], + "coverageDirectory": "../coverage", + "testEnvironment": "node" + } +} diff --git a/noti-server/src/app.delayed.consumer.ts b/noti-worker-delayed/src/app.consumer.ts similarity index 100% rename from noti-server/src/app.delayed.consumer.ts rename to noti-worker-delayed/src/app.consumer.ts diff --git a/noti-worker-delayed/src/app.module.ts b/noti-worker-delayed/src/app.module.ts new file mode 100644 index 0000000..7fa07f8 --- /dev/null +++ b/noti-worker-delayed/src/app.module.ts @@ -0,0 +1,23 @@ +import { Module } from '@nestjs/common'; +import { DelayedConsumer } from './app.consumer'; +import { ConfigModule } from '@nestjs/config'; +import { BullModule } from '@nestjs/bull'; +import { MailModule } from './mail/mail.module'; + +@Module({ + imports: [ + ConfigModule.forRoot({ + isGlobal: true, + }), + BullModule.forRoot({ + redis: { + host: process.env.REDIS_HOST, + port: Number(process.env.REDIS_PORT), + }, + }), + MailModule, + BullModule.registerQueue({ name: 'delayed' }), + ], + providers: [DelayedConsumer], +}) +export class AppModule {} diff --git a/noti-worker-delayed/src/common/templates/cancel.hbs b/noti-worker-delayed/src/common/templates/cancel.hbs new file mode 100644 index 0000000..2ad097c --- /dev/null +++ b/noti-worker-delayed/src/common/templates/cancel.hbs @@ -0,0 +1,33 @@ +
+
+
+

나만의 코스로 함께 + 달리는 러닝 커뮤니티

+
+

모임이 취소되었어요😥😥

+
+
+

모임 제목

+

{{title}}

+
+
+

집합 위치

+

{{hName}}

+
+
+

집합 일시

+

{{startTime}}

+
+
+

총거리

+

{{pathLength}}km

+
+
+
+
+

행복회로 | 서울특별시 중구 남산동2가 + 32-13 303호

+
+
+
\ No newline at end of file diff --git a/noti-worker-delayed/src/common/templates/recruit.hbs b/noti-worker-delayed/src/common/templates/recruit.hbs new file mode 100644 index 0000000..a2ceec2 --- /dev/null +++ b/noti-worker-delayed/src/common/templates/recruit.hbs @@ -0,0 +1,38 @@ +
+
+
+

나만의 코스로 함께 + 달리는 러닝 커뮤니티

+
+

잠시후 출발하는 모임이 있습니다

+
+
+

모임 제목

+

{{title}}

+
+
+

집합 위치

+

{{hName}}

+
+
+

집합 일시

+

{{startTime}}

+
+
+

총거리

+

{{pathLength}}km

+
+
+
+ 모임 + 정보 보러가기! +
+
+
+

행복회로 | 서울특별시 중구 남산동2가 + 32-13 303호

+
+
+
\ No newline at end of file diff --git a/noti-worker-delayed/src/common/templates/signup.hbs b/noti-worker-delayed/src/common/templates/signup.hbs new file mode 100644 index 0000000..98caf28 --- /dev/null +++ b/noti-worker-delayed/src/common/templates/signup.hbs @@ -0,0 +1,23 @@ +
+
+
+

나만의 코스로 함께 + 달리는 러닝 커뮤니티

+
+

{{id}}님 가입을 환영합니다.🎉

+

+ 지금부터 이 계정으로 RunWithMe를 이용하실 수 있어요 :) +

+
+ RunWithMe를 + 시작해보세요! +
+
+
+

행복회로 | 서울특별시 중구 남산동2가 + 32-13 303호

+
+
+
\ No newline at end of file diff --git a/noti-worker-delayed/src/mail/mail.module.ts b/noti-worker-delayed/src/mail/mail.module.ts new file mode 100644 index 0000000..b96e0a5 --- /dev/null +++ b/noti-worker-delayed/src/mail/mail.module.ts @@ -0,0 +1,35 @@ +import { Module } from '@nestjs/common'; +import { MailService } from './mail.service'; +import { MailerModule } from '@nestjs-modules/mailer'; +import { ConfigModule, ConfigService } from '@nestjs/config'; +import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter'; + +@Module({ + imports: [ + MailerModule.forRootAsync({ + imports: [ConfigModule], + useFactory: async (config: ConfigService) => ({ + transport: { + service: config.get('EMAIL_SERVICE'), + host: config.get('EMAIL_HOST'), + port: config.get('EMAIL_PORT'), + auth: { + user: config.get('EMAIL_USER'), + pass: config.get('EMAIL_PW'), + }, + }, + template: { + dir: process.cwd() + '/src/common/templates/', + adapter: new HandlebarsAdapter(), + options: { + strict: true, + }, + }, + }), + inject: [ConfigService], + }), + ], + providers: [MailService], + exports: [MailService], +}) +export class MailModule {} diff --git a/noti-worker-delayed/src/mail/mail.service.ts b/noti-worker-delayed/src/mail/mail.service.ts new file mode 100644 index 0000000..5c74d23 --- /dev/null +++ b/noti-worker-delayed/src/mail/mail.service.ts @@ -0,0 +1,49 @@ +import { Injectable } from '@nestjs/common'; +import { MailerService } from '@nestjs-modules/mailer'; + +@Injectable() +export class MailService { + constructor(private mailService: MailerService) {} + + async sendEmail( + type: string, + email: string | Array, + data: any, + ): Promise { + try { + const { subject, template } = this.getTemplate(type); + await this.mailService.sendMail({ + from: process.env.EMAIL_USER, + to: email, + subject, + template, + context: data, + }); + } catch (err) { + throw new Error(err); + } + } + + getTemplate(type: string) { + if (type === 'signup') { + return { + subject: 'RunWithMe: 회원가입을 환영합니다.', + template: 'signup', + }; + } + + if (type === 'recruit') { + return { + subject: 'RunWithMe: 회원님이 참여중인 러닝 모임이 곧 시작됩니다!', + template: 'recruit', + }; + } + + if (type === 'cancel') { + return { + subject: 'RunWithMe: 회원님이 참여중인 모집이 취소되었어요...', + template: 'cancel', + }; + } + } +} diff --git a/noti-worker-delayed/src/main.ts b/noti-worker-delayed/src/main.ts new file mode 100644 index 0000000..157b2f6 --- /dev/null +++ b/noti-worker-delayed/src/main.ts @@ -0,0 +1,8 @@ +import { NestFactory } from '@nestjs/core'; +import { AppModule } from './app.module'; + +async function bootstrap() { + const app = await NestFactory.create(AppModule); + await app.listen(14000); +} +bootstrap(); diff --git a/noti-worker-delayed/tsconfig.build.json b/noti-worker-delayed/tsconfig.build.json new file mode 100644 index 0000000..64f86c6 --- /dev/null +++ b/noti-worker-delayed/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] +} diff --git a/noti-worker-delayed/tsconfig.json b/noti-worker-delayed/tsconfig.json new file mode 100644 index 0000000..adb614c --- /dev/null +++ b/noti-worker-delayed/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "es2017", + "sourceMap": true, + "outDir": "./dist", + "baseUrl": "./", + "incremental": true, + "skipLibCheck": true, + "strictNullChecks": false, + "noImplicitAny": false, + "strictBindCallApply": false, + "forceConsistentCasingInFileNames": false, + "noFallthroughCasesInSwitch": false + } +} diff --git a/noti-worker-immediate/.env b/noti-worker-immediate/.env new file mode 100644 index 0000000..3e68015 --- /dev/null +++ b/noti-worker-immediate/.env @@ -0,0 +1,8 @@ +EMAIL_SERVICE=RunWithMe +EMAIL_HOST=smtp.worksmobile.com +EMAIL_PORT=587 +EMAIL_USER=admin@runwithme.co.kr +EMAIL_PW=2HMxdMVBXa68 + +REDIS_HOST=localhost +REDIS_PORT=6379 \ No newline at end of file diff --git a/noti-worker-immediate/.eslintrc.js b/noti-worker-immediate/.eslintrc.js new file mode 100644 index 0000000..8f5aedb --- /dev/null +++ b/noti-worker-immediate/.eslintrc.js @@ -0,0 +1,25 @@ +module.exports = { + parser: '@typescript-eslint/parser', + parserOptions: { + project: 'tsconfig.json', + tsconfigRootDir : __dirname, + sourceType: 'module', + }, + plugins: ['@typescript-eslint/eslint-plugin'], + extends: [ + 'plugin:@typescript-eslint/recommended', + 'plugin:prettier/recommended', + ], + root: true, + env: { + node: true, + jest: true, + }, + ignorePatterns: ['.eslintrc.js'], + 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', + }, +}; diff --git a/noti-worker-immediate/.gitignore b/noti-worker-immediate/.gitignore new file mode 100644 index 0000000..22f55ad --- /dev/null +++ b/noti-worker-immediate/.gitignore @@ -0,0 +1,35 @@ +# compiled output +/dist +/node_modules + +# 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 \ No newline at end of file diff --git a/noti-worker-immediate/.prettierrc b/noti-worker-immediate/.prettierrc new file mode 100644 index 0000000..dcb7279 --- /dev/null +++ b/noti-worker-immediate/.prettierrc @@ -0,0 +1,4 @@ +{ + "singleQuote": true, + "trailingComma": "all" +} \ No newline at end of file diff --git a/noti-worker-immediate/README.md b/noti-worker-immediate/README.md new file mode 100644 index 0000000..00a13b1 --- /dev/null +++ b/noti-worker-immediate/README.md @@ -0,0 +1,73 @@ +

+ Nest Logo +

+ +[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456 +[circleci-url]: https://circleci.com/gh/nestjs/nest + +

A progressive Node.js framework for building efficient and scalable server-side applications.

+

+NPM Version +Package License +NPM Downloads +CircleCI +Coverage +Discord +Backers on Open Collective +Sponsors on Open Collective + + Support us + +

+ + +## Description + +[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository. + +## Installation + +```bash +$ npm install +``` + +## Running the app + +```bash +# development +$ npm run start + +# watch mode +$ npm run start:dev + +# production mode +$ npm run start:prod +``` + +## Test + +```bash +# unit tests +$ npm run test + +# e2e tests +$ npm run test:e2e + +# test coverage +$ npm run test:cov +``` + +## Support + +Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support). + +## Stay in touch + +- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com) +- Website - [https://nestjs.com](https://nestjs.com/) +- Twitter - [@nestframework](https://twitter.com/nestframework) + +## License + +Nest is [MIT licensed](LICENSE). diff --git a/noti-worker-immediate/nest-cli.json b/noti-worker-immediate/nest-cli.json new file mode 100644 index 0000000..2566481 --- /dev/null +++ b/noti-worker-immediate/nest-cli.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://json.schemastore.org/nest-cli", + "collection": "@nestjs/schematics", + "sourceRoot": "src" +} diff --git a/noti-worker-immediate/package.json b/noti-worker-immediate/package.json new file mode 100644 index 0000000..02ba79b --- /dev/null +++ b/noti-worker-immediate/package.json @@ -0,0 +1,75 @@ +{ + "name": "noti-worker", + "version": "0.0.1", + "description": "", + "author": "", + "private": true, + "license": "UNLICENSED", + "scripts": { + "prebuild": "rimraf dist", + "build": "nest build", + "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", + "start": "nest start", + "start:dev": "nest start --watch", + "start:debug": "nest start --debug --watch", + "start:prod": "node dist/main", + "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" + }, + "dependencies": { + "@nestjs-modules/mailer": "^1.8.1", + "@nestjs/bull": "^0.6.2", + "@nestjs/common": "^9.0.0", + "@nestjs/config": "^2.2.0", + "@nestjs/core": "^9.0.0", + "@nestjs/platform-express": "^9.0.0", + "bull": "^4.10.2", + "reflect-metadata": "^0.1.13", + "rimraf": "^3.0.2", + "rxjs": "^7.2.0" + }, + "devDependencies": { + "@nestjs/cli": "^9.0.0", + "@nestjs/schematics": "^9.0.0", + "@nestjs/testing": "^9.0.0", + "@types/express": "^4.17.13", + "@types/jest": "28.1.8", + "@types/node": "^16.0.0", + "@types/supertest": "^2.0.11", + "@typescript-eslint/eslint-plugin": "^5.0.0", + "@typescript-eslint/parser": "^5.0.0", + "eslint": "^8.0.1", + "eslint-config-prettier": "^8.3.0", + "eslint-plugin-prettier": "^4.0.0", + "jest": "28.1.3", + "prettier": "^2.3.2", + "source-map-support": "^0.5.20", + "supertest": "^6.1.3", + "ts-jest": "28.0.8", + "ts-loader": "^9.2.3", + "ts-node": "^10.0.0", + "tsconfig-paths": "4.1.0", + "typescript": "^4.7.4" + }, + "jest": { + "moduleFileExtensions": [ + "js", + "json", + "ts" + ], + "rootDir": "src", + "testRegex": ".*\\.spec\\.ts$", + "transform": { + "^.+\\.(t|j)s$": "ts-jest" + }, + "collectCoverageFrom": [ + "**/*.(t|j)s" + ], + "coverageDirectory": "../coverage", + "testEnvironment": "node" + } +} diff --git a/noti-server/src/app.immediate.consumer.ts b/noti-worker-immediate/src/app.consumer.ts similarity index 100% rename from noti-server/src/app.immediate.consumer.ts rename to noti-worker-immediate/src/app.consumer.ts diff --git a/noti-worker-immediate/src/app.module.ts b/noti-worker-immediate/src/app.module.ts new file mode 100644 index 0000000..af2c2d6 --- /dev/null +++ b/noti-worker-immediate/src/app.module.ts @@ -0,0 +1,23 @@ +import { Module } from '@nestjs/common'; +import { ImmediateConsumer } from './app.consumer'; +import { ConfigModule } from '@nestjs/config'; +import { BullModule } from '@nestjs/bull'; +import { MailModule } from './mail/mail.module'; + +@Module({ + imports: [ + ConfigModule.forRoot({ + isGlobal: true, + }), + BullModule.forRoot({ + redis: { + host: process.env.REDIS_HOST, + port: Number(process.env.REDIS_PORT), + }, + }), + MailModule, + BullModule.registerQueue({ name: 'immediate' }), + ], + providers: [ImmediateConsumer], +}) +export class AppModule {} diff --git a/noti-worker-immediate/src/common/templates/cancel.hbs b/noti-worker-immediate/src/common/templates/cancel.hbs new file mode 100644 index 0000000..2ad097c --- /dev/null +++ b/noti-worker-immediate/src/common/templates/cancel.hbs @@ -0,0 +1,33 @@ +
+
+
+

나만의 코스로 함께 + 달리는 러닝 커뮤니티

+
+

모임이 취소되었어요😥😥

+
+
+

모임 제목

+

{{title}}

+
+
+

집합 위치

+

{{hName}}

+
+
+

집합 일시

+

{{startTime}}

+
+
+

총거리

+

{{pathLength}}km

+
+
+
+
+

행복회로 | 서울특별시 중구 남산동2가 + 32-13 303호

+
+
+
\ No newline at end of file diff --git a/noti-worker-immediate/src/common/templates/recruit.hbs b/noti-worker-immediate/src/common/templates/recruit.hbs new file mode 100644 index 0000000..a2ceec2 --- /dev/null +++ b/noti-worker-immediate/src/common/templates/recruit.hbs @@ -0,0 +1,38 @@ +
+
+
+

나만의 코스로 함께 + 달리는 러닝 커뮤니티

+
+

잠시후 출발하는 모임이 있습니다

+
+
+

모임 제목

+

{{title}}

+
+
+

집합 위치

+

{{hName}}

+
+
+

집합 일시

+

{{startTime}}

+
+
+

총거리

+

{{pathLength}}km

+
+
+ +
+
+

행복회로 | 서울특별시 중구 남산동2가 + 32-13 303호

+
+
+
\ No newline at end of file diff --git a/noti-worker-immediate/src/common/templates/signup.hbs b/noti-worker-immediate/src/common/templates/signup.hbs new file mode 100644 index 0000000..98caf28 --- /dev/null +++ b/noti-worker-immediate/src/common/templates/signup.hbs @@ -0,0 +1,23 @@ +
+
+
+

나만의 코스로 함께 + 달리는 러닝 커뮤니티

+
+

{{id}}님 가입을 환영합니다.🎉

+

+ 지금부터 이 계정으로 RunWithMe를 이용하실 수 있어요 :) +

+ +
+
+

행복회로 | 서울특별시 중구 남산동2가 + 32-13 303호

+
+
+
\ No newline at end of file diff --git a/noti-worker-immediate/src/mail/mail.module.ts b/noti-worker-immediate/src/mail/mail.module.ts new file mode 100644 index 0000000..b96e0a5 --- /dev/null +++ b/noti-worker-immediate/src/mail/mail.module.ts @@ -0,0 +1,35 @@ +import { Module } from '@nestjs/common'; +import { MailService } from './mail.service'; +import { MailerModule } from '@nestjs-modules/mailer'; +import { ConfigModule, ConfigService } from '@nestjs/config'; +import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter'; + +@Module({ + imports: [ + MailerModule.forRootAsync({ + imports: [ConfigModule], + useFactory: async (config: ConfigService) => ({ + transport: { + service: config.get('EMAIL_SERVICE'), + host: config.get('EMAIL_HOST'), + port: config.get('EMAIL_PORT'), + auth: { + user: config.get('EMAIL_USER'), + pass: config.get('EMAIL_PW'), + }, + }, + template: { + dir: process.cwd() + '/src/common/templates/', + adapter: new HandlebarsAdapter(), + options: { + strict: true, + }, + }, + }), + inject: [ConfigService], + }), + ], + providers: [MailService], + exports: [MailService], +}) +export class MailModule {} diff --git a/noti-worker-immediate/src/mail/mail.service.ts b/noti-worker-immediate/src/mail/mail.service.ts new file mode 100644 index 0000000..5c74d23 --- /dev/null +++ b/noti-worker-immediate/src/mail/mail.service.ts @@ -0,0 +1,49 @@ +import { Injectable } from '@nestjs/common'; +import { MailerService } from '@nestjs-modules/mailer'; + +@Injectable() +export class MailService { + constructor(private mailService: MailerService) {} + + async sendEmail( + type: string, + email: string | Array, + data: any, + ): Promise { + try { + const { subject, template } = this.getTemplate(type); + await this.mailService.sendMail({ + from: process.env.EMAIL_USER, + to: email, + subject, + template, + context: data, + }); + } catch (err) { + throw new Error(err); + } + } + + getTemplate(type: string) { + if (type === 'signup') { + return { + subject: 'RunWithMe: 회원가입을 환영합니다.', + template: 'signup', + }; + } + + if (type === 'recruit') { + return { + subject: 'RunWithMe: 회원님이 참여중인 러닝 모임이 곧 시작됩니다!', + template: 'recruit', + }; + } + + if (type === 'cancel') { + return { + subject: 'RunWithMe: 회원님이 참여중인 모집이 취소되었어요...', + template: 'cancel', + }; + } + } +} diff --git a/noti-worker-immediate/src/main.ts b/noti-worker-immediate/src/main.ts new file mode 100644 index 0000000..1a7cc54 --- /dev/null +++ b/noti-worker-immediate/src/main.ts @@ -0,0 +1,8 @@ +import { NestFactory } from '@nestjs/core'; +import { AppModule } from './app.module'; + +async function bootstrap() { + const app = await NestFactory.create(AppModule); + await app.listen(14001); +} +bootstrap(); diff --git a/noti-worker-immediate/tsconfig.build.json b/noti-worker-immediate/tsconfig.build.json new file mode 100644 index 0000000..64f86c6 --- /dev/null +++ b/noti-worker-immediate/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] +} diff --git a/noti-worker-immediate/tsconfig.json b/noti-worker-immediate/tsconfig.json new file mode 100644 index 0000000..adb614c --- /dev/null +++ b/noti-worker-immediate/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "declaration": true, + "removeComments": true, + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "target": "es2017", + "sourceMap": true, + "outDir": "./dist", + "baseUrl": "./", + "incremental": true, + "skipLibCheck": true, + "strictNullChecks": false, + "noImplicitAny": false, + "strictBindCallApply": false, + "forceConsistentCasingInFileNames": false, + "noFallthroughCasesInSwitch": false + } +}