mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
Merge pull request #15044 from overleaf/mf-send-warning-to-users-with-personal-and-group-subscriptions
Show notification warning to user with both personal and group subscriptions GitOrigin-RevId: 7f46d7af10389f552175ce26fae9469e0167f95b
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
const NotificationsBuilder = require('../app/src/Features/Notifications/NotificationsBuilder')
|
||||
const { db, waitForDb } = require('../app/src/infrastructure/mongodb')
|
||||
const { batchedUpdate } = require('./helpers/batchedUpdate')
|
||||
|
||||
const DRY_RUN = !process.argv.includes('--dry-run=false')
|
||||
|
||||
if (DRY_RUN) {
|
||||
console.log('Doing dry run')
|
||||
}
|
||||
|
||||
async function processBatch(groupSubscriptionsBatch) {
|
||||
console.log('\n')
|
||||
console.log('----- Batch computation started -----')
|
||||
const flattenedMemberIds = groupSubscriptionsBatch
|
||||
.map(sub => sub.member_ids)
|
||||
.flatMap(memberId => memberId)
|
||||
const uniqueFlattenedMemberIds = [...new Set(flattenedMemberIds)]
|
||||
|
||||
const userWithIndividualAndGroupSubscriptions = await db.subscriptions
|
||||
.find({
|
||||
groupPlan: false,
|
||||
'recurlyStatus.state': 'active',
|
||||
admin_id: { $in: uniqueFlattenedMemberIds },
|
||||
})
|
||||
.toArray()
|
||||
|
||||
console.log(
|
||||
`Found ${userWithIndividualAndGroupSubscriptions.length} affected users in this batch`
|
||||
)
|
||||
|
||||
if (DRY_RUN) {
|
||||
console.error('---')
|
||||
console.error('Dry-run enabled, use --dry-run=false to commit changes')
|
||||
console.error('---')
|
||||
} else {
|
||||
if (userWithIndividualAndGroupSubscriptions.length > 0) {
|
||||
console.log(
|
||||
`Notifying ${userWithIndividualAndGroupSubscriptions.length} users`
|
||||
)
|
||||
|
||||
for (const notif of userWithIndividualAndGroupSubscriptions) {
|
||||
await NotificationsBuilder.promises
|
||||
.personalAndGroupSubscriptions(notif.admin_id.toString())
|
||||
.create()
|
||||
}
|
||||
|
||||
console.log(
|
||||
`${userWithIndividualAndGroupSubscriptions.length} users successfully notified in this batch`
|
||||
)
|
||||
} else {
|
||||
console.log(
|
||||
'No users currently subscribe to both individual and group subscription in this batch'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await waitForDb()
|
||||
|
||||
await batchedUpdate('subscriptions', { groupPlan: true }, processBatch, {
|
||||
member_ids: 1,
|
||||
})
|
||||
}
|
||||
|
||||
main()
|
||||
.then(() => {
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user