Files
What you'll learn
- Replace an in-memory store with TypeORM repositories behind the same service, so the API does not change
- Seed a fresh database when a module starts, with OnModuleInit
- Relate two entities with @ManyToOne, typed with Relation<> so the files can import each other safely, and load the relation with every read
- Make a multi-step change all or nothing with DataSource.transaction(), and prove the rollback by reading the data back
Press Run tests to start the app. Its log appears here.Graded endpoints
Still there from lesson 1
Seeded when the module started; the same API as before, with whether each cat was adopted
The breed filter is a WHERE now
The 404 is unchanged
The database gives the id; the answer is a read of the stored row
Validation still stops it before the database
An update merges into the stored row
204, and the row is gone
From the database too
A fourth cat, for the adoption rules below
The adoption, with its cat loaded and marked adopted
An adopted cat is a 409 that names it
A 404, inside the transaction
The adoption body is validated like any other
Her second cat
The limit is checked after both writes, and its refusal rolls them back
The rollback undid the change to the cat, not only the adoption
Two, each with its cat; the refused one left nothing behind