mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-08 00:29:04 +02:00
912324f560
GitOrigin-RevId: b58b02f9e9c8d47909e95c3ade8e1bf33ed46c80
125 lines
3.0 KiB
JavaScript
125 lines
3.0 KiB
JavaScript
const mappings = new Map([
|
|
['salesforce_id', generateSubscriptionToSalesforceMapping],
|
|
['v1_id', generateSubscriptionToV1Mapping],
|
|
['recurlySubscription_id', generateSubscriptionToRecurlyMapping],
|
|
])
|
|
|
|
/**
|
|
* @typedef {(import('./types.d.ts').AccountMapping)} AccountMapping
|
|
* @import { StripePaymentProviderService } from '../../../../types/subscription/dashboard/subscription'
|
|
*/
|
|
|
|
/**
|
|
*
|
|
* @param {Object} subscription
|
|
* @param {Object} updatedSubscription
|
|
* @return {Array<AccountMapping>}
|
|
*/
|
|
function extractAccountMappingsFromSubscription(
|
|
subscription,
|
|
updatedSubscription
|
|
) {
|
|
const accountMappings = []
|
|
mappings.forEach((generateMapping, param) => {
|
|
if (updatedSubscription[param] || updatedSubscription[param] === '') {
|
|
if (subscription[param] !== updatedSubscription[param]) {
|
|
accountMappings.push(
|
|
generateMapping(subscription.id, updatedSubscription[param])
|
|
)
|
|
}
|
|
}
|
|
})
|
|
return accountMappings
|
|
}
|
|
|
|
function generateV1Mapping(v1Id, salesforceId, createdAt) {
|
|
return {
|
|
source: 'salesforce',
|
|
sourceEntity: 'account',
|
|
sourceEntityId: salesforceId,
|
|
target: 'v1',
|
|
targetEntity: 'university',
|
|
targetEntityId: v1Id,
|
|
createdAt,
|
|
}
|
|
}
|
|
|
|
function generateSubscriptionToV1Mapping(subscriptionId, v1Id) {
|
|
return {
|
|
source: 'v1',
|
|
sourceEntity: 'university',
|
|
sourceEntityId: v1Id,
|
|
target: 'v2',
|
|
targetEntity: 'subscription',
|
|
targetEntityId: subscriptionId,
|
|
createdAt: new Date().toISOString(),
|
|
}
|
|
}
|
|
|
|
function generateSubscriptionToSalesforceMapping(subscriptionId, salesforceId) {
|
|
return {
|
|
source: 'salesforce',
|
|
sourceEntity: 'account',
|
|
sourceEntityId: salesforceId,
|
|
target: 'v2',
|
|
targetEntity: 'subscription',
|
|
targetEntityId: subscriptionId,
|
|
createdAt: new Date().toISOString(),
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {string} subscriptionId
|
|
* @param {string} recurlyId
|
|
* @param {string} [createdAt] - Should be an ISO date
|
|
* @return {AccountMapping}
|
|
*/
|
|
function generateSubscriptionToRecurlyMapping(
|
|
subscriptionId,
|
|
recurlyId,
|
|
createdAt = new Date().toISOString()
|
|
) {
|
|
return {
|
|
source: 'recurly',
|
|
sourceEntity: 'subscription',
|
|
sourceEntityId: recurlyId,
|
|
target: 'v2',
|
|
targetEntity: 'subscription',
|
|
targetEntityId: subscriptionId,
|
|
createdAt,
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param {string} subscriptionId
|
|
* @param {string} stripeId
|
|
* @param {StripePaymentProviderService} stripePaymentProviderService
|
|
* @param {string} [createdAt] - Should be an ISO date
|
|
* @return {AccountMapping}
|
|
*/
|
|
function generateSubscriptionToStripeMapping(
|
|
subscriptionId,
|
|
stripeId,
|
|
stripePaymentProviderService,
|
|
createdAt = new Date().toISOString()
|
|
) {
|
|
return {
|
|
source: stripePaymentProviderService,
|
|
sourceEntity: 'subscription',
|
|
sourceEntityId: stripeId,
|
|
target: 'v2',
|
|
targetEntity: 'subscription',
|
|
targetEntityId: subscriptionId,
|
|
createdAt,
|
|
}
|
|
}
|
|
|
|
export default {
|
|
extractAccountMappingsFromSubscription,
|
|
generateV1Mapping,
|
|
generateSubscriptionToRecurlyMapping,
|
|
generateSubscriptionToStripeMapping,
|
|
}
|