diff --git a/src/adapters/notifications/MockNotificationAdapter.ts b/src/adapters/notifications/MockNotificationAdapter.ts index 2609538a1..dea041ca3 100644 --- a/src/adapters/notifications/MockNotificationAdapter.ts +++ b/src/adapters/notifications/MockNotificationAdapter.ts @@ -11,6 +11,11 @@ import { logger } from '../../utils/logger'; import { RecurringDonation } from '../../entities/recurringDonation'; export class MockNotificationAdapter implements NotificationAdapterInterface { + async createOrttoProfile(params: User): Promise { + logger.debug('MockNotificationAdapter createOrttoProfile', params); + return Promise.resolve(undefined); + } + async updateOrttoPeople(params: OrttoPerson[]): Promise { logger.debug('MockNotificationAdapter updateOrttoPeople', params); return Promise.resolve(undefined); diff --git a/src/adapters/notifications/NotificationAdapterInterface.ts b/src/adapters/notifications/NotificationAdapterInterface.ts index cad690687..8e0f88dd2 100644 --- a/src/adapters/notifications/NotificationAdapterInterface.ts +++ b/src/adapters/notifications/NotificationAdapterInterface.ts @@ -34,6 +34,8 @@ export interface OrttoPerson { } export interface NotificationAdapterInterface { + createOrttoProfile(params: User): Promise; + updateOrttoPeople(params: OrttoPerson[]): Promise; donationReceived(params: { diff --git a/src/adapters/notifications/NotificationCenterAdapter.ts b/src/adapters/notifications/NotificationCenterAdapter.ts index cc65cc942..75896d01c 100644 --- a/src/adapters/notifications/NotificationCenterAdapter.ts +++ b/src/adapters/notifications/NotificationCenterAdapter.ts @@ -94,6 +94,22 @@ export class NotificationCenterAdapter implements NotificationAdapterInterface { return; } + async createOrttoProfile(user: User): Promise { + try { + const { id, email, firstName, lastName } = user; + await callSendNotification({ + eventName: NOTIFICATIONS_EVENT_NAMES.CREATE_ORTTO_PROFILE, + trackId: 'create-ortto-profile-' + user.id, + userWalletAddress: user.walletAddress!, + segment: { + payload: { userId: id, email, firstName, lastName }, + }, + }); + } catch (e) { + logger.error('createOrttoProfile >> error', e); + } + } + async updateOrttoPeople(people: OrttoPerson[]): Promise { // TODO we should me this to notification-center, it's not good that we call Ortto directly try { @@ -1196,7 +1212,7 @@ interface SendNotificationBody { email?: string; trackId?: string; metadata?: any; - projectId: string; + projectId?: string; userWalletAddress: string; segment?: { payload: any; diff --git a/src/analytics/analytics.ts b/src/analytics/analytics.ts index 62478d0e9..e7ebf9155 100644 --- a/src/analytics/analytics.ts +++ b/src/analytics/analytics.ts @@ -46,4 +46,5 @@ export enum NOTIFICATIONS_EVENT_NAMES { SUPER_TOKENS_BALANCE_WEEK = 'One week left in stream balance', SUPER_TOKENS_BALANCE_MONTH = 'One month left in stream balance', SUPER_TOKENS_BALANCE_DEPLETED = 'Stream balance depleted', + CREATE_ORTTO_PROFILE = 'Create Ortto profile', } diff --git a/src/resolvers/userResolver.ts b/src/resolvers/userResolver.ts index 4a56ae2a6..32754a08b 100644 --- a/src/resolvers/userResolver.ts +++ b/src/resolvers/userResolver.ts @@ -125,6 +125,7 @@ export class UserResolver { @Arg('email', { nullable: true }) email: string, @Arg('url', { nullable: true }) url: string, @Arg('avatar', { nullable: true }) avatar: string, + @Arg('newUser', { nullable: true }) newUser: boolean, @Ctx() { req: { user } }: ApolloContext, ): Promise { if (!user) @@ -185,6 +186,9 @@ export class UserResolver { userId: dbUser.id.toString(), }); await getNotificationAdapter().updateOrttoPeople([orttoPerson]); + if (newUser) { + await getNotificationAdapter().createOrttoProfile(dbUser); + } return true; } diff --git a/test/graphqlQueries.ts b/test/graphqlQueries.ts index 69352e2d4..3e9146d6a 100644 --- a/test/graphqlQueries.ts +++ b/test/graphqlQueries.ts @@ -1318,6 +1318,7 @@ export const updateUser = ` $lastName: String $firstName: String $avatar: String + $newUser: Boolean ) { updateUser( url: $url @@ -1326,6 +1327,7 @@ export const updateUser = ` firstName: $firstName lastName: $lastName avatar: $avatar + newUser: $newUser ) } `;