Compare commits
4 Commits
fcd84014a0
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a43c6a295 | |||
| 51f22807a1 | |||
| 8eada01a3b | |||
| 782b3dfd00 |
@@ -17,6 +17,9 @@
|
|||||||
"author": "ODIT.Services",
|
"author": "ODIT.Services",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@hapi/hapi": "^20.0.1",
|
||||||
|
"@types/hapi__hapi": "^20.0.2",
|
||||||
|
"class-validator": "^0.12.2",
|
||||||
"pg": "^8.4.2",
|
"pg": "^8.4.2",
|
||||||
"reflect-metadata": "^0.1.10",
|
"reflect-metadata": "^0.1.10",
|
||||||
"typeorm": "0.2.29"
|
"typeorm": "0.2.29"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {Entity, PrimaryGeneratedColumn, Column, JoinColumn, OneToOne} from "typeorm";
|
import {Entity, PrimaryGeneratedColumn, Column, JoinColumn, OneToOne} from "typeorm";
|
||||||
|
import {IsEmail} from "class-validator";
|
||||||
import {Address} from "./Address";
|
import {Address} from "./Address";
|
||||||
|
|
||||||
@Entity()
|
@Entity()
|
||||||
@@ -11,9 +12,10 @@ export class Customer {
|
|||||||
name: string;
|
name: string;
|
||||||
|
|
||||||
@Column()
|
@Column()
|
||||||
lastName: string;
|
@IsEmail()
|
||||||
|
email: string;
|
||||||
|
|
||||||
@OneToOne(() => Address)
|
@OneToOne(() => Address)
|
||||||
@JoinColumn()
|
@JoinColumn()
|
||||||
invoiceAddress: Address;
|
address: Address;
|
||||||
}
|
}
|
||||||
16
src/entity/User.ts
Normal file
16
src/entity/User.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import {Entity, PrimaryGeneratedColumn, Column} from "typeorm";
|
||||||
|
import {IsEmail} from "class-validator";
|
||||||
|
|
||||||
|
@Entity()
|
||||||
|
export class Customer {
|
||||||
|
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
@Column()
|
||||||
|
@IsEmail()
|
||||||
|
email: string;
|
||||||
|
}
|
||||||
29
src/index.ts
29
src/index.ts
@@ -1,9 +1,10 @@
|
|||||||
import "reflect-metadata";
|
import "reflect-metadata";
|
||||||
import {createConnection} from "typeorm";
|
import {createConnection} from "typeorm";
|
||||||
import {Address} from "./entity/Address";
|
import {Address} from "./entity/Address";
|
||||||
|
import { Server, Request, ResponseToolkit } from "@hapi/hapi";
|
||||||
|
|
||||||
createConnection().then(async connection => {
|
const init = async () => {
|
||||||
|
const connection = await createConnection();
|
||||||
console.log("Inserting a new user into the database...");
|
console.log("Inserting a new user into the database...");
|
||||||
const addr = new Address();
|
const addr = new Address();
|
||||||
addr.street = "Test";
|
addr.street = "Test";
|
||||||
@@ -15,8 +16,22 @@ createConnection().then(async connection => {
|
|||||||
await connection.manager.save(addr);
|
await connection.manager.save(addr);
|
||||||
console.log("Saved a new addr with id: " + addr.id);
|
console.log("Saved a new addr with id: " + addr.id);
|
||||||
|
|
||||||
console.log("Loading addr from the database...");
|
const server: Server = new Server({
|
||||||
const addrs = await connection.manager.find(Address);
|
port: 3000,
|
||||||
console.log("Loaded addr: ", addrs);
|
host: 'localhost'
|
||||||
|
});
|
||||||
}).catch(error => console.log(error));
|
server.route({
|
||||||
|
method: 'GET',
|
||||||
|
path: '/',
|
||||||
|
handler: (request: Request, h: ResponseToolkit) => {
|
||||||
|
return connection.manager.find(Address);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await server.start();
|
||||||
|
console.log('Server running on %s', server.info.uri);
|
||||||
|
};
|
||||||
|
process.on('unhandledRejection', (err) => {
|
||||||
|
console.log(err);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
||||||
|
init();
|
||||||
@@ -4,10 +4,10 @@
|
|||||||
"es5",
|
"es5",
|
||||||
"es6"
|
"es6"
|
||||||
],
|
],
|
||||||
"target": "es5",
|
"target": "es6",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
"outDir": "./build",
|
"outDir": "./dist",
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"sourceMap": true
|
"sourceMap": true
|
||||||
|
|||||||
Reference in New Issue
Block a user