Utilizing TypeORM alongside Angular to store form data in the database has been successful. The connection configuration is correct, allowing for data storage from the backend.
{
"type": "mssql",
"host": "***",
"port": ***,
[...]
"entities": [
"src/entity/**/*.ts"
],
"migrations": [
"src/migration/**/*.ts"
],
[...]
}
The process of saving to the database functions well with the following code:
import "reflect-metadata";
import {createConnection} from "typeorm";
import {User} from "./entity/User";
[...]
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);
console.log("Loading users from the database...");
const users = await connection.manager.find(User);
console.log("Loaded users: ", users);
}).catch(error => console.log(error));
However, I am facing difficulties in saving data from a frontend form. Here's my current code:
SubmitForm() {
//initialize connection with the database
this.connection.then(async connection=> {
console.log("Inserting a new user into the database...");
//create a new enrollee
let enrollee = new Enrollee();
enrollee.enrolleeTitle = this.PDTitle;
enrollee.enrolleeLastName = this.PDSurname;
enrollee.enrolleeFirstName = this.PDFirstname;
enrollee.enrolleeOtherName = this.PDMiddlename;
[...]
let enrolleeRepo = connection.getRepository(Enrollee);
//save info into database
await enrolleeRepo.save(enrollee);
console.log("Saved a new user with id: " + enrollee.id);
//get all enrollees
console.log("Loading enrollees from the database...");
let enrollees = await enrolleeRepo.find();
console.log("Loaded errollees: ", enrollees);
}).catch(error => console.log(error));
}
The project compilation fails with numerous errors. Any assistance or guidance would be greatly appreciated.