Compare commits

...

143 Commits

Author SHA1 Message Date
Kamil Myśliwiec
2b29461a68 chore(release) publish v4.6.3 2018-02-16 11:49:52 +01:00
Kamil Myśliwiec
a763e00507 Update CHANGELOG.md 2018-02-16 11:35:05 +01:00
Kamil Myśliwiec
649d99e09f Update CHANGELOG.md 2018-02-16 11:25:23 +01:00
Kamil Myśliwiec
581e183246 Update CHANGELOG.md 2018-02-16 11:24:52 +01:00
Kamil Myśliwiec
375028dbf2 Auto stash before merge of "master" and "origin/master" 2018-02-16 00:23:26 +01:00
Kamil Myśliwiec
97c6ae4481 Merge remote-tracking branch 'origin/master' 2018-02-16 00:23:08 +01:00
Kamil Myśliwiec
325748d945 chore(release) publish v4.6.2 2018-02-16 00:21:53 +01:00
Kamil Myśliwiec
e8d017398c Update CHANGELOG.md 2018-02-15 22:53:13 +01:00
Kamil Myśliwiec
0c06d41c9d chore(release) publish v4.6.1 2018-02-15 22:45:13 +01:00
Kamil Myśliwiec
7fb15113fa Auto stash before merge of "master" and "origin/master" 2018-02-15 22:40:18 +01:00
Kamil Myśliwiec
d489788248 chore(release) publish v4.6.1 2018-02-15 22:37:32 +01:00
Kamil Myśliwiec
ebf5dad9bb Merge remote-tracking branch 'origin/master' 2018-02-15 22:31:23 +01:00
Kamil Myśliwiec
7bc156f01e chore(release) publish v4.6.1 2018-02-15 22:24:53 +01:00
Kamil Myśliwiec
2c0902f248 Merge pull request #413 from BrianDGLS/patch-2
refactor(@common/utils): remove unused import in forward ref util
2018-02-13 13:46:00 +01:00
BrianDGLS
edaf60fea9 refactor(@common/utils): remove yarn.lock 2018-02-12 16:10:59 +00:00
BrianDGLS
5c47ccd78e refactor(@common/utils): remove unused import in forward ref util 2018-02-12 16:10:47 +00:00
Kamil Myśliwiec
6bb6286761 chore(release) publish v4.6.0 2018-02-11 23:46:25 +01:00
Kamil Myśliwiec
9ca38166dd Merge remote-tracking branch 'origin/master' 2018-02-11 23:45:05 +01:00
Kamil Myśliwiec
a2a00ad31a chore(release) publish v4.6.0 2018-02-11 23:44:11 +01:00
Kamil Myśliwiec
5fe79633bf chore(release) publish v4.6.0 2018-02-11 23:40:24 +01:00
Kamil Myśliwiec
450368779c chore(release) publish v4.5.12@next 2018-02-11 14:35:13 +01:00
Kamil Myśliwiec
4feba7504f chore(release) publish v4.5.12 2018-02-11 13:53:48 +01:00
Kamil Myśliwiec
d804d65cde chore(release) publish v4.5.11 2018-02-11 13:14:55 +01:00
Kamil Myśliwiec
3e2d887a12 tests(@nestjs/common) fix ValidationPipe spec files 2018-02-11 13:12:16 +01:00
Kamil Myśliwiec
e4549f8701 Merge branch 'fwoelffel-improve-validation-pipe' 2018-02-11 12:26:46 +01:00
Kamil Myśliwiec
80481a5117 Merge branch 'improve-validation-pipe' of https://github.com/fwoelffel/nest into fwoelffel-improve-validation-pipe 2018-02-11 12:25:50 +01:00
Kamil Myśliwiec
86e32f6aed Merge remote-tracking branch 'origin/master' 2018-02-11 12:24:46 +01:00
Kamil Myśliwiec
7415021ba1 feature(@nestjs/common) add enable() wrapper around express app 2018-02-11 12:24:34 +01:00
Kamil Myśliwiec
cd5ab322cb Merge pull request #408 from BrianDGLS/patch-1
refactor(examples): remove unneeded whitespace
2018-02-11 12:17:05 +01:00
Kamil Myśliwiec
ea1f1b14bd Merge remote-tracking branch 'origin/master' 2018-02-11 12:15:53 +01:00
Kamil Myśliwiec
b6817403ad bugfix(@nestjs/core) fix EXPRESS_REF issue 2018-02-11 12:15:48 +01:00
Kamil Myśliwiec
bc13118eb7 Merge pull request #401 from delasteve/feat/express-disable
feat(common): expose wrapper for express disable
2018-02-11 12:13:56 +01:00
BrianDGLS
b1502a6028 refactor(examples): remove unneeded whitespace for all demoes 2018-02-09 16:01:49 +00:00
Brian Douglas
9147a12705 refactor(examples): remove unneeded whitespace 2018-02-09 15:55:05 +00:00
Stephen Cavaliere
236cf1853f feat(common): expose wrapper for express disable 2018-02-06 17:45:31 -05:00
Frédéric Woelffel
27c083985c refactor(@nestjs/common): mark the ValidatorPipe parameters as optional 2018-02-05 20:27:06 +01:00
Kamil Myśliwiec
4c92b9418e Merge branch 'fwoelffel-improve-validation-pipe' 2018-02-05 16:34:56 +01:00
Kamil Myśliwiec
7fdd07cfa5 feature(@nestjs/common) improve variable name and single condition 2018-02-05 16:32:59 +01:00
Kamil Myśliwiec
11253f5009 Merge branch 'improve-validation-pipe' of https://github.com/fwoelffel/nest into fwoelffel-improve-validation-pipe 2018-02-05 16:18:31 +01:00
Kamil Myśliwiec
1279602f1c Merge branch 'oschweitzer-parseInt-pipe-improvement' 2018-02-05 16:15:44 +01:00
Kamil Myśliwiec
ec6b89160d feature(@nestjs/common) refactor ParseIntPipe 2018-02-05 16:14:12 +01:00
Kamil Myśliwiec
0dd55875f7 Merge branch 'parseInt-pipe-improvement' of https://github.com/oschweitzer/nest into oschweitzer-parseInt-pipe-improvement 2018-02-05 16:08:48 +01:00
Kamil Myśliwiec
2296d30900 Merge branch 'qbodart-controller-inheritance' 2018-02-05 16:07:03 +01:00
Kamil Myśliwiec
75600bc725 Update CHANGELOG.md 2018-02-05 16:05:32 +01:00
Kamil Myśliwiec
bc7914e1df feature(@nestjs/core) use generator instead of local variable 2018-02-05 16:03:10 +01:00
Kamil Myśliwiec
2003c1e7ff Merge branch 'controller-inheritance' of https://github.com/qbodart/nest into qbodart-controller-inheritance 2018-02-05 15:35:38 +01:00
Kamil Myśliwiec
cf5fcbdf0b bugfix(@nestjs/core) nest seems to fails silently #287 2018-02-05 15:34:58 +01:00
Kamil Myśliwiec
fde169636f bugfix(@nestjs/core) inconsistent arguments 2018-02-05 13:10:44 +01:00
Kamil Myśliwiec
7af4a012b4 Merge branch 'master' of https://github.com/nestjs/nest 2018-02-05 13:09:08 +01:00
Kamil Myśliwiec
8cd42f519b Merge branch 'shekohex-nest-router' 2018-02-05 13:08:52 +01:00
Kamil Myśliwiec
8fdf428143 fix missing space, remove yarn.lock 2018-02-05 13:04:22 +01:00
Oli1810
e089a4730f feat(@nestjs/common): update validation condition
This commit also removes the unused rxjs import
2018-02-05 12:40:32 +01:00
Kamil Myśliwiec
d843678ec4 feature(@nestjs/core) injectable APP_REF & Reflector bugfix 2018-02-05 12:39:41 +01:00
Kamil Myśliwiec
e6825dcc7b Merge branch 'nest-router' of https://github.com/shekohex/nest into shekohex-nest-router 2018-02-05 11:47:54 +01:00
Kamil Myśliwiec
08fc594349 feature(@nestjs/core) injectable APP_REF 2018-02-05 11:47:14 +01:00
Kamil Myśliwiec
68edfda978 Update Readme.md 2018-02-04 17:07:39 +01:00
Kamil Myśliwiec
68014d8f95 Update Readme.md 2018-02-04 17:03:52 +01:00
Frédéric Woelffel
aaab2bc6ef refactor(@nestjs/common): rewrite the ValidationPipe constructor
initialize the properties in a more elegant way
2018-02-04 13:04:08 +01:00
Kamil Myśliwiec
f0c92bb328 Merge pull request #374 from 4F2E4A2E/patch-1
Improvement: Unused constant schema
2018-02-04 09:39:32 +01:00
Kamil Myśliwiec
327f402c1c Merge pull request #375 from f3ath/patch-1
Remove unused import
2018-02-04 09:38:53 +01:00
Kamil Myśliwiec
708e36b7ed Merge pull request #395 from pmitrifork/fix-allow-string-pipe-port
Allow providing server port as a string
2018-02-04 09:34:25 +01:00
Frédéric Woelffel
ff229b522f feat(@nestjs/common): improve the ValidationPipe
add support for all class-validator options
2018-02-04 00:59:33 +01:00
Frédéric Woelffel
9992996104 refactor(@nestjs/common): rename the ValidationPipe properties
adopt the class-validator naming scheme
2018-02-04 00:45:34 +01:00
Frédéric Woelffel
eebd72c5e4 feat(@nestjs/common): improve the ValidationPipe
allow to whitelist and forbid properties without transforming the returned object
2018-02-04 00:43:57 +01:00
Przemyslaw Milosz Miszczuk
9ae0953b50 Allows providing string as port (e.g. IIS on Azure uses strings such as "\\.\pipe\d226d7b0-64a0-4d04-96d4-a75e1278b7a9") 2018-02-03 23:20:00 +01:00
Kamil Myśliwiec
7357007a50 Merge pull request #386 from beeman/beeman/add-http-status-418
feat: add HTTP Status Code 418
2018-02-03 20:58:08 +01:00
Shady Khalifa
8ae0a43282 feat(@nestjs/core): add the appilty to have a path prop for the Module by using RouterModule. 2018-01-31 21:43:29 +02:00
Shady Khalifa
2f3732ec77 feat(@nestjs/common) : Module Path 2018-01-31 21:41:09 +02:00
Quentin
dd7ceafc4d feature(@nestjs) Enable inheritance for controllers
Changes to metadataScanner to enable scanning of Parent classes
2018-01-31 12:15:19 +01:00
Bram Borggreve
e2ede3e976 feat: add HTTP Status Code 418 2018-01-30 09:51:00 -05:00
Olivier Schweitzer
f854ae6180 tests(@nestjs/common): update test for parseIntPipe 2018-01-30 09:15:46 +01:00
Olivier Schweitzer
122c145b6c feat(@nestjs/common): improve the parseIntPipe 2018-01-30 09:15:14 +01:00
Olivier Schweitzer
ba00ce65a6 tests(@nestjs/common): add tests for the ValidationPipe 2018-01-29 14:34:09 +01:00
Frédéric Woelffel
dc24a2072e feat(@nestjs/common) improve the ValidationPipe 2018-01-29 14:30:04 +01:00
Alexey
fbd2fea4f1 Remove unused import 2018-01-23 16:33:36 -08:00
4F2E4A2E
fad0e6a208 Improvement: Unused constant schema 2018-01-23 15:36:57 +01:00
Kamil Myśliwiec
18125677b2 examples(@nestjs) update plain mongoose example 2018-01-21 13:52:27 +01:00
Kamil Myśliwiec
43e99499a7 examples(@nestjs) update plain mongoose example 2018-01-21 13:51:37 +01:00
Kamil Myśliwiec
74468739a6 Merge remote-tracking branch 'origin/master' 2018-01-21 13:47:50 +01:00
Kamil Myśliwiec
214037f1bb examples(@nestjs) update websockets & graphql & mongoose 2018-01-21 13:47:42 +01:00
Kamil Myśliwiec
3ea0bd9d45 Merge pull request #369 from amitport/patch-1
remove old autoSchemaSync
2018-01-21 10:58:16 +01:00
Amit Portnoy
ee05a31f64 remove old autoSchemaSync 2018-01-21 11:37:52 +02:00
Kamil Myśliwiec
fc3e2fde78 bugfix(@nestjs/core) router execution context issue #343 2018-01-16 17:20:06 +01:00
Kamil Myśliwiec
b6cba3784d chore(release) publish v4.5.10 2018-01-13 20:43:38 +01:00
Kamil Myśliwiec
957929e31d chore(release) publish v4.5.9 2018-01-13 01:00:44 +01:00
Kamil Myśliwiec
4bcfe79e07 chore(release) publish v4.5.8 2018-01-12 13:16:55 +01:00
Kamil Myśliwiec
77b778f044 chore(release) publish v4.5.8 2018-01-12 12:37:49 +01:00
Kamil Myśliwiec
466dc841c0 Merge pull request #342 from leokraken/fix/graphqlexample
[Fix] Graphql example
2018-01-11 11:29:20 +01:00
Kamil Myśliwiec
5caef83200 Update cats.types.graphql 2018-01-11 11:28:42 +01:00
Kamil Myśliwiec
6cbe49604c Update cats.resolvers.ts 2018-01-11 11:28:17 +01:00
Kamil Myśliwiec
3bb2e2489e Update Readme.md 2018-01-09 15:50:36 +01:00
leokraken
e57203c2b8 Fix graphql basic example 2018-01-08 20:06:20 -03:00
Kamil Myśliwiec
23624dec23 Update Readme.md 2018-01-08 11:43:27 +01:00
Kamil Myśliwiec
37392212c9 Update Readme.md 2018-01-08 09:46:21 +01:00
Kamil Myśliwiec
4d32bc3508 Merge pull request #340 from patrickhousley/bugfix/symbol-injection
fix(core): support symbols
2018-01-06 12:55:08 +01:00
Patrick Housley
4359785f5b fix(core): support symbols
Support for the use of symbols as the provided in modules exports was
broken as a result of
https://github.com/nestjs/nest/compare/v4.5.5...master#diff-f52585e35398d156c2cd41f3863d4c52R184.
This bugfix corrects the issue by updating the changed code to test for
and support symbols.
2018-01-05 18:16:13 -06:00
Kamil Myśliwiec
ceb0ecbdcd Merge remote-tracking branch 'origin/master' 2018-01-05 11:20:51 +01:00
Kamil Myśliwiec
df48878d6b bugfix(@nestjs/core) bugfix #337 2018-01-05 11:20:35 +01:00
Kamil Myśliwiec
cfa9115526 chore(release) publish v4.5.7 2018-01-05 11:07:32 +01:00
Kamil Myśliwiec
496285d9d1 Merge pull request #334 from vladotesanovic/master
Update dependency in mockgoose example
2018-01-04 15:43:59 +01:00
Vlado Tešanović
acbb857fcd Update dependency to mockgoose-fix 2018-01-02 22:05:30 +01:00
Vlado Tesanovic
6e9f432d06 Merge pull request #1 from nestjs/master
Update
2018-01-02 21:51:35 +01:00
Kamil Myśliwiec
9e3b07de6f examples(@nestjs) update examples 2018-01-02 16:02:19 +01:00
Kamil Myśliwiec
46a961c8d7 chore(@nestjs) release v4.5.6 2018-01-02 15:52:11 +01:00
Kamil Myśliwiec
e12141dc70 chore(release) publish v4.5.6 2018-01-02 15:15:04 +01:00
Kamil Myśliwiec
e9dcac6124 examples(@nestjs) update examples 2018-01-02 12:38:48 +01:00
Kamil Myśliwiec
ab86e44f0a chore(release) publish v4.5.5 2018-01-02 12:11:43 +01:00
Kamil Myśliwiec
5ed8c5980b bugfix(@nestjs/core) dynamic modules imports 2017-12-31 12:48:18 +01:00
Kamil Myśliwiec
601de0fe46 chore(release) publish v4.5.4 2017-12-30 22:36:13 +01:00
Kamil Myśliwiec
3150c19a8e chore(release) publish v4.5.3 2017-12-30 14:14:46 +01:00
Kamil Myśliwiec
5e58318894 Merge remote-tracking branch 'origin/master' 2017-12-30 13:59:18 +01:00
Kamil Myśliwiec
13ddd03356 examples(@nestjs) update examples 2017-12-30 13:56:46 +01:00
Kamil Myśliwiec
606557864b Merge pull request #327 from xeoneux/patch-1
Create express server if not provided in testing
2017-12-30 13:55:58 +01:00
Kamil Myśliwiec
2b1898c00b Update Readme.md 2017-12-23 11:45:08 +01:00
Aayush Kapoor
74d6c37c8b Create express server if not provided in testing 2017-12-23 15:06:40 +05:30
Kamil Myśliwiec
d2875bfcab chore(release) publish v4.5.2 2017-12-22 15:22:30 +01:00
Kamil Myśliwiec
200e6cb673 chore(release) publish v4.5.2 2017-12-22 15:12:33 +01:00
Kamil Myśliwiec
e83aca183d update(@core) increase router performance 2017-12-22 15:08:46 +01:00
Kamil Myśliwiec
2a6ca015fc cov(@nestjs) increase test coverage 2017-12-21 22:03:16 +01:00
Kamil Myśliwiec
864fac9cea feature(@common) rename modules to imports property 2017-12-21 20:26:45 +01:00
Kamil Myśliwiec
2a727b9024 Merge remote-tracking branch 'origin/master' 2017-12-21 20:17:29 +01:00
Kamil Myśliwiec
d7b0e0557b ci(@nestjs) update prettier options 2017-12-21 20:14:23 +01:00
Kamil Myśliwiec
52e0128258 ci(@nestjs) integrate with prettier 2017-12-21 19:29:39 +01:00
Kamil Myśliwiec
bb0ce8ce3f Update Readme.md 2017-12-21 14:27:29 +01:00
Kamil Myśliwiec
8afafc6c34 Update Readme.md 2017-12-21 14:27:01 +01:00
Kamil Myśliwiec
028c8aacf0 Merge pull request #319 from XerxesMK/patch-2
Removed unused import
2017-12-21 11:47:33 +01:00
Hector Chauran
b605b8871e Removed unused import
`PrimaryGeneratedColumn` is not  being used in `photo.entity.ts` because the example uses mongodb.
2017-12-20 19:22:08 -04:00
Kamil Myśliwiec
81be8a0fbc Merge remote-tracking branch 'origin/master' 2017-12-15 23:41:53 +01:00
Kamil Myśliwiec
27b54d567a update(@nestjs) update package.json 2017-12-15 23:41:47 +01:00
Kamil Myśliwiec
4d4f7a448c Merge pull request #250 from wbhob/contrib
Add contribution guidelines v1
2017-12-15 22:55:35 +01:00
Kamil Myśliwiec
ade7aed794 Merge branch 'master' into contrib 2017-12-15 22:54:13 +01:00
Kamil Myśliwiec
fe24ae456b Merge branch 'master' into contrib 2017-12-15 22:53:32 +01:00
Kamil Myśliwiec
3e0ee2108f chore(release) publish v4.5.1 2017-12-15 22:31:27 +01:00
Kamil Myśliwiec
49bb841615 update(@nestjs) update package.json 2017-12-15 20:59:33 +01:00
Kamil Myśliwiec
ca3ff1b2d8 update(@nestjs) CHANGELOG update 2017-12-15 16:33:01 +01:00
Kamil Myśliwiec
62adce80c8 update(@nestjs) lib & CHANGELOG update 2017-12-15 16:32:05 +01:00
Wilson Hobbs
82cb61aa2b Merge branch 'master' into contrib 2017-11-24 20:52:59 -05:00
Wilson Hobbs
447b8ab624 Fix the last mention of Angular 2017-11-17 09:14:44 -05:00
Wilson Hobbs
5b92c33cb2 Merge branch 'master' of https://github.com/nestjs/nest into contrib 2017-11-16 21:10:57 -05:00
Wilson Hobbs
77817b232f revert(): remove outstanding commit from other PR 2017-11-16 20:47:41 -05:00
Wilson Hobbs
40194281b1 Revert "ci(): add format checker\nthis commit will ensure that every commit is properly formatted. I\'ve included a command, [20:37:16] Using gulpfile ~/nest/gulpfile.js"
This reverts commit c4a3e0296d.
2017-11-16 20:46:37 -05:00
Wilson Hobbs
2984df1395 chore(): add contribution guidelines v1 2017-11-16 20:41:41 -05:00
Wilson Hobbs
c4a3e0296d ci(): add format checker\nthis commit will ensure that every commit is properly formatted. I\'ve included a command, [20:37:16] Using gulpfile ~/nest/gulpfile.js
[20:37:16] Starting 'format'...
[20:37:22] Finished 'format' after 5.76 s that will take care of this for you.\nThis functionality is taken directly from Angular's repository.
2017-11-16 20:37:22 -05:00
765 changed files with 17080 additions and 15691 deletions

2
.gitignore vendored
View File

@@ -1,6 +1,6 @@
# dependencies
node_modules/
package-lock.json
# IDE
/.idea
/.awcache

4
.prettierrc Normal file
View File

@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}

View File

@@ -1,4 +1,74 @@
## 4.5.0@soon
## 4.6.3
### Bug Fixes
- **core**: error thrown when connecting to microservice (hybrid applicaton) [#425](https://github.com/nestjs/nest/issues/425)
## 4.6.2
### Improvements
- **core**: simplify `NestFactory.create(...args)` signature
## 4.6.1
### Improvements
- **common**: create `ModuleMetadata` interface
- **core**: majority of methods (`INestApplication`, `INestMicroservice`, and `INestApplicationContext`) return `this` instead of `void`
- **core**: remove static dependencies & relationships inside `NestFactory`
### Features
- **core**: [feature] add `appOptions` property to `create[..]` methods of `NestFactory`
### Bug Fixes
- **common**: [bugfix] update `class-validator` [#417](https://github.com/nestjs/nest/issues/417)
- **core**: [bugfix] catch error thrown by `bodyParser` in exception filter [#422](https://github.com/nestjs/nest/issues/422)
## 4.6.0
### Features
- **common**: `ValidationPipe` improvements [#383](https://github.com/nestjs/nest/pull/383)
- **common**: `ParseIntPipe` improvements [#385](https://github.com/nestjs/nest/pull/385)
- **common**: add `FileInterceptor`, `FilesInterceptor`, `@UploadedFile()` and `@UploadedFiles()` (`multer` integration)
- **common**: add `HttpModule` that exposes `HttpService` (`axios` integration)
- **core**: add `app.disable()` and `app.enable()` wrappers around `express` app
- **core**: add ability to inject `express` reference (`EXPRESS_REF` token)
- **core**: enable possibility to extend metadata (inheritance support) [#228](https://github.com/nestjs/nest/issues/228)
- **core**: `NestFactory.create()` now accepts third argument `HttpsOptions`
- **core**: add `app.enableCors()` to `INestApplication` (`cors` integration)
- **core**: add `@Render()` decorator (MVC applications)
- **core**: provide `Logger.overrideLogger()` [#247](https://github.com/nestjs/nest/issues/247)
- **microservices**: add `listenAsync()` to `INestMicroservice` instance
### Bug Fixes
- **core**: simplify HTTPS protocol usage
- **core**: custom transport strategy - thrown exceptions issue [#290](https://github.com/nestjs/nest/issues/290)
- **core**: injector fails silently [#287](https://github.com/nestjs/nest/issues/287)
- **core**: secure websockets (`wss://`) [#384](https://github.com/nestjs/nest/issues/384)
- **core**: can't select/get from context when using `NestFactory.createMicroservice()` [#398](https://github.com/nestjs/nest/issues/398)
- **core**: interceptor `$stream` observable returns another observable instead of the response object [#376](https://github.com/nestjs/nest/issues/376)
- **core**: `Observable.throw` from controller results in unhandled rejection promise [#373](https://github.com/nestjs/nest/issues/373)
## 4.5.10
- **core**: [bugfix] #343
- **core**: [bugfix] #337
## 4.5.6
- **core**: [bugfix] dynamic modules `exports`
## 4.5.5
- **core**: [bugfix] add missing `app.engine()` wrapper
## 4.5.4
- **core**: [bugfix] dynamic modules recurrent imports fix
## 4.5.3
- **testing**: [bugfix] issue #326
## 4.5.2
- **common**: [feature] rename `modules` to `imports` (`@Module()` decorator)
- **core**: [feature] exception filters with empty `@Catch()` metadata handle each occurred exception
- **core**: [improvement] increase performance
## 4.5.1
- **common**: [feature] `INestAplication` provides a `getHttpServer()` method now
- **websockets**: [bugfix] `IoAdapter` bugfix
## 4.5.0
- **common**: bugfix #286
- **core**: dynamic modules feature
- **core**: global scope feature

271
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,271 @@
# Contributing to Nest
We would love for you to contribute to Nest and help make it even better than it is
today! As a contributor, here are the guidelines we would like you to follow:
- [Code of Conduct](#coc)
- [Question or Problem?](#question)
- [Issues and Bugs](#issue)
- [Feature Requests](#feature)
- [Submission Guidelines](#submit)
- [Coding Rules](#rules)
- [Commit Message Guidelines](#commit)
<!-- - [Signing the CLA](#cla) -->
<!-- ## <a name="coc"></a> Code of Conduct
Help us keep Nest open and inclusive. Please read and follow our [Code of Conduct][coc]. -->
## <a name="question"></a> Got a Question or Problem?
**Do not open issues for general support questions as we want to keep GitHub issues for bug reports and feature requests.** You've got much better chances of getting your question answered on [Stack Overflow](https://stackoverflow.com/questions/tagged/nestjs) where the questions should be tagged with tag `nestjs`.
Stack Overflow is a much better place to ask questions since:
<!-- - there are thousands of people willing to help on Stack Overflow [maybe one day] -->
- questions and answers stay available for public viewing so your question / answer might help someone else
- Stack Overflow's voting system assures that the best answers are prominently visible.
To save your and our time, we will systematically close all issues that are requests for general support and redirect people to Stack Overflow.
If you would like to chat about the question in real-time, you can reach out via [our gitter channel][gitter].
## <a name="issue"></a> Found a Bug?
If you find a bug in the source code, you can help us by
[submitting an issue](#submit-issue) to our [GitHub Repository][github]. Even better, you can
[submit a Pull Request](#submit-pr) with a fix.
## <a name="feature"></a> Missing a Feature?
You can *request* a new feature by [submitting an issue](#submit-issue) to our GitHub
Repository. If you would like to *implement* a new feature, please submit an issue with
a proposal for your work first, to be sure that we can use it.
Please consider what kind of change it is:
* For a **Major Feature**, first open an issue and outline your proposal so that it can be
discussed. This will also allow us to better coordinate our efforts, prevent duplication of work,
and help you to craft the change so that it is successfully accepted into the project. For your issue name, please prefix your proposal with `[discussion]`, for example "[discussion]: your feature idea".
* **Small Features** can be crafted and directly [submitted as a Pull Request](#submit-pr).
## <a name="submit"></a> Submission Guidelines
### <a name="submit-issue"></a> Submitting an Issue
Before you submit an issue, please search the issue tracker, maybe an issue for your problem already exists and the discussion might inform you of workarounds readily available.
We want to fix all the issues as soon as possible, but before fixing a bug we need to reproduce and confirm it. In order to reproduce bugs we will systematically ask you to provide a minimal reproduction scenario using a repository or [Gist](https://gist.github.com/). Having a live, reproducible scenario gives us wealth of important information without going back & forth to you with additional questions like:
- version of NestJS used
- 3rd-party libraries and their versions
- and most importantly - a use-case that fails
<!--
// TODO we need to create a playground, similar to plunkr
A minimal reproduce scenario using a repository or Gist allows us to quickly confirm a bug (or point out coding problem) as well as confirm that we are fixing the right problem. If neither of these are not a suitable way to demonstrate the problem (for example for issues related to our npm packaging), please create a standalone git repository demonstrating the problem. -->
<!-- We will be insisting on a minimal reproduce scenario in order to save maintainers time and ultimately be able to fix more bugs. Interestingly, from our experience users often find coding problems themselves while preparing a minimal plunk. We understand that sometimes it might be hard to extract essentials bits of code from a larger code-base but we really need to isolate the problem before we can fix it. -->
Unfortunately, we are not able to investigate / fix bugs without a minimal reproduction, so if we don't hear back from you we are going to close an issue that don't have enough info to be reproduced.
You can file new issues by filling out our [new issue form](https://github.com/nestjs/nest/issues/new).
### <a name="submit-pr"></a> Submitting a Pull Request (PR)
Before you submit your Pull Request (PR) consider the following guidelines:
1. Search [GitHub](https://github.com/nestjs/nest/pulls) for an open or closed PR
that relates to your submission. You don't want to duplicate effort.
<!-- 1. Please sign our [Contributor License Agreement (CLA)](#cla) before sending PRs.
We cannot accept code without this. -->
1. Fork the nestjs/nest repo.
1. Make your changes in a new git branch:
```shell
git checkout -b my-fix-branch master
```
1. Create your patch, **including appropriate test cases**.
1. Follow our [Coding Rules](#rules).
1. Run the full Nest test suite, as described in the [developer documentation][dev-doc],
and ensure that all tests pass.
1. Commit your changes using a descriptive commit message that follows our
[commit message conventions](#commit). Adherence to these conventions
is necessary because release notes are automatically generated from these messages.
```shell
git commit -a
```
Note: the optional commit `-a` command line option will automatically "add" and "rm" edited files.
1. Push your branch to GitHub:
```shell
git push origin my-fix-branch
```
1. In GitHub, send a pull request to `nestjs:master`.
* If we suggest changes then:
* Make the required updates.
* Re-run the Nest test suites to ensure tests are still passing.
* Rebase your branch and force push to your GitHub repository (this will update your Pull Request):
```shell
git rebase master -i
git push -f
```
That's it! Thank you for your contribution!
#### After your pull request is merged
After your pull request is merged, you can safely delete your branch and pull the changes
from the main (upstream) repository:
* Delete the remote branch on GitHub either through the GitHub web UI or your local shell as follows:
```shell
git push origin --delete my-fix-branch
```
* Check out the master branch:
```shell
git checkout master -f
```
* Delete the local branch:
```shell
git branch -D my-fix-branch
```
* Update your master with the latest upstream version:
```shell
git pull --ff upstream master
```
## <a name="rules"></a> Coding Rules
To ensure consistency throughout the source code, keep these rules in mind as you are working:
* All features or bug fixes **must be tested** by one or more specs (unit-tests).
<!--
// We're working on auto-documentation.
* All public API methods **must be documented**. (Details TBC). -->
* We follow [Google's JavaScript Style Guide][js-style-guide], but wrap all code at
**100 characters**. An automated formatter is available, see
[DEVELOPER.md](docs/DEVELOPER.md#clang-format).
## <a name="commit"></a> Commit Message Guidelines
We have very precise rules over how our git commit messages can be formatted. This leads to **more
readable messages** that are easy to follow when looking through the **project history**. But also,
we use the git commit messages to **generate the Nest change log**.
### Commit Message Format
Each commit message consists of a **header**, a **body** and a **footer**. The header has a special
format that includes a **type**, a **scope** and a **subject**:
```
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
```
The **header** is mandatory and the **scope** of the header is optional.
Any line of the commit message cannot be longer 100 characters! This allows the message to be easier
to read on GitHub as well as in various git tools.
Footer should contain a [closing reference to an issue](https://help.github.com/articles/closing-issues-via-commit-messages/) if any.
Samples: (even more [samples](https://github.com/nestjs/nest/commits/master))
```
docs(changelog): update change log to beta.5
```
```
fix(release): need to depend on latest rxjs and zone.js
The version in our package.json gets copied to the one we publish, and users need the latest of these.
```
### Revert
If the commit reverts a previous commit, it should begin with `revert: `, followed by the header of the reverted commit. In the body it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.
### Type
Must be one of the following:
* **build**: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
* **ci**: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
* **docs**: Documentation only changes
* **feat**: A new feature
* **fix**: A bug fix
* **perf**: A code change that improves performance
* **refactor**: A code change that neither fixes a bug nor adds a feature
* **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
* **test**: Adding missing tests or correcting existing tests
### Scope
The scope should be the name of the npm package affected (as perceived by person reading changelog generated from commit messages.
The following is the list of supported scopes:
* **common**
* **core**
* **examples**
* **microservices**
* **testing**
* **websockets**
There are currently a few exceptions to the "use package name" rule:
* **packaging**: used for changes that change the npm package layout in all of our packages, e.g. public path changes, package.json changes done to all packages, d.ts file/format changes, changes to bundles, etc.
* **changelog**: used for updating the release notes in CHANGELOG.md
* **examples/#**: for the example apps directory, replacing # with the example app number
<!-- * **aio**: used for docs-app (angular.io) related changes within the /aio directory of the repo -->
* none/empty string: useful for `style`, `test` and `refactor` changes that are done across all packages (e.g. `style: add missing semicolons`)
### Subject
The subject contains succinct description of the change:
* use the imperative, present tense: "change" not "changed" nor "changes"
* don't capitalize first letter
* no dot (.) at the end
### Body
Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
The body should include the motivation for the change and contrast this with previous behavior.
### Footer
The footer should contain any information about **Breaking Changes** and is also the place to
reference GitHub issues that this commit **Closes**.
**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.
A detailed explanation can be found in this [document][commit-message-format].
<!-- ## <a name="cla"></a> Signing the CLA
Please sign our Contributor License Agreement (CLA) before sending pull requests. For any code
changes to be accepted, the CLA must be signed. It's a quick process, we promise!
* For individuals we have a [simple click-through form][individual-cla].
* For corporations we'll need you to
[print, sign and one of scan+email, fax or mail the form][corporate-cla]. -->
<!-- [angular-group]: https://groups.google.com/forum/#!forum/angular -->
<!-- [coc]: https://github.com/angular/code-of-conduct/blob/master/CODE_OF_CONDUCT.md -->
[commit-message-format]: https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#
[corporate-cla]: http://code.google.com/legal/corporate-cla-v1.0.html
[dev-doc]: https://github.com/nestjs/nest/blob/master/docs/DEVELOPER.md
[github]: https://github.com/nestjs/nest
[gitter]: https://gitter.im/nestjs/nest
[individual-cla]: http://code.google.com/legal/individual-cla-v1.0.html
[js-style-guide]: https://google.github.io/styleguide/jsguide.html
[jsfiddle]: http://jsfiddle.net
[plunker]: http://plnkr.co/edit
[runnable]: http://runnable.com
<!-- [stackoverflow]: http://stackoverflow.com/questions/tagged/angular -->

View File

@@ -7,14 +7,14 @@
[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 web applications, heavily inspired by <a href="https://angular.io" target="blank">Angular</a>.</p>
<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#4" alt="Coverage" /></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>
@@ -24,7 +24,7 @@
## Description
<p>Nest is a framework for building efficient, scalable <a href="http://nodejs.org" target="_blank">Node.js</a> web applications. It uses modern JavaScript, is built with <a href="http://www.typescriptlang.org" target="_blank">TypeScript</a> (preserves compatibility with pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).</p>
<p>Nest is a framework for building efficient, scalable <a href="http://nodejs.org" target="_blank">Node.js</a> server-side applications. It uses modern JavaScript, is built with <a href="http://www.typescriptlang.org" target="_blank">TypeScript</a> (preserves compatibility with pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).</p>
<p>Under the hood, Nest makes use of <a href="https://expressjs.com/" target="_blank">Express</a>, allowing for easy use of the myriad third-party plugins which are available.</p>
## Philosophy
@@ -40,7 +40,7 @@ To check out the [guide](https://docs.nestjs.com), visit [docs.nestjs.com](https
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://opencollective.com/nest). Thanks! :heart_eyes:
<a href="https://valor-software.com/"><img src="https://docs.nestjs.com/assets/sponsors/valor-software.png" width="210" /></a>
<a href="https://valor-software.com/"><img src="https://docs.nestjs.com/assets/sponsors/valor-software.png" width="210" /></a> &nbsp; &nbsp; <a href="https://scal.io"><img src="https://nestjs.com/img/scalio-logo.png" width="160" /></a>
## Backers

View File

@@ -1,8 +1,8 @@
import * as express from 'express';
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { CatsModule } from '../../src/modules/cats/cats.module';
import { CatsService } from '../../src/modules/cats/cats.service';
import { CatsModule } from '../../src/cats/cats.module';
import { CatsService } from '../../src/cats/cats.service';
import { INestApplication } from '@nestjs/common';
describe('Cats', () => {
@@ -13,7 +13,7 @@ describe('Cats', () => {
beforeAll(async () => {
const module = await Test.createTestingModule({
modules: [CatsModule],
imports: [CatsModule],
})
.overrideComponent(CatsService)
.useValue(catsService)

View File

@@ -1,14 +1,2 @@
require('ts-node/register');
require('./src/server');
require('./src/main');

View File

@@ -6,7 +6,7 @@
"scripts": {
"start": "node index.js",
"prestart:prod": "tsc",
"start:prod": "node dist/server.js",
"start:prod": "node dist/main.js",
"test": "jest --config=jest.json",
"test:watch": "jest --watch --config=jest.json",
"test:coverage": "jest --config=jest.json --coverage --coverageDirectory=coverage",

View File

@@ -4,12 +4,13 @@ import { CatsModule } from './cats/cats.module';
import { CatsController } from './cats/cats.controller';
@Module({
modules: [CatsModule],
imports: [CatsModule],
})
export class ApplicationModule implements NestModule {
configure(consumer: MiddlewaresConsumer): void {
consumer.apply(LoggerMiddleware)
.with('ApplicationModule')
.forRoutes(CatsController);
}
}
configure(consumer: MiddlewaresConsumer): void {
consumer
.apply(LoggerMiddleware)
.with('ApplicationModule')
.forRoutes(CatsController);
}
}

View File

@@ -8,9 +8,9 @@ describe('CatsController', () => {
beforeEach(async () => {
const module = await Test.createTestingModule({
controllers: [CatsController],
components: [CatsService],
}).compile();
controllers: [CatsController],
components: [CatsService],
}).compile();
catsService = module.get<CatsService>(CatsService);
catsController = module.get<CatsController>(CatsController);
@@ -24,4 +24,4 @@ describe('CatsController', () => {
expect(await catsController.findAll()).toBe(result);
});
});
});
});

View File

@@ -1,4 +1,13 @@
import { Controller, Get, Post, Body, UseGuards, ReflectMetadata, UseInterceptors, Param } from '@nestjs/common';
import {
Controller,
Get,
Post,
Body,
UseGuards,
ReflectMetadata,
UseInterceptors,
Param,
} from '@nestjs/common';
import { CreateCatDto } from './dto/create-cat.dto';
import { CatsService } from './cats.service';
import { Cat } from './interfaces/cat.interface';
@@ -26,7 +35,10 @@ export class CatsController {
}
@Get(':id')
findOne(@Param('id', new ParseIntPipe()) id) {
findOne(
@Param('id', new ParseIntPipe())
id,
) {
// logic
}
}
}

View File

@@ -13,4 +13,4 @@ export class CatsService {
findAll(): Cat[] {
return this.cats;
}
}
}

View File

@@ -0,0 +1,9 @@
import { IsString, IsInt } from 'class-validator';
export class CreateCatDto {
@IsString() readonly name: string;
@IsInt() readonly age: number;
@IsString() readonly breed: string;
}

View File

@@ -2,4 +2,4 @@ export interface Cat {
readonly name: string;
readonly age: number;
readonly breed: string;
}
}

View File

@@ -1,3 +1,3 @@
import { ReflectMetadata } from '@nestjs/common';
export const Roles = (...roles: string[]) => ReflectMetadata('roles', roles);
export const Roles = (...roles: string[]) => ReflectMetadata('roles', roles);

View File

@@ -5,4 +5,4 @@ export class ForbiddenException extends HttpException {
constructor() {
super('Forbidden', HttpStatus.FORBIDDEN);
}
}
}

View File

@@ -11,4 +11,4 @@ export class HttpExceptionFilter implements ExceptionFilter {
message: `It's a message from the exception filter`,
});
}
}
}

View File

@@ -14,7 +14,8 @@ export class RolesGuard implements CanActivate {
}
const user = req.user;
const hasRole = () => !!user.roles.find((role) => !!roles.find((item) => item === role));
const hasRole = () =>
!!user.roles.find(role => !!roles.find(item => item === role));
return user && user.roles && hasRole();
}
}
}

View File

@@ -6,10 +6,14 @@ import 'rxjs/add/observable/of';
export abstract class CacheInterceptor implements NestInterceptor {
protected abstract readonly isCached: () => boolean;
intercept(dataOrRequest, context: ExecutionContext, stream$: Observable<any>): Observable<any> {
intercept(
dataOrRequest,
context: ExecutionContext,
stream$: Observable<any>,
): Observable<any> {
if (this.isCached()) {
return Observable.of([]);
}
return stream$;
}
}
}

View File

@@ -0,0 +1,28 @@
import {
Interceptor,
NestInterceptor,
ExecutionContext,
HttpStatus,
} from '@nestjs/common';
import { HttpException } from '@nestjs/common';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
@Interceptor()
export class ExceptionInterceptor implements NestInterceptor {
intercept(
dataOrRequest,
context: ExecutionContext,
stream$: Observable<any>,
): Observable<any> {
return stream$.catch(err =>
Observable.throw(
new HttpException(
'Exception interceptor message',
HttpStatus.BAD_GATEWAY,
),
),
);
}
}

View File

@@ -4,12 +4,14 @@ import 'rxjs/add/operator/do';
@Interceptor()
export class LoggingInterceptor implements NestInterceptor {
intercept(dataOrRequest, context: ExecutionContext, stream$: Observable<any>): Observable<any> {
intercept(
dataOrRequest,
context: ExecutionContext,
stream$: Observable<any>,
): Observable<any> {
console.log('Before...');
const now = Date.now();
return stream$.do(
() => console.log(`After... ${Date.now() - now}ms`),
);
return stream$.do(() => console.log(`After... ${Date.now() - now}ms`));
}
}
}

View File

@@ -2,7 +2,9 @@ import { mixin } from '@nestjs/common';
import { CacheInterceptor } from './cache.interceptor';
export function mixinCacheInterceptor(isCached: () => boolean) {
return mixin(class extends CacheInterceptor {
protected readonly isCached = isCached;
});
}
return mixin(
class extends CacheInterceptor {
protected readonly isCached = isCached;
},
);
}

View File

@@ -4,7 +4,11 @@ import 'rxjs/add/operator/map';
@Interceptor()
export class TransformInterceptor implements NestInterceptor {
intercept(dataOrRequest, context: ExecutionContext, stream$: Observable<any>): Observable<any> {
return stream$.map((data) => ({ data }));
intercept(
dataOrRequest,
context: ExecutionContext,
stream$: Observable<any>,
): Observable<any> {
return stream$.map(data => ({ data }));
}
}
}

View File

@@ -7,5 +7,5 @@ export class LoggerMiddleware implements NestMiddleware {
console.log(`[${name}] Request...`); // [ApplicationModule] Request...
next();
};
}
}
}
}

View File

@@ -1,5 +1,10 @@
import { HttpException } from '@nestjs/common';
import { PipeTransform, Pipe, ArgumentMetadata, HttpStatus } from '@nestjs/common';
import {
PipeTransform,
Pipe,
ArgumentMetadata,
HttpStatus,
} from '@nestjs/common';
@Pipe()
export class ParseIntPipe implements PipeTransform<string> {
@@ -10,4 +15,4 @@ export class ParseIntPipe implements PipeTransform<string> {
}
return val;
}
}
}

View File

@@ -0,0 +1,30 @@
import { HttpException } from '@nestjs/common';
import {
PipeTransform,
Pipe,
ArgumentMetadata,
HttpStatus,
} from '@nestjs/common';
import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';
@Pipe()
export class ValidationPipe implements PipeTransform<any> {
async transform(value, metadata: ArgumentMetadata) {
const { metatype } = metadata;
if (!metatype || !this.toValidate(metatype)) {
return value;
}
const object = plainToClass(metatype, value);
const errors = await validate(object);
if (errors.length > 0) {
throw new HttpException('Validation failed', HttpStatus.BAD_REQUEST);
}
return value;
}
private toValidate(metatype): boolean {
const types = [String, Boolean, Number, Array, Object];
return !types.find(type => metatype === type);
}
}

View File

@@ -1,6 +1,6 @@
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './modules/app.module';
import { ValidationPipe } from './modules/common/pipes/validation.pipe';
import { ApplicationModule } from './app.module';
import { ValidationPipe } from './common/pipes/validation.pipe';
async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);

View File

@@ -1,9 +0,0 @@
import { Module } from '@nestjs/common';
import { CatsController } from './cats.controller';
import { CatsService } from './cats.service';
@Module({
controllers: [CatsController],
components: [CatsService],
})
export class CatsModule {}

View File

@@ -1,12 +0,0 @@
import { IsString, IsInt } from 'class-validator';
export class CreateCatDto {
@IsString()
readonly name: string;
@IsInt()
readonly age: number;
@IsString()
readonly breed: string;
}

View File

@@ -1,14 +0,0 @@
import { Interceptor, NestInterceptor, ExecutionContext, HttpStatus } from '@nestjs/common';
import { HttpException } from '@nestjs/common';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/catch';
import 'rxjs/add/observable/throw';
@Interceptor()
export class ExceptionInterceptor implements NestInterceptor {
intercept(dataOrRequest, context: ExecutionContext, stream$: Observable<any>): Observable<any> {
return stream$.catch((err) => Observable.throw(
new HttpException('Exception interceptor message', HttpStatus.BAD_GATEWAY),
));
}
}

View File

@@ -1,25 +0,0 @@
import { HttpException } from '@nestjs/common';
import { PipeTransform, Pipe, ArgumentMetadata, HttpStatus } from '@nestjs/common';
import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';
@Pipe()
export class ValidationPipe implements PipeTransform<any> {
async transform(value, metadata: ArgumentMetadata) {
const { metatype } = metadata;
if (!metatype || !this.toValidate(metatype)) {
return value;
}
const object = plainToClass(metatype, value);
const errors = await validate(object);
if (errors.length > 0) {
throw new HttpException('Validation failed', HttpStatus.BAD_REQUEST);
}
return value;
}
private toValidate(metatype): boolean {
const types = [String, Boolean, Number, Array, Object];
return !types.find((type) => metatype === type);
}
}

View File

@@ -2,7 +2,7 @@
<head>
<script src="socket.io.js"></script>
<script>
const socket = io('http://localhost:81');
const socket = io('http://localhost:3000');
socket.on('connect', function() {
console.log('Connected');
socket.emit('events', { test: 'test' });

View File

@@ -1,14 +1,2 @@
require('ts-node/register');
require('./src/server');
require('./src/main');

View File

@@ -6,7 +6,7 @@
"scripts": {
"start": "node index.js",
"prestart:prod": "tsc",
"start:prod": "node dist/server.js"
"start:prod": "node dist/main.js"
},
"dependencies": {
"@nestjs/common": "^4.3.0",

View File

@@ -2,6 +2,6 @@ import { Module } from '@nestjs/common';
import { EventsModule } from './events/events.module';
@Module({
modules: [EventsModule],
imports: [EventsModule],
})
export class ApplicationModule {}
export class ApplicationModule {}

View File

@@ -22,9 +22,9 @@ export class WsAdapter implements WebSocketAdapter {
process: (data: any) => Observable<any>,
) {
Observable.fromEvent(client, 'message')
.switchMap((buffer) => this.bindMessageHandler(buffer, handlers, process))
.filter((result) => !!result)
.subscribe((response) => client.send(JSON.stringify(response)));
.switchMap(buffer => this.bindMessageHandler(buffer, handlers, process))
.filter(result => !!result)
.subscribe(response => client.send(JSON.stringify(response)));
}
public bindMessageHandler(
@@ -33,11 +33,13 @@ export class WsAdapter implements WebSocketAdapter {
process: (data: any) => Observable<any>,
): Observable<any> {
const data = JSON.parse(buffer.data);
const messageHandler = handlers.find((handler) => handler.message === data.type);
const messageHandler = handlers.find(
handler => handler.message === data.type,
);
if (!messageHandler) {
return Observable.empty();
}
const { callback } = messageHandler;
return process(callback(data));
}
}
}

View File

@@ -1,3 +1,3 @@
import { ReflectMetadata } from '@nestjs/common';
export const Roles = (...roles: string[]) => ReflectMetadata('roles', roles);
export const Roles = (...roles: string[]) => ReflectMetadata('roles', roles);

View File

@@ -9,4 +9,4 @@ export class ExceptionFilter implements WsExceptionFilter {
message: `It's a message from the exception filter`,
});
}
}
}

View File

@@ -14,7 +14,8 @@ export class RolesGuard implements CanActivate {
}
const user = data.user;
const hasRole = () => !!user.roles.find((role) => !!roles.find((item) => item === role));
const hasRole = () =>
!!user.roles.find(role => !!roles.find(item => item === role));
return user && user.roles && hasRole();
}
}
}

View File

@@ -4,11 +4,15 @@ import 'rxjs/add/observable/of';
@Interceptor()
export class CacheInterceptor implements NestInterceptor {
intercept(dataOrRequest, context: ExecutionContext, stream$: Observable<any>): Observable<any> {
intercept(
dataOrRequest,
context: ExecutionContext,
stream$: Observable<any>,
): Observable<any> {
const isCached = true;
if (isCached) {
return Observable.of([]);
}
return stream$;
}
}
}

View File

@@ -4,12 +4,14 @@ import 'rxjs/add/operator/do';
@Interceptor()
export class LoggingInterceptor implements NestInterceptor {
intercept(dataOrRequest, context: ExecutionContext, stream$: Observable<any>): Observable<any> {
intercept(
dataOrRequest,
context: ExecutionContext,
stream$: Observable<any>,
): Observable<any> {
console.log('Before...');
const now = Date.now();
return stream$.do(
() => console.log(`After... ${Date.now() - now}ms`),
);
return stream$.do(() => console.log(`After... ${Date.now() - now}ms`));
}
}
}

View File

@@ -4,7 +4,11 @@ import 'rxjs/add/operator/map';
@Interceptor()
export class TransformInterceptor implements NestInterceptor {
intercept(dataOrRequest, context: ExecutionContext, stream$: Observable<any>): Observable<any> {
return stream$.map((data) => ({ data }));
intercept(
dataOrRequest,
context: ExecutionContext,
stream$: Observable<any>,
): Observable<any> {
return stream$.map(data => ({ data }));
}
}
}

View File

@@ -0,0 +1,30 @@
import {
PipeTransform,
Pipe,
ArgumentMetadata,
HttpStatus,
} from '@nestjs/common';
import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';
import { WsException } from '@nestjs/websockets';
@Pipe()
export class ValidationPipe implements PipeTransform<any> {
async transform(value, metadata: ArgumentMetadata) {
const { metatype } = metadata;
if (!metatype || !this.toValidate(metatype)) {
return value;
}
const object = plainToClass(metatype, value);
const errors = await validate(object);
if (errors.length > 0) {
throw new WsException('Validation failed');
}
return value;
}
private toValidate(metatype): boolean {
const types = [String, Boolean, Number, Array, Object];
return !types.find(type => metatype === type);
}
}

View File

@@ -1,9 +1,15 @@
import { WebSocketGateway, SubscribeMessage, WsResponse, WebSocketServer, WsException } from '@nestjs/websockets';
import {
WebSocketGateway,
SubscribeMessage,
WsResponse,
WebSocketServer,
WsException,
} from '@nestjs/websockets';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/from';
import 'rxjs/add/operator/map';
@WebSocketGateway(81)
@WebSocketGateway()
export class EventsGateway {
@WebSocketServer() server;
@@ -12,7 +18,6 @@ export class EventsGateway {
const event = 'events';
const response = [1, 2, 3];
return Observable.from(response)
.map((res) => ({ event, data: res }));
return Observable.from(response).map(res => ({ event, data: res }));
}
}
}

View File

@@ -2,6 +2,6 @@ import { Module } from '@nestjs/common';
import { EventsGateway } from './events.gateway';
@Module({
components: [EventsGateway],
components: [EventsGateway],
})
export class EventsModule {}
export class EventsModule {}

View File

@@ -1,5 +1,5 @@
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './modules/app.module';
import { ApplicationModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);

View File

@@ -1,25 +0,0 @@
import { PipeTransform, Pipe, ArgumentMetadata, HttpStatus } from '@nestjs/common';
import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';
import { WsException } from '@nestjs/websockets';
@Pipe()
export class ValidationPipe implements PipeTransform<any> {
async transform(value, metadata: ArgumentMetadata) {
const { metatype } = metadata;
if (!metatype || !this.toValidate(metatype)) {
return value;
}
const object = plainToClass(metatype, value);
const errors = await validate(object);
if (errors.length > 0) {
throw new WsException('Validation failed');
}
return value;
}
private toValidate(metatype): boolean {
const types = [String, Boolean, Number, Array, Object];
return !types.find((type) => metatype === type);
}
}

View File

@@ -1,14 +1,2 @@
require('ts-node/register');
require('./src/server');
require('./src/main');

View File

@@ -6,7 +6,7 @@
"scripts": {
"start": "node index.js",
"prestart:prod": "tsc",
"start:prod": "node dist/server.js"
"start:prod": "node dist/main.js"
},
"dependencies": {
"@nestjs/common": "^4.3.0",

View File

@@ -2,6 +2,6 @@ import { Module } from '@nestjs/common';
import { MathModule } from './math/math.module';
@Module({
modules: [MathModule],
imports: [MathModule],
})
export class ApplicationModule {}
export class ApplicationModule {}

View File

@@ -2,13 +2,14 @@ import * as amqp from 'amqplib';
import { ClientProxy } from '@nestjs/microservices';
export class RabbitMQClient extends ClientProxy {
constructor(
private readonly host: string,
private readonly queue: string) {
super();
}
constructor(private readonly host: string, private readonly queue: string) {
super();
}
protected async sendSingleMessage(messageObj, callback: (err, result, disposed?: boolean) => void) {
protected async sendSingleMessage(
messageObj,
callback: (err, result, disposed?: boolean) => void,
) {
const server = await amqp.connect(this.host);
const channel = await server.createChannel();
const { sub, pub } = this.getQueues();
@@ -16,15 +17,23 @@ export class RabbitMQClient extends ClientProxy {
channel.assertQueue(sub, { durable: false });
channel.assertQueue(pub, { durable: false });
channel.consume(pub, (message) => this.handleMessage(message, server, callback), { noAck: true });
channel.consume(
pub,
message => this.handleMessage(message, server, callback),
{ noAck: true },
);
channel.sendToQueue(sub, Buffer.from(JSON.stringify(messageObj)));
}
private handleMessage(message, server, callback: (err, result, disposed?: boolean) => void) {
private handleMessage(
message,
server,
callback: (err, result, disposed?: boolean) => void,
) {
const { content } = message;
const { err, response, disposed } = JSON.parse(content.toString());
if (disposed) {
server.close();
server.close();
}
callback(err, response, disposed);
}
@@ -32,4 +41,4 @@ export class RabbitMQClient extends ClientProxy {
private getQueues() {
return { pub: `${this.queue}_pub`, sub: `${this.queue}_sub` };
}
}
}

View File

@@ -3,14 +3,12 @@ import { Server, CustomTransportStrategy } from '@nestjs/microservices';
import { Observable } from 'rxjs/Observable';
export class RabbitMQServer extends Server implements CustomTransportStrategy {
private server: amqp.Connection = null;
private channel: amqp.Channel = null;
private server: amqp.Connection = null;
private channel: amqp.Channel = null;
constructor(
private readonly host: string,
private readonly queue: string) {
super();
}
constructor(private readonly host: string, private readonly queue: string) {
super();
}
public async listen(callback: () => void) {
await this.init();
@@ -31,12 +29,14 @@ export class RabbitMQServer extends Server implements CustomTransportStrategy {
const handlers = this.getHandlers();
const pattern = JSON.stringify(messageObj.pattern);
if (!this.messageHandlers[pattern]) {
return;
return;
}
const handler = this.messageHandlers[pattern];
const response$ = this.transformToObservable(await handler(messageObj.data)) as Observable<any>;
response$ && this.send(response$, (data) => this.sendMessage(data));
const response$ = this.transformToObservable(
await handler(messageObj.data),
) as Observable<any>;
response$ && this.send(response$, data => this.sendMessage(data));
}
private sendMessage(message) {
@@ -50,4 +50,4 @@ export class RabbitMQServer extends Server implements CustomTransportStrategy {
this.channel.assertQueue(`${this.queue}_sub`, { durable: false });
this.channel.assertQueue(`${this.queue}_pub`, { durable: false });
}
}
}

View File

@@ -1,3 +1,3 @@
import { ReflectMetadata } from '@nestjs/common';
export const Roles = (...roles: string[]) => ReflectMetadata('roles', roles);
export const Roles = (...roles: string[]) => ReflectMetadata('roles', roles);

View File

@@ -8,4 +8,4 @@ export class ExceptionFilter implements RpcExceptionFilter {
catch(exception: RpcException): Observable<any> {
return Observable.throw(exception.getError());
}
}
}

View File

@@ -14,7 +14,8 @@ export class RolesGuard implements CanActivate {
}
const user = data.user;
const hasRole = () => !!user.roles.find((role) => !!roles.find((item) => item === role));
const hasRole = () =>
!!user.roles.find(role => !!roles.find(item => item === role));
return user && user.roles && hasRole();
}
}
}

View File

@@ -4,11 +4,15 @@ import 'rxjs/add/observable/of';
@Interceptor()
export class CacheInterceptor implements NestInterceptor {
intercept(dataOrRequest, context: ExecutionContext, stream$: Observable<any>): Observable<any> {
intercept(
dataOrRequest,
context: ExecutionContext,
stream$: Observable<any>,
): Observable<any> {
const isCached = true;
if (isCached) {
return Observable.of([]);
}
return stream$;
}
}
}

View File

@@ -4,12 +4,14 @@ import 'rxjs/add/operator/do';
@Interceptor()
export class LoggingInterceptor implements NestInterceptor {
intercept(dataOrRequest, context: ExecutionContext, stream$: Observable<any>): Observable<any> {
intercept(
dataOrRequest,
context: ExecutionContext,
stream$: Observable<any>,
): Observable<any> {
console.log('Before...');
const now = Date.now();
return stream$.do(
() => console.log(`After... ${Date.now() - now}ms`),
);
return stream$.do(() => console.log(`After... ${Date.now() - now}ms`));
}
}
}

View File

@@ -4,7 +4,11 @@ import 'rxjs/add/operator/map';
@Interceptor()
export class TransformInterceptor implements NestInterceptor {
intercept(dataOrRequest, context: ExecutionContext, stream$: Observable<any>): Observable<any> {
return stream$.map((data) => ({ data }));
intercept(
dataOrRequest,
context: ExecutionContext,
stream$: Observable<any>,
): Observable<any> {
return stream$.map(data => ({ data }));
}
}
}

View File

@@ -0,0 +1,25 @@
import { PipeTransform, Pipe, ArgumentMetadata } from '@nestjs/common';
import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';
import { RpcException } from '@nestjs/microservices';
@Pipe()
export class ValidationPipe implements PipeTransform<any> {
async transform(value, metadata: ArgumentMetadata) {
const { metatype } = metadata;
if (!metatype || !this.toValidate(metatype)) {
return value;
}
const object = plainToClass(metatype, value);
const errors = await validate(object);
if (errors.length > 0) {
throw new RpcException('Validation failed');
}
return value;
}
private toValidate(metatype): boolean {
const types = [String, Boolean, Number, Array, Object];
return !types.find(type => metatype === type);
}
}

View File

@@ -1,14 +1,18 @@
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './modules/app.module';
import { Transport } from '@nestjs/microservices';
import { ApplicationModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.createMicroservice(ApplicationModule);
await app.listenAsync();
/** Hybrid application (HTTP + (n)Microservices)
const app = await NestFactory.create(ApplicationModule);
app.connectMicroservice({
transport: Transport.TCP,
});
await app.startAllMicroservicesAsync();
await app.listen(3001);
await app.listen(3001); */
}
bootstrap();

View File

@@ -1,5 +1,10 @@
import { Controller, Get, UseInterceptors } from '@nestjs/common';
import { ClientProxy, Client, Transport, MessagePattern } from '@nestjs/microservices';
import {
ClientProxy,
Client,
Transport,
MessagePattern,
} from '@nestjs/microservices';
import { Observable } from 'rxjs/Observable';
import { LoggingInterceptor } from '../common/interceptors/logging.interceptor';
@@ -20,4 +25,4 @@ export class MathController {
sum(data: number[]): number {
return (data || []).reduce((a, b) => a + b);
}
}
}

View File

@@ -2,6 +2,6 @@ import { Module } from '@nestjs/common';
import { MathController } from './math.controller';
@Module({
controllers: [MathController],
controllers: [MathController],
})
export class MathModule {}
export class MathModule {}

View File

@@ -1,25 +0,0 @@
import { PipeTransform, Pipe, ArgumentMetadata } from '@nestjs/common';
import { validate } from 'class-validator';
import { plainToClass } from 'class-transformer';
import { RpcException } from '@nestjs/microservices';
@Pipe()
export class ValidationPipe implements PipeTransform<any> {
async transform(value, metadata: ArgumentMetadata) {
const { metatype } = metadata;
if (!metatype || !this.toValidate(metatype)) {
return value;
}
const object = plainToClass(metatype, value);
const errors = await validate(object);
if (errors.length > 0) {
throw new RpcException('Validation failed');
}
return value;
}
private toValidate(metatype): boolean {
const types = [String, Boolean, Number, Array, Object];
return !types.find((type) => metatype === type);
}
}

View File

@@ -1,14 +1,2 @@
require('ts-node/register');
require('./src/server');
require('./src/main');

View File

@@ -6,7 +6,7 @@
"scripts": {
"start": "node index.js",
"prestart:prod": "tsc",
"start:prod": "node dist/server.js"
"start:prod": "node dist/main.js"
},
"dependencies": {
"@nestjs/common": "^4.3.0",

View File

@@ -3,6 +3,6 @@ import { CoreModule } from './core/core.module';
import { FeatureModule } from './feature/feature.module';
@Module({
modules: [FeatureModule],
imports: [FeatureModule],
})
export class ApplicationModule {}
export class ApplicationModule {}

View File

@@ -5,4 +5,4 @@ import { CommonService } from './common.service';
components: [CommonService],
exports: [CommonService],
})
export class CommonModule {}
export class CommonModule {}

View File

@@ -6,4 +6,4 @@ export class CommonService {
constructor(private readonly coreService: CoreService) {
console.log('CommonService', coreService);
}
}
}

View File

@@ -7,4 +7,4 @@ export class ContextService {
constructor(private readonly commonService: CoreService) {
console.log('ContextService', commonService);
}
}
}

View File

@@ -5,8 +5,8 @@ import { ContextService } from './context.service';
import { FeatureModule } from '../feature/feature.module';
@Module({
modules: [CommonModule],
imports: [CommonModule],
components: [CoreService, ContextService],
exports: [CommonModule],
})
export class CoreModule {}
export class CoreModule {}

View File

@@ -5,4 +5,4 @@ export class CoreService {
constructor() {
console.log('CoreService');
}
}
}

View File

@@ -3,7 +3,7 @@ import { FeatureService } from './feature.service';
import { CoreModule } from '../core/core.module';
@Module({
modules: [CoreModule],
imports: [CoreModule],
components: [FeatureService],
})
export class FeatureModule {}
export class FeatureModule {}

View File

@@ -3,8 +3,7 @@ import { CommonService } from '../common/common.service';
@Component()
export class FeatureService {
constructor(
private readonly commonService: CommonService) {
constructor(private readonly commonService: CommonService) {
console.log('FeatureService', commonService);
}
}
}

View File

@@ -1,5 +1,5 @@
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './modules/app.module';
import { ApplicationModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);

View File

@@ -1,14 +1,2 @@
require('ts-node/register');
require('./src/server');
require('./src/main');

View File

@@ -6,5 +6,5 @@
"password": "root",
"database": "test",
"entities": ["src/**/**.entity{.ts,.js}"],
"autoSchemaSync": true
}
"synchronize": true
}

View File

@@ -6,15 +6,12 @@
"scripts": {
"start": "node index.js",
"prestart:prod": "tsc",
"start:prod": "node dist/server.js"
"start:prod": "node dist/main.js"
},
"dependencies": {
"@nestjs/common": "^4.3.0",
"@nestjs/core": "^4.3.0",
"@nestjs/microservices": "^4.3.0",
"@nestjs/testing": "^4.3.0",
"@nestjs/typeorm": "^1.0.0",
"@nestjs/websockets": "^4.3.0",
"@nestjs/common": "^4.5.0",
"@nestjs/core": "^4.5.0",
"@nestjs/typeorm": "^2.0.0",
"mysql": "^2.14.1",
"redis": "^2.7.1",
"reflect-metadata": "^0.1.10",

View File

@@ -1,13 +1,8 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PhotoModule } from './photo/photo.module';
import { Photo } from './photo/photo.entity';
@Module({
modules: [
TypeOrmModule.forRoot([Photo]),
PhotoModule,
],
imports: [TypeOrmModule.forRoot(), PhotoModule],
})
export class ApplicationModule {}

View File

@@ -1,5 +1,5 @@
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './modules/app.module';
import { ApplicationModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);

View File

@@ -1,22 +0,0 @@
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Photo {
@PrimaryGeneratedColumn()
id: number;
@Column({ length: 500 })
name: string;
@Column('text')
description: string;
@Column()
filename: string;
@Column('int')
views: number;
@Column()
isPublished: boolean;
}

View File

@@ -0,0 +1,17 @@
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
@Entity()
export class Photo {
@PrimaryGeneratedColumn() id: number;
@Column({ length: 500 })
name: string;
@Column('text') description: string;
@Column() filename: string;
@Column('int') views: number;
@Column() isPublished: boolean;
}

View File

@@ -1,8 +1,11 @@
import { Module } from '@nestjs/common';
import { PhotoService } from './photo.service';
import { PhotoController } from './photo.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Photo } from './photo.entity';
@Module({
imports: [TypeOrmModule.forFeature([Photo])],
components: [PhotoService],
controllers: [PhotoController],
})

View File

@@ -1,7 +1,6 @@
import { Component, Inject } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Photo } from './photo.entity';
@Component()

View File

@@ -1,14 +1,2 @@
require('ts-node/register');
require('./src/server');
require('./src/main');

View File

@@ -6,7 +6,7 @@
"scripts": {
"start": "node index.js",
"prestart:prod": "tsc",
"start:prod": "node dist/server.js"
"start:prod": "node dist/main.js"
},
"dependencies": {
"@nestjs/common": "^4.3.0",
@@ -14,7 +14,7 @@
"@nestjs/microservices": "^4.3.0",
"@nestjs/testing": "^4.3.0",
"@nestjs/websockets": "^4.3.0",
"mongoose": "^4.11.13",
"mongoose": "^5.0.1",
"redis": "^2.7.1",
"reflect-metadata": "^0.1.10",
"rxjs": "^5.4.3",

View File

@@ -2,6 +2,6 @@ import { Module } from '@nestjs/common';
import { CatsModule } from './cats/cats.module';
@Module({
modules: [CatsModule],
imports: [CatsModule],
})
export class ApplicationModule {}
export class ApplicationModule {}

View File

@@ -16,4 +16,4 @@ export class CatsController {
async findAll(): Promise<Cat[]> {
return this.catsService.findAll();
}
}
}

View File

@@ -5,11 +5,8 @@ import { catsProviders } from './cats.providers';
import { DatabaseModule } from '../database/database.module';
@Module({
modules: [DatabaseModule],
imports: [DatabaseModule],
controllers: [CatsController],
components: [
CatsService,
...catsProviders,
],
components: [CatsService, ...catsProviders],
})
export class CatsModule {}
export class CatsModule {}

View File

@@ -7,4 +7,4 @@ export const catsProviders = [
useFactory: (connection: Connection) => connection.model('Cat', CatSchema),
inject: ['DbConnectionToken'],
},
];
];

View File

@@ -5,8 +5,7 @@ import { CreateCatDto } from './dto/create-cat.dto';
@Component()
export class CatsService {
constructor(
@Inject('CatModelToken') private readonly catModel: Model<Cat>) {}
constructor(@Inject('CatModelToken') private readonly catModel: Model<Cat>) {}
async create(createCatDto: CreateCatDto): Promise<Cat> {
const createdCat = new this.catModel(createCatDto);
@@ -16,4 +15,4 @@ export class CatsService {
async findAll(): Promise<Cat[]> {
return await this.catModel.find().exec();
}
}
}

View File

@@ -2,4 +2,4 @@ export class CreateCatDto {
readonly name: string;
readonly age: number;
readonly breed: string;
}
}

View File

@@ -4,4 +4,4 @@ export interface Cat extends Document {
readonly name: string;
readonly age: number;
readonly breed: string;
}
}

View File

@@ -4,4 +4,4 @@ export const CatSchema = new mongoose.Schema({
name: String,
age: Number,
breed: String,
});
});

View File

@@ -5,4 +5,4 @@ import { databaseProviders } from './database.providers';
components: [...databaseProviders],
exports: [...databaseProviders],
})
export class DatabaseModule {}
export class DatabaseModule {}

View File

@@ -0,0 +1,9 @@
import * as mongoose from 'mongoose';
export const databaseProviders = [
{
provide: 'DbConnectionToken',
useFactory: async (): Promise<mongoose.Connection> =>
await mongoose.connect('mongodb://localhost/nest'),
},
];

View File

@@ -1,5 +1,5 @@
import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './modules/app.module';
import { ApplicationModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(ApplicationModule);

View File

@@ -1,13 +0,0 @@
import * as mongoose from 'mongoose';
export const databaseProviders = [
{
provide: 'DbConnectionToken',
useFactory: async (): Promise<mongoose.Connection> => {
(mongoose as any).Promise = global.Promise;
return await mongoose.connect('mongodb://localhost/nest', {
useMongoClient: true,
});
},
},
];

View File

@@ -1,14 +1,2 @@
require('ts-node/register');
require('./src/server');
require('./src/main');

Some files were not shown because too many files have changed in this diff Show More