cargamasviva
This commit is contained in:
+15
-33
@@ -1,39 +1,21 @@
|
||||
import "reflect-metadata";
|
||||
import { createConnection } from "typeorm";
|
||||
import { User } from "./db/entity/User";
|
||||
import { TipoProblema } from "./db/entity/TipoProblema";
|
||||
import { Ayuda } from "./db/entity/Ayuda";
|
||||
|
||||
import * as express from 'express'
|
||||
import * as bodyParser from 'body-parser'
|
||||
import routes from './routes/index'
|
||||
import { createConnection } from 'typeorm'
|
||||
const PORT = 3000
|
||||
createConnection()
|
||||
.then(async (connection) => {
|
||||
console.log("Inserting a new user into the database...");
|
||||
const user = new User();
|
||||
user.firstName = "Timber";
|
||||
user.lastName = "Saw";
|
||||
user.age = 25;
|
||||
await connection.manager.save(user);
|
||||
console.log("Saved a new user with id: " + user.id);
|
||||
const tipoProblema = new TipoProblema();
|
||||
tipoProblema.nombre = "test";
|
||||
const ayuda = new Ayuda();
|
||||
ayuda.nombre = "test";
|
||||
ayuda.correo = "correo@test";
|
||||
ayuda.solucion = "sdasd";
|
||||
ayuda.descripcion = "daskdjskjdjasda";
|
||||
ayuda.tipoProblema = tipoProblema;
|
||||
const app = express()
|
||||
// configure multer
|
||||
app.use(bodyParser.urlencoded({ extended: false }))
|
||||
app.use(bodyParser.json())
|
||||
|
||||
await connection.manager.save(tipoProblema);
|
||||
await connection.manager.save(ayuda);
|
||||
app.get('/', (req, res) => res.send('Hello World!'))
|
||||
|
||||
console.log("Loading users from the database...");
|
||||
const users = await connection.manager.find(User);
|
||||
const problemas = await connection.manager.find(TipoProblema);
|
||||
const ayudasRep = connection.getRepository(Ayuda);
|
||||
const ayudas = await ayudasRep.find({ relations: ["tipoProblema"] });
|
||||
console.log("Loaded users: ", users);
|
||||
console.log("Loaded users: ", problemas);
|
||||
console.log("Loaded users: ", ayudas);
|
||||
app.use('/', routes)
|
||||
|
||||
console.log("Here you can setup and run express/koa/any other framework.");
|
||||
app.listen(PORT, () =>
|
||||
console.log(`Example app listening at http://localhost:${PORT}`)
|
||||
)
|
||||
})
|
||||
.catch((error) => console.log(error));
|
||||
.catch((error) => console.log('TypeORM connection error: ', error))
|
||||
|
||||
Reference in New Issue
Block a user