Add an endpoint for rails to record salesforce mappings

GitOrigin-RevId: fcca974a69217dc885c458543a82b4dcc338d98b
This commit is contained in:
andrew rumble 2024-09-03 15:30:34 +01:00 committed by Copybot
parent 24b27e3863
commit 2486f893eb
3 changed files with 42 additions and 0 deletions

View file

@ -28,8 +28,30 @@ export function extractAccountMappingsFromSubscription(
} }
return accountMappings return accountMappings
} }
export 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) { function generateSubscriptionToSalesforceMapping(subscriptionId, salesforceId) {
return { return {
@ -45,4 +67,5 @@ function generateSubscriptionToSalesforceMapping(subscriptionId, salesforceId) {
export default { export default {
extractAccountMappingsFromSubscription, extractAccountMappingsFromSubscription,
generateV1Mapping,
} }

View file

@ -4,6 +4,18 @@ import SessionManager from '../Authentication/SessionManager.js'
import GeoIpLookup from '../../infrastructure/GeoIpLookup.js' import GeoIpLookup from '../../infrastructure/GeoIpLookup.js'
import Features from '../../infrastructure/Features.js' import Features from '../../infrastructure/Features.js'
import { expressify } from '@overleaf/promise-utils' import { expressify } from '@overleaf/promise-utils'
import { generateV1Mapping } from './AccountMappingHelper.mjs'
async function registerSalesforceMapping(req, res, next) {
if (!Features.hasFeature('analytics')) {
return res.sendStatus(202)
}
const { createdAt, salesforceId, v1Id } = req.body
AnalyticsManager.registerAccountMapping(
generateV1Mapping(v1Id, salesforceId, createdAt)
)
res.sendStatus(202)
}
async function updateEditingSession(req, res, next) { async function updateEditingSession(req, res, next) {
if (!Features.hasFeature('analytics')) { if (!Features.hasFeature('analytics')) {
@ -47,6 +59,7 @@ function recordEvent(req, res, next) {
} }
export default { export default {
registerSalesforceMapping: expressify(registerSalesforceMapping),
updateEditingSession: expressify(updateEditingSession), updateEditingSession: expressify(updateEditingSession),
recordEvent, recordEvent,
} }

View file

@ -41,5 +41,11 @@ export default {
RateLimiterMiddleware.rateLimit(rateLimiters.uniExternalCollabProxy), RateLimiterMiddleware.rateLimit(rateLimiters.uniExternalCollabProxy),
AnalyticsProxy.call('/uniExternalCollaboration') AnalyticsProxy.call('/uniExternalCollaboration')
) )
publicApiRouter.post(
'/analytics/register-v-1-salesforce-mapping',
AuthenticationController.requirePrivateApiAuth(),
AnalyticsController.registerSalesforceMapping
)
}, },
} }