fix(auth): update shared subscriptions upon subscription sync (#1022)
This commit is contained in:
parent
4de0bfa36d
commit
d7a1c667dd
3 changed files with 17 additions and 0 deletions
|
@ -1421,6 +1421,7 @@ export class ContainerConfigLoader {
|
||||||
container.get<SetSettingValue>(TYPES.Auth_SetSettingValue),
|
container.get<SetSettingValue>(TYPES.Auth_SetSettingValue),
|
||||||
container.get<OfflineSettingServiceInterface>(TYPES.Auth_OfflineSettingService),
|
container.get<OfflineSettingServiceInterface>(TYPES.Auth_OfflineSettingService),
|
||||||
container.get<ContentDecoderInterface>(TYPES.Auth_ContenDecoder),
|
container.get<ContentDecoderInterface>(TYPES.Auth_ContenDecoder),
|
||||||
|
container.get<RenewSharedSubscriptions>(TYPES.Auth_RenewSharedSubscriptions),
|
||||||
container.get<winston.Logger>(TYPES.Auth_Logger),
|
container.get<winston.Logger>(TYPES.Auth_Logger),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,6 +16,7 @@ import { OfflineSettingName } from '../Setting/OfflineSettingName'
|
||||||
import { UserSubscriptionType } from '../Subscription/UserSubscriptionType'
|
import { UserSubscriptionType } from '../Subscription/UserSubscriptionType'
|
||||||
import { ApplyDefaultSubscriptionSettings } from '../UseCase/ApplyDefaultSubscriptionSettings/ApplyDefaultSubscriptionSettings'
|
import { ApplyDefaultSubscriptionSettings } from '../UseCase/ApplyDefaultSubscriptionSettings/ApplyDefaultSubscriptionSettings'
|
||||||
import { SetSettingValue } from '../UseCase/SetSettingValue/SetSettingValue'
|
import { SetSettingValue } from '../UseCase/SetSettingValue/SetSettingValue'
|
||||||
|
import { RenewSharedSubscriptions } from '../UseCase/RenewSharedSubscriptions/RenewSharedSubscriptions'
|
||||||
|
|
||||||
export class SubscriptionSyncRequestedEventHandler implements DomainEventHandlerInterface {
|
export class SubscriptionSyncRequestedEventHandler implements DomainEventHandlerInterface {
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -27,6 +28,7 @@ export class SubscriptionSyncRequestedEventHandler implements DomainEventHandler
|
||||||
private setSettingValue: SetSettingValue,
|
private setSettingValue: SetSettingValue,
|
||||||
private offlineSettingService: OfflineSettingServiceInterface,
|
private offlineSettingService: OfflineSettingServiceInterface,
|
||||||
private contentDecoder: ContentDecoderInterface,
|
private contentDecoder: ContentDecoderInterface,
|
||||||
|
private renewSharedSubscriptions: RenewSharedSubscriptions,
|
||||||
private logger: Logger,
|
private logger: Logger,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
@ -85,6 +87,19 @@ export class SubscriptionSyncRequestedEventHandler implements DomainEventHandler
|
||||||
event.payload.timestamp,
|
event.payload.timestamp,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const renewalResult = await this.renewSharedSubscriptions.execute({
|
||||||
|
inviterEmail: user.email,
|
||||||
|
newSubscriptionId: event.payload.subscriptionId,
|
||||||
|
newSubscriptionName: event.payload.subscriptionName,
|
||||||
|
newSubscriptionExpiresAt: event.payload.subscriptionExpiresAt,
|
||||||
|
timestamp: event.payload.timestamp,
|
||||||
|
})
|
||||||
|
if (renewalResult.isFailed()) {
|
||||||
|
this.logger.error(`Could not renew shared subscriptions for user: ${renewalResult.getError()}`, {
|
||||||
|
userId: user.uuid,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
await this.roleService.addUserRoleBasedOnSubscription(user, event.payload.subscriptionName)
|
await this.roleService.addUserRoleBasedOnSubscription(user, event.payload.subscriptionName)
|
||||||
|
|
||||||
const applyingSettingsResult = await this.applyDefaultSubscriptionSettings.execute({
|
const applyingSettingsResult = await this.applyDefaultSubscriptionSettings.execute({
|
||||||
|
|
|
@ -84,6 +84,7 @@ export class TypeORMUserSubscriptionRepository implements UserSubscriptionReposi
|
||||||
userUuid,
|
userUuid,
|
||||||
subscriptionId,
|
subscriptionId,
|
||||||
})
|
})
|
||||||
|
.orderBy('ends_at', 'DESC')
|
||||||
.getOne()
|
.getOne()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue