-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2342 from hashgraph/feature/auto-fill-suggestions…
…-config auto fill suggestions config
- Loading branch information
Showing
5 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { ConfigType } from '@guardian/interfaces'; | ||
import { Migration } from '@mikro-orm/migrations-mongodb'; | ||
|
||
/** | ||
* Migration to version 2.13.0 | ||
*/ | ||
export class ReleaseMigration extends Migration { | ||
/** | ||
* Up migration | ||
*/ | ||
async up(): Promise<void> { | ||
await this.setupSuggestionsConfig(); | ||
} | ||
|
||
/** | ||
* Setup suggestions config | ||
*/ | ||
async setupSuggestionsConfig() { | ||
const suggestionsConfigCollection = | ||
this.getCollection('SuggestionsConfig'); | ||
const policyCollection = this.getCollection('Policy'); | ||
const policiesByUsers = await policyCollection | ||
.aggregate([ | ||
{ | ||
$group: { | ||
_id: '$owner', | ||
policyIds: { | ||
$push: '$_id', | ||
}, | ||
}, | ||
}, | ||
]) | ||
.toArray(); | ||
for (const policiesByUser of policiesByUsers) { | ||
await suggestionsConfigCollection.insertOne({ | ||
user: policiesByUser._id, | ||
items: policiesByUser.policyIds | ||
.slice(0, 5) | ||
.map((id, index) => ({ | ||
id, | ||
index, | ||
type: ConfigType.POLICY, | ||
})), | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters