fix: the seed command handles the new aliases

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-06-06 17:56:12 +02:00 committed by David Mehren
parent 56eaddff8c
commit 9383eeb53a
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

View file

@ -12,6 +12,7 @@ import { HistoryEntry } from './history/history-entry.entity';
import { Identity } from './identity/identity.entity'; import { Identity } from './identity/identity.entity';
import { ProviderType } from './identity/provider-type.enum'; import { ProviderType } from './identity/provider-type.enum';
import { MediaUpload } from './media/media-upload.entity'; import { MediaUpload } from './media/media-upload.entity';
import { Alias } from './notes/alias.entity';
import { Note } from './notes/note.entity'; import { Note } from './notes/note.entity';
import { Tag } from './notes/tag.entity'; import { Tag } from './notes/tag.entity';
import { NoteGroupPermission } from './permissions/note-group-permission.entity'; import { NoteGroupPermission } from './permissions/note-group-permission.entity';
@ -43,6 +44,7 @@ createConnection({
Identity, Identity,
Author, Author,
Session, Session,
Alias,
], ],
synchronize: true, synchronize: true,
logging: false, logging: false,
@ -89,12 +91,14 @@ createConnection({
if (!foundUsers) { if (!foundUsers) {
throw new Error('Could not find freshly seeded users. Aborting.'); throw new Error('Could not find freshly seeded users. Aborting.');
} }
const foundNotes = await connection.manager.find(Note); const foundNotes = await connection.manager.find(Note, {
relations: ['aliases'],
});
if (!foundNotes) { if (!foundNotes) {
throw new Error('Could not find freshly seeded notes. Aborting.'); throw new Error('Could not find freshly seeded notes. Aborting.');
} }
for (const note of foundNotes) { for (const note of foundNotes) {
if (!note.alias) { if (!note.aliases[0]) {
throw new Error( throw new Error(
'Could not find alias of freshly seeded notes. Aborting.', 'Could not find alias of freshly seeded notes. Aborting.',
); );
@ -106,7 +110,7 @@ createConnection({
); );
} }
for (const note of foundNotes) { for (const note of foundNotes) {
console.log(`Created Note '${note.alias ?? ''}'`); console.log(`Created Note '${note.aliases[0].name ?? ''}'`);
} }
for (const user of foundUsers) { for (const user of foundUsers) {
for (const note of foundNotes) { for (const note of foundNotes) {
@ -114,7 +118,7 @@ createConnection({
await connection.manager.save(historyEntry); await connection.manager.save(historyEntry);
console.log( console.log(
`Created HistoryEntry for user '${user.userName}' and note '${ `Created HistoryEntry for user '${user.userName}' and note '${
note.alias ?? '' note.aliases[0].name ?? ''
}'`, }'`,
); );
} }