This is a full-stack application implemented with TypeScript that demostrates how to handle data in a relational database with ORM and howto store hierarchical data in NgRx Store and manage with NgRx Data. Repo contains two projects:
- mikroorm-demo-server (backend)
- angular-orm-demo (frontend)
- PostgreSQL
- NestJS
- MikroORM
- Angular
- Bootstrap
- ngx-bootstrap
- ngrx (Entity, Data)
- Data managent with ORM (mikro-orm)
- JWT based authentication (passport)
- Logging (winston)
- Generics for CRUD Entity Repository
- Generics for CRUD Entity Service
- Generics for CRUD REST controllers
- Centralized error handling + sending custom error status messages about general database (unique, constrain, ...) errors
- Reactive Forms with validation
- Modal data editor dialogs
- Auto-focus on forms
- Data storage of hierarchical data with NgRx Data
- Generics (service, components) for CRUD operations
- Drag-and-drop operations
- Modal confirm dialogs
Data persisted in relational database (PostgreSQL) in normalized format. It's a good approach to do the same in NgRx Store. Store hierarchical data in normalized form. The basic concepts of normalizing data are:
- Each type of data gets its own "table" in the state.
- Each "data table" should store the individual items in an object, with the IDs of the items as keys and the items themselves as the values.
- Any references to individual items should be done by storing the item's ID.
- Arrays of IDs should be used to indicate ordering.
If you need normalized data in hierarchical form you can read and convert it with NgRx selectors.
Installed PostreSQL server.
Backend:
cd mikroorm-demo-server
npm install
Frontend:
cd angular-orm-demo
npm install
Create database:
createdb -U postgres mynestjsormdemo
Set database credentials in .env, for example:
DATABASE_USER=postgres
DATABASE_PASSWORD=postgres
Create database schema:
cd mikroorm-demo-server
npm run createdbschema
Backend:
cd mikroorm-demo-server
npm run start
Frontend:
cd angular-orm-demo
npm run start
Call frontend: http://localhost:4201
You can test manually the backend with Postman. Import this workspace for testing.