refactor(core): Delete duplicate code across all commands (#5452)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-02-10 14:59:20 +01:00
committed by GitHub
parent 8494c97821
commit 5194513850
26 changed files with 979 additions and 1345 deletions

View File

@@ -7,14 +7,16 @@ export class Reset extends BaseCommand {
static description = '\nResets the database to the default ldap state';
async run(): Promise<void> {
const ldapIdentities = await Db.collections.AuthIdentity.find({
// eslint-disable-next-line @typescript-eslint/naming-convention
const { AuthIdentity, AuthProviderSyncHistory, Settings, User } = Db.collections;
const ldapIdentities = await AuthIdentity.find({
where: { providerType: 'ldap' },
select: ['userId'],
});
await Db.collections.AuthProviderSyncHistory.delete({ providerType: 'ldap' });
await Db.collections.AuthIdentity.delete({ providerType: 'ldap' });
await Db.collections.User.delete({ id: In(ldapIdentities.map((i) => i.userId)) });
await Db.collections.Settings.delete({ key: LDAP_FEATURE_NAME });
await AuthProviderSyncHistory.delete({ providerType: 'ldap' });
await AuthIdentity.delete({ providerType: 'ldap' });
await User.delete({ id: In(ldapIdentities.map((i) => i.userId)) });
await Settings.delete({ key: LDAP_FEATURE_NAME });
this.logger.info('Successfully reset the database to default ldap state.');
}
@@ -22,6 +24,5 @@ export class Reset extends BaseCommand {
async catch(error: Error): Promise<void> {
this.logger.error('Error resetting database. See log messages for details.');
this.logger.error(error.message);
this.exit(1);
}
}