-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 783f277
Showing
15 changed files
with
4,087 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
### Node template | ||
.DS_Store | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git | ||
node_modules | ||
.npmrc | ||
*.log | ||
|
||
# Typings | ||
typings/ | ||
|
||
# Typescript | ||
src/**/*.js | ||
src/**/*.js.map | ||
test/**/*.js | ||
test/**/*.js.map | ||
|
||
# Test | ||
/coverage | ||
/stdout | ||
/stderr | ||
/es6/ | ||
/lib/ | ||
/dts/ | ||
/.tmp | ||
/.nyc_output/ | ||
/mongodb | ||
|
||
# IDE | ||
.vscode | ||
.idea | ||
|
||
# Project | ||
public |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"exclude": [ | ||
"**/*.d.ts", | ||
"node_modules", | ||
"**/index.ts", | ||
"**/interfaces/**", | ||
"**/*.spec.ts", | ||
"src/test/tools.js" | ||
], | ||
"reporter": [ | ||
"text-summary", | ||
"html", | ||
"lcov" | ||
], | ||
"extension": [ | ||
".ts" | ||
], | ||
"check-coverage": true, | ||
"lines": 99, | ||
"statements": 100, | ||
"functions": 99, | ||
"branches": 89, | ||
"all": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
{ | ||
"name": "@tsed/typeorm-example", | ||
"version": "1.0.0", | ||
"description": "", | ||
"scripts": { | ||
"clean": "rimraf '{src,test}/**/*.{js,js.map}'", | ||
"build": "npm run tsc", | ||
"test": "npm run clean && npm run test:lint && npm run test:coverage", | ||
"test:unit": "cross-env NODE_ENV=test mocha", | ||
"test:coverage": "cross-env NODE_ENV=test nyc mocha", | ||
"test:lint": "tslint --project tsconfig.json", | ||
"test:lint:fix": "tslint --project tsconfig.json --fix", | ||
"travis:deploy-once": "travis-deploy-once", | ||
"travis:coveralls": "nyc report --reporter=text-lcov | coveralls", | ||
"tsc": "tsc --project tsconfig.json", | ||
"tsc:w": "tsc --project tsconfig.json -w", | ||
"start:dev": "nodemon --watch 'src/**/*.ts' --ignore 'node_modules/**/*' --exec ts-node src/index.ts", | ||
"start": "ts-node src/index.ts", | ||
"start:prod": "npm run build && cross-env NODE_ENV=production node dist/index.js" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@tsed/common": "5.18.0", | ||
"@tsed/core": "5.18.0", | ||
"@tsed/di": "5.18.0", | ||
"@tsed/socketio": "5.18.0", | ||
"@tsed/swagger": "5.18.0", | ||
"@tsed/testing": "5.18.0", | ||
"@tsed/typeorm": "5.18.0", | ||
"@types/swagger-schema-official": "^2.0.10", | ||
"body-parser": "^1.18.3", | ||
"compression": "^1.7.3", | ||
"cookie-parser": "^1.4.3", | ||
"express": "^4.16.2", | ||
"express-session": "^1.15.6", | ||
"method-override": "^3.0.0", | ||
"pg": "^7.4.3", | ||
"serve-static": "^1.13.1", | ||
"typeorm": "^0.2.7" | ||
}, | ||
"devDependencies": { | ||
"@types/chai": "^4.1.5", | ||
"@types/chai-as-promised": "^7.1.0", | ||
"@types/express": "^4.16.0", | ||
"@types/http-proxy": "^1.16.2", | ||
"@types/mocha": "^5.2.5", | ||
"@types/node": "^10.11.0", | ||
"@types/request-promise": "^4.1.42", | ||
"@types/sinon": "^5.0.2", | ||
"@types/sinon-chai": "^3.2.0", | ||
"@types/supertest": "^2.0.6", | ||
"chai": "^4.1.2", | ||
"chai-as-promised": "^7.1.1", | ||
"concurrently": "^4.0.1", | ||
"mocha": "^5.2.0", | ||
"nodemon": "^1.17.5", | ||
"nyc": "^13.1.0", | ||
"rimraf": "^2.6.2", | ||
"sinon": "^6.3.5", | ||
"sinon-chai": "^3.3.0", | ||
"supertest": "^3.3.0", | ||
"ts-node": "^7.0.1", | ||
"tslint": "^5.12.0", | ||
"typescript": "^3.2.2" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Ts.ED - TypeORM | ||
|
||
Here an example to configure your server and how to create your first controller. | ||
|
||
See [Ts.ED](https://tsed.io) project for more information. | ||
|
||
## Checkout | ||
|
||
This repository provide getting started project example for each Ts.ED version since `v5.18.1`. | ||
|
||
```bash | ||
git checkout -b https://github.com/TypedProject/tsed-example-typeorm/tree/v5.18.1 | ||
``` | ||
|
||
To checkout another version just replace `v5.18.1` by the desired version. | ||
|
||
## Install | ||
|
||
> **Important!** Ts.ED requires Node >= 8, Express >= 4 and TypeScript >= 3. | ||
```batch | ||
npm install | ||
``` | ||
|
||
## Run | ||
|
||
``` | ||
npm start | ||
``` | ||
|
||
## Contributing | ||
|
||
You can make a PR directly on https://github.com/TypedProject/ts-express-decorators repository. | ||
|
||
## Backers | ||
|
||
Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)] | ||
|
||
<a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/tiers/backer.svg?width=890"></a> | ||
|
||
|
||
## Sponsors | ||
|
||
Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)] | ||
|
||
## License | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 - 2019 Romain Lenzotti | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
[travis]: https://travis-ci.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const Chai = require("chai"); | ||
const ChaiAsPromised = require("chai-as-promised"); | ||
const SinonChai = require("sinon-chai"); | ||
|
||
Chai.should(); | ||
Chai.use(SinonChai); | ||
Chai.use(ChaiAsPromised); | ||
|
||
process.on("unhandledRejection", (reason, p) => { | ||
console.log("Unhandled Rejection at: Promise", p, "reason:", reason); | ||
// application specific logging, throwing an error, or other logic here | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import {GlobalAcceptMimesMiddleware, ServerLoader, ServerSettings} from "@tsed/common"; | ||
import "@tsed/swagger"; | ||
import "@tsed/typeorm"; | ||
|
||
const cookieParser = require("cookie-parser"); | ||
const bodyParser = require("body-parser"); | ||
const compress = require("compression"); | ||
const methodOverride = require("method-override"); | ||
const session = require("express-session"); | ||
const rootDir = __dirname; | ||
|
||
@ServerSettings({ | ||
rootDir, | ||
port: 3000, | ||
acceptMimes: ["application/json"], | ||
mount: { | ||
"/v1": `${rootDir}/controllers/**/**Ctrl.{ts,js}` | ||
}, | ||
typeorm: [ | ||
{ | ||
name: "default", | ||
type: "postgres", | ||
host: "localhost", | ||
port: 5432, | ||
username: "postgres", | ||
password: "", | ||
database: "romain.lenzotti", | ||
synchronize: true, | ||
logging: false, | ||
entities: [ | ||
`${rootDir}/entity/*{.ts,.js}` | ||
], | ||
migrations: [ | ||
`${rootDir}/migrations/*{.ts,.js}` | ||
], | ||
subscribers: [ | ||
`${rootDir}/subscriber/*{.ts,.js}` | ||
] | ||
} | ||
], | ||
swagger: { | ||
path: "/api-docs" | ||
} | ||
}) | ||
export class Server extends ServerLoader { | ||
$onMountingMiddlewares(): void | Promise<any> { | ||
this | ||
.use(GlobalAcceptMimesMiddleware) | ||
.use(cookieParser()) | ||
.use(compress({})) | ||
.use(methodOverride()) | ||
.use(bodyParser.json()) | ||
.use(bodyParser.urlencoded({ | ||
extended: true | ||
})) | ||
.use(session({ | ||
secret: "mysecretkey", | ||
resave: true, | ||
saveUninitialized: true, | ||
maxAge: 36000, | ||
cookie: { | ||
path: "/", | ||
httpOnly: true, | ||
secure: false, | ||
maxAge: null | ||
} | ||
})); | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import {Controller, Get, RouteService} from "@tsed/common"; | ||
|
||
@Controller("/rest") | ||
export class RestCtrl { | ||
|
||
constructor(private routeService: RouteService) { | ||
|
||
} | ||
|
||
@Get("/") | ||
public getRoutes() { | ||
return this.routeService.getAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {BodyParams, Controller, Get, Post} from "@tsed/common"; | ||
import {ReturnsArray} from "@tsed/swagger"; | ||
import {User} from "../../entity/User"; | ||
import {UsersService} from "../../services/UsersService"; | ||
|
||
@Controller("/users") | ||
export class UsersCtrl { | ||
|
||
constructor(private usersService: UsersService) { | ||
} | ||
|
||
@Post("/") | ||
create(@BodyParams() user: User): Promise<User> { | ||
return this.usersService.create(user); | ||
} | ||
|
||
@Get("/") | ||
@ReturnsArray(User) | ||
async getList(): Promise<User[]> { | ||
return this.usersService.find(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {Minimum, Required, Property} from "@tsed/common"; | ||
import {Example, Description} from "@tsed/swagger"; | ||
import {Column, Entity, PrimaryGeneratedColumn} from "typeorm"; | ||
|
||
@Entity() | ||
export class User { | ||
@Description('Database assigned id') | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Description('User firstname') | ||
@Column() | ||
@Required() | ||
firstName: string; | ||
|
||
@Description('User lastname') | ||
@Column() | ||
@Required() | ||
lastName: string; | ||
|
||
@Description('User Age') | ||
@Column() | ||
@Minimum(18) | ||
@Example(18) | ||
age: number; | ||
|
||
additional: string; // won't be serialized/deserialized by Ts.ED because @PropertyType or other Ts.ED decorator are missing | ||
|
||
@Property() | ||
additional2: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import "reflect-metadata"; | ||
import {$log} from "ts-log-debug"; | ||
|
||
import {Server} from "./Server"; | ||
|
||
$log.debug("Start server..."); | ||
new Server() | ||
.start() | ||
.catch((er) => console.error(er)); |
Oops, something went wrong.