Skip to content
Snippets Groups Projects
Commit 6046da4e authored by ncastejon's avatar ncastejon
Browse files

Initial commit. Email service

parents
No related branches found
No related tags found
No related merge requests found
node_modules
npm-debug.log
\ No newline at end of file
*.csv
*.dat
*.iml
*.log
*.out
*.pid
*.seed
*.sublime-*
*.swo
*.swp
*.tgz
*.xml
.DS_Store
.idea
.project
.strong-pm
coverage
node_modules
npm-debug.log
{
"singleQuote": true,
"trailingComma": "all"
}
\ No newline at end of file
FROM node:8
# Create app directory
WORKDIR /app
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
#RUN npm install --only=production
# Bundle app source
COPY . .
CMD npm run start:dev
EXPOSE 3000
<p align="center">
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
</p>
[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master
[travis-url]: https://travis-ci.org/nestjs/nest
[linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux
[linux-url]: https://travis-ci.org/nestjs/nest
<p align="center">A progressive <a href="http://nodejs.org" target="blank">Node.js</a> framework for building efficient and scalable server-side applications, heavily inspired by <a href="https://angular.io" target="blank">Angular</a>.</p>
<p align="center">
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
<a href="https://travis-ci.org/nestjs/nest"><img src="https://api.travis-ci.org/nestjs/nest.svg?branch=master" alt="Travis" /></a>
<a href="https://travis-ci.org/nestjs/nest"><img src="https://img.shields.io/travis/nestjs/nest/master.svg?label=linux" alt="Linux" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a>
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a>
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a>
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
</p>
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
## 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
# incremental rebuild (webpack)
$ npm run webpack
$ npm run start:hmr
# 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).
version: '3.1'
services:
service-email:
build: .
ports:
- 3001: 3000
\ No newline at end of file
{
"language": "ts",
"collection": "@nestjs/schematics",
"sourceRoot": "src"
}
{
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "node --inspect-brk -r ts-node/register src/main.ts"
}
\ No newline at end of file
{
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.spec.ts"],
"exec": "ts-node -r tsconfig-paths/register src/main.ts"
}
This diff is collapsed.
{
"name": "service-email",
"version": "0.0.0",
"description": "description",
"author": "",
"license": "MIT",
"scripts": {
"format": "prettier --write \"src/**/*.ts\"",
"start": "ts-node -r tsconfig-paths/register src/main.ts",
"start:dev": "nodemon",
"start:debug": "nodemon --config nodemon-debug.json",
"prestart:prod": "rimraf dist && tsc",
"start:prod": "node dist/main.js",
"start:hmr": "node dist/server",
"lint": "tslint -p tsconfig.json -c tslint.json",
"test": "jest",
"test:watch": "jest --watch",
"test:cov": "jest --coverage",
"test:e2e": "jest --config ./test/jest-e2e.json",
"webpack": "webpack --config webpack.config.js"
},
"dependencies": {
"@nestjs/common": "^5.1.0",
"@nestjs/core": "^5.1.0",
"@nestjs/swagger": "^2.5.1",
"class-validator": "^0.9.1",
"reflect-metadata": "^0.1.12",
"rxjs": "^6.2.2",
"typescript": "^3.0.1"
},
"devDependencies": {
"@nestjs/testing": "^5.1.0",
"@types/express": "^4.16.0",
"@types/jest": "^23.3.1",
"@types/node": "^10.7.1",
"@types/supertest": "^2.0.5",
"jest": "^23.5.0",
"nodemon": "^1.18.3",
"prettier": "^1.14.2",
"rimraf": "^2.6.2",
"supertest": "^3.1.0",
"ts-jest": "^23.1.3",
"ts-loader": "^4.4.2",
"ts-node": "^7.0.1",
"tsconfig-paths": "^3.5.0",
"tslint": "5.11.0",
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0",
"webpack-node-externals": "^1.7.2"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".spec.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
}
import { Module } from '@nestjs/common';
import { EmailModule } from 'email/email.module';
@Module({
imports: [EmailModule],
controllers: [],
providers: [],
})
export class AppModule {}
import { Test, TestingModule } from '@nestjs/testing';
import { EmailController } from './email.controller';
describe('Email Controller', () => {
let module: TestingModule;
beforeAll(async () => {
module = await Test.createTestingModule({
controllers: [EmailController],
}).compile();
});
it('should be defined', () => {
const controller: EmailController = module.get<EmailController>(EmailController);
expect(controller).toBeDefined();
});
});
import { Controller, Post, Body } from '@nestjs/common';
import { Email } from './email';
import { EmailService } from './email.service';
import { ApiBadRequestResponse, ApiOkResponse } from '@nestjs/swagger';
@Controller('email')
export class EmailController {
constructor(
private emailService: EmailService,
) {}
@Post('send')
@ApiOkResponse({ description: 'OK'})
@ApiBadRequestResponse({ description: 'Missing fields'})
create(@Body() email: Email) {
return this.emailService.send(email);
}
}
import { Module } from '@nestjs/common';
import { EmailService } from './email.service';
import { EmailController } from './email.controller';
@Module({
providers: [EmailService],
controllers: [EmailController],
})
export class EmailModule {}
import { Test, TestingModule } from '@nestjs/testing';
import { EmailService } from './email.service';
describe('EmailService', () => {
let service: EmailService;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [EmailService],
}).compile();
service = module.get<EmailService>(EmailService);
});
it('should be defined', () => {
expect(service).toBeDefined();
});
});
import { Injectable } from '@nestjs/common';
import * as amqp from 'amqplib/callback_api';
import { Email } from './email';
@Injectable()
export class EmailService {
send(email: Email) {
const rabbitmqUrl = 'amqp://user:password123@0.0.0.0:5672';
const mailerQueue = 'portail-data-send-email';
// Connect to rabbitmq
amqp.connect(rabbitmqUrl, (err, conn) => {
if (err != null) { console.log(err); };
// Create a communication channel
conn.createChannel((error, ch) => {
if (error != null) console.log(error);
// Stringify and bufferise message
const buffer = Buffer.from(JSON.stringify(email));
ch.assertQueue(mailerQueue, { durable: true });
ch.sendToQueue(mailerQueue, buffer);
console.log(`sent to queue ${mailerQueue}: ${JSON.stringify(email)}`);
});
setTimeout(() => {
conn.close();
}, 500);
});
}
}
import { IsDefined } from 'class-validator';
import { ApiModelProperty, ApiModelPropertyOptional } from '@nestjs/swagger';
export class Email {
@ApiModelProperty()
@IsDefined()
to: string[];
@ApiModelProperty()
@IsDefined()
from: string;
@ApiModelPropertyOptional()
cc: string[];
@ApiModelPropertyOptional()
bcc: string[];
@ApiModelProperty()
@IsDefined()
subject: string;
@ApiModelProperty()
@IsDefined()
text: string;
}
\ No newline at end of file
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { ValidationPipe } from '@nestjs/common';
import * as fs from 'fs';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({ credentials: true, origin: true});
const options = new DocumentBuilder()
.setBasePath('')
.setTitle('Portail Data Email MicroService API')
.setDescription('APIs description for the Email API')
.setVersion('0.1')
.build();
const document = SwaggerModule.createDocument(app, options);
fs.writeFileSync('./swagger-spec.json', JSON.stringify(document));
SwaggerModule.setup('api', app, document);
app.useGlobalPipes(new ValidationPipe());
await app.listen(3000);
}
bootstrap();
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"noImplicitAny": false,
"removeComments": true,
"noLib": false,
"allowSyntheticDefaultImports": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es6",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./src"
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment