Compare commits

...

6 Commits

Author SHA1 Message Date
1a43c6a295 Added a simple hapi endpoint 2020-11-04 21:39:01 +01:00
51f22807a1 Added simple user objects 2020-11-04 21:33:32 +01:00
8eada01a3b Updated the ts config 2020-11-04 21:33:18 +01:00
782b3dfd00 Added mail including validation to Customers 2020-11-04 21:30:35 +01:00
fcd84014a0 Switched to a js based orm config 2020-11-04 21:26:52 +01:00
598ce8c518 Switched to a typeorm-friendlier structure 2020-11-04 21:23:42 +01:00
8 changed files with 142 additions and 75 deletions

View File

@@ -1,20 +0,0 @@
import {Entity, PrimaryGeneratedColumn, Column, JoinColumn} from "typeorm";
import {Address} from "./Address";
@Entity()
export class Customer {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column()
lastName: string;
@OneToOne(() => Address)
@JoinColumn
@Column()
invoiceAddress: Address;
}

24
ormconfig.js Normal file
View File

@@ -0,0 +1,24 @@
module.exports = {
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "test",
"password": "test",
"database": "test",
"synchronize": true,
"logging": false,
"entities": [
"src/entity/**/*.ts"
],
"migrations": [
"src/migration/**/*.ts"
],
"subscribers": [
"src/subscriber/**/*.ts"
],
"cli": {
"entitiesDir": "src/entity",
"migrationsDir": "src/migration",
"subscribersDir": "src/subscriber"
}
}

View File

@@ -1,22 +1,32 @@
{
"name": "samurai",
"version": "0.0.1",
"description": "Our own Invoice Stuff",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git@git.odit.services:odit/samurai-next.git"
},
"keywords": [
"invoice",
"crm"
],
"author": "ODIT.Services",
"license": "MIT",
"dependencies": {
"typeorm": "^0.2.29"
}
"name": "samurai",
"version": "0.0.1",
"description": "Our own Invoice Stuff",
"main": "index.ts",
"scripts": {
"dev": "ts-node src/index.ts"
},
"repository": {
"type": "git",
"url": "git@git.odit.services:odit/samurai-next.git"
},
"keywords": [
"invoice",
"crm"
],
"author": "ODIT.Services",
"license": "MIT",
"dependencies": {
"@hapi/hapi": "^20.0.1",
"@types/hapi__hapi": "^20.0.2",
"class-validator": "^0.12.2",
"pg": "^8.4.2",
"reflect-metadata": "^0.1.10",
"typeorm": "0.2.29"
},
"devDependencies": {
"@types/node": "^8.0.29",
"ts-node": "3.3.0",
"typescript": "3.3.3333"
}
}

View File

@@ -10,7 +10,7 @@ export class Address {
street: string;
@Column()
housenumber: string;
number: string;
@Column()
city: string;

21
src/entity/Customer.ts Normal file
View File

@@ -0,0 +1,21 @@
import {Entity, PrimaryGeneratedColumn, Column, JoinColumn, OneToOne} from "typeorm";
import {IsEmail} from "class-validator";
import {Address} from "./Address";
@Entity()
export class Customer {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column()
@IsEmail()
email: string;
@OneToOne(() => Address)
@JoinColumn()
address: Address;
}

16
src/entity/User.ts Normal file
View 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;
}

37
src/index.ts Normal file
View File

@@ -0,0 +1,37 @@
import "reflect-metadata";
import {createConnection} from "typeorm";
import {Address} from "./entity/Address";
import { Server, Request, ResponseToolkit } from "@hapi/hapi";
const init = async () => {
const connection = await createConnection();
console.log("Inserting a new user into the database...");
const addr = new Address();
addr.street = "Test";
addr.number = "1";
addr.city = "herzo";
addr.plz = "91074";
addr.state = "Franken";
addr.country = "Germany"
await connection.manager.save(addr);
console.log("Saved a new addr with id: " + addr.id);
const server: Server = new Server({
port: 3000,
host: 'localhost'
});
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();

View File

@@ -1,36 +1,15 @@
{
"compilerOptions": {
"lib": ["es5", "es6"],
"outDir": "build/compiled",
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"importHelpers": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noImplicitAny": true,
"declaration": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"stripInternal": true,
"pretty": true,
"strictNullChecks": true,
"noUnusedLocals": true,
"downlevelIteration": true
},
"include": [
"sample",
"src",
"test",
"models"
],
"exclude": [
"tmp",
"temp",
"build",
"node_modules"
]
"compilerOptions": {
"lib": [
"es5",
"es6"
],
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"outDir": "./dist",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true
}
}