-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add migration for allowed channels settings
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
packages/api/src/database/migrations/12_praise_allowed_channels_settings.ts
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,43 @@ | ||
import { SettingGroup } from '@settings/types'; | ||
import { SettingsModel } from '../../settings/entities'; | ||
|
||
const settings = [ | ||
{ | ||
key: 'PRAISE_ALLOWED_IN_ALL_CHANNELS', | ||
value: true, | ||
type: 'Boolean', | ||
label: 'Praising allowed in all Channels', | ||
description: | ||
'If enabled, this allows praise to be dished in all channels in the server', | ||
group: SettingGroup.DISCORD, | ||
}, | ||
{ | ||
key: 'PRAISE_ALLOWED_CHANNEL_IDS', | ||
value: '0, 0', | ||
type: 'IntegerList', | ||
label: 'Channels where praise is allowed', | ||
description: 'List of channel IDs in which discord users can use praise', | ||
group: SettingGroup.DISCORD, | ||
}, | ||
]; | ||
|
||
const up = async (): Promise<void> => { | ||
const settingUpdates = settings.map((s) => ({ | ||
updateOne: { | ||
filter: { key: s.key }, | ||
|
||
// Insert setting if not found, otherwise continue | ||
update: { $setOnInsert: { ...s } }, | ||
upsert: true, | ||
}, | ||
})); | ||
|
||
await SettingsModel.bulkWrite(settingUpdates); | ||
}; | ||
|
||
const down = async (): Promise<void> => { | ||
const allKeys = settings.map((s) => s.key); | ||
await SettingsModel.deleteMany({ key: { $in: allKeys } }); | ||
}; | ||
|
||
export { up, down }; |