Add error handling in seed.ts

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-05-02 18:35:38 +02:00
parent 980da1fa43
commit a72b4b1eb1
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

@ -56,7 +56,16 @@ createConnection({
user.ownedNotes = [note];
await connection.manager.save([user, note, revision]);
const foundUser = await connection.manager.findOne(User);
if (!foundUser) {
throw new Error('Could not find freshly seeded user. Aborting.');
}
const foundNote = await connection.manager.findOne(Note);
if (!foundNote) {
throw new Error('Could not find freshly seeded note. Aborting.');
}
if (!foundNote.alias) {
throw new Error('Could not find alias of freshly seeded note. Aborting.');
}
const historyEntry = HistoryEntry.create(foundUser, foundNote);
await connection.manager.save(historyEntry);
console.log(`Created User '${foundUser.userName}'`);