This repository has been archived by the owner on Dec 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds statement creators for completed sale and generated lead (…
…LLC-36) (#10)
- Loading branch information
1 parent
a13ebf7
commit b33f49c
Showing
6 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
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,20 @@ | ||
import completedSale from '../statementCreators/completedSale'; | ||
|
||
const statement = completedSale({ | ||
actionDate: new Date(), | ||
activityUrl: 'https://demo.example.org/courses/demo-course', | ||
siteUrl: 'https://demo.example.org', | ||
siteName: 'Demo Example Site', | ||
platformUrl: 'https://example.org', | ||
platformName: 'Example Platform', | ||
userId: '123', | ||
userIdProviderUrl: 'https://demo.example.org', | ||
userEmail: '[email protected]', | ||
userDisplayName: 'Demo User', | ||
isWon: true, | ||
closedReason: 'Too expensive', | ||
accountDisplayName: 'Example Account', | ||
accountUrl: 'https://demo.example.org', | ||
}); | ||
|
||
export default statement; |
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,16 @@ | ||
import generatedLead from '../statementCreators/generatedLead'; | ||
|
||
const statement = generatedLead({ | ||
actionDate: new Date(), | ||
activityUrl: 'https://demo.example.org/courses/demo-course', | ||
siteUrl: 'https://demo.example.org', | ||
siteName: 'Demo Example Site', | ||
platformUrl: 'https://example.org', | ||
platformName: 'Example Platform', | ||
userId: '123', | ||
userIdProviderUrl: 'https://demo.example.org', | ||
userEmail: '[email protected]', | ||
userDisplayName: 'Demo User', | ||
}); | ||
|
||
export default statement; |
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
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
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,82 @@ | ||
import UserSiteAction from '../actionUtils/UserSiteAction'; | ||
import { organization, salesOpportunity, site, source } from '../statementConstants/activityTypes'; | ||
import { closedSale } from '../statementConstants/verbs'; | ||
import createActivity from '../statementUtils/createActivity'; | ||
import createAgent from '../statementUtils/createAgent'; | ||
import createTimestamp from '../statementUtils/createTimestamp'; | ||
import { Extensions, Statement } from '../statementUtils/types'; | ||
|
||
export interface CompletedSaleAction extends UserSiteAction { | ||
/** The URL where the activity can be accessed. */ | ||
readonly activityUrl: string; | ||
|
||
/** The human readable name for the activity. */ | ||
readonly activityName?: string; | ||
|
||
/** Additional properties of the activity. */ | ||
readonly activityExtensions?: Extensions; | ||
|
||
/** Determines if the sale was a success or failure. */ | ||
readonly isWon?: boolean; | ||
|
||
/** The reason for which a sale or opportunity is closed, usually when lost */ | ||
readonly closedReason?: string; | ||
|
||
/** The URL or identifier of the account or organization linked to the sale or opportunity. */ | ||
readonly accountUrl: string; | ||
|
||
/** The name of the account or organization linked to the sale or opportunity. */ | ||
readonly accountDisplayName?: string; | ||
} | ||
|
||
/** | ||
* Creates an xAPI Statement to represent a user completing a face-to-face meeting. | ||
*/ | ||
export default function completedSale(action: CompletedSaleAction): Statement { | ||
return { | ||
timestamp: createTimestamp(action.actionDate), | ||
actor: createAgent({ | ||
displayName: action.userDisplayName, | ||
id: action.userId, | ||
idProviderUrl: action.userIdProviderUrl, | ||
email: action.userEmail, | ||
}), | ||
verb: closedSale, | ||
object: createActivity({ | ||
type: salesOpportunity, | ||
url: action.activityUrl, | ||
name: action.activityName, | ||
extensions: action.activityExtensions, | ||
}), | ||
context: { | ||
platform: action.platformName, | ||
language: 'en', | ||
extensions: action.contextExtensions, | ||
contextActivities: { | ||
grouping: [ | ||
createActivity({ | ||
type: site, | ||
url: action.siteUrl, | ||
name: action.siteName, | ||
}), | ||
], | ||
parent: [ | ||
createActivity({ | ||
type: organization, | ||
url: action.accountUrl, | ||
name: action.accountDisplayName, | ||
}), | ||
], | ||
category: [createActivity({ | ||
type: source, | ||
url: action.platformUrl, | ||
name: action.platformName, | ||
})], | ||
}, | ||
}, | ||
result: { | ||
success: action.isWon, | ||
response: action.closedReason, | ||
}, | ||
}; | ||
} |
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,57 @@ | ||
import UserSiteAction from '../actionUtils/UserSiteAction'; | ||
import { salesLead, site, source } from '../statementConstants/activityTypes'; | ||
import { generated } from '../statementConstants/verbs'; | ||
import createActivity from '../statementUtils/createActivity'; | ||
import createAgent from '../statementUtils/createAgent'; | ||
import createTimestamp from '../statementUtils/createTimestamp'; | ||
import { Extensions, Statement } from '../statementUtils/types'; | ||
|
||
export interface GeneratedLeadAction extends UserSiteAction { | ||
/** The URL where the activity can be accessed. */ | ||
readonly activityUrl: string; | ||
|
||
/** The human readable name for the activity. */ | ||
readonly activityName?: string; | ||
|
||
/** Additional properties of the activity. */ | ||
readonly activityExtensions?: Extensions; | ||
} | ||
|
||
/** | ||
* Creates an xAPI Statement to represent a user completing a face-to-face meeting. | ||
*/ | ||
export default function generatedLead(action: GeneratedLeadAction): Statement { | ||
return { | ||
timestamp: createTimestamp(action.actionDate), | ||
actor: createAgent({ | ||
displayName: action.userDisplayName, | ||
id: action.userId, | ||
idProviderUrl: action.userIdProviderUrl, | ||
email: action.userEmail, | ||
}), | ||
verb: generated, | ||
object: createActivity({ | ||
type: salesLead, | ||
url: action.activityUrl, | ||
name: action.activityName, | ||
extensions: action.activityExtensions, | ||
}), | ||
context: { | ||
platform: action.platformName, | ||
language: 'en', | ||
extensions: action.contextExtensions, | ||
contextActivities: { | ||
grouping: [createActivity({ | ||
type: site, | ||
url: action.siteUrl, | ||
name: action.siteName, | ||
})], | ||
category: [createActivity({ | ||
type: source, | ||
url: action.platformUrl, | ||
name: action.platformName, | ||
})], | ||
}, | ||
}, | ||
}; | ||
} |