Extern trigger for setting fields to subscriber

This commit is contained in:
elweyn 2023-04-04 19:10:25 +02:00
parent 05e0ab1f7b
commit f486bc0fd0

View File

@ -1,8 +1,12 @@
// eslint-disable @typescript-eslint/no-explicit-any
import { User } from '@entity/User'
import { getKlickTippUser } from '@/apis/KlicktippController'
import { getKlickTippUser, addFieldsToSubscriber } from '@/apis/KlicktippController'
import LogError from '@/server/LogError'
import connection from '@/typeorm/connection'
import { lastDateTimeEvents } from '@/graphql/resolver/util/eventList'
import { EventType } from '@/event/EventType'
import { Event as DbEvent } from '@/event/Event'
export async function retrieveNotRegisteredEmails(): Promise<string[]> {
const con = await connection()
@ -27,4 +31,35 @@ export async function retrieveNotRegisteredEmails(): Promise<string[]> {
return notRegisteredUser
}
void retrieveNotRegisteredEmails()
function klickTippSendFieldToUser(events: any, value: string): void {
for(const event of events) {
addFieldsToSubscriber(event.email, { [value]: event.value })
}
}
export async function exportEventDataToKlickTipp(): Promise<void> {
const connectionInstance = await connection()
if (!connectionInstance) {
throw new LogError('No connection to database')
}
const lastLoginEvents = await lastDateTimeEvents(EventType.USER_LOGIN)
klickTippSendFieldToUser(lastLoginEvents, 'GDD last login')
const registeredEvents = await lastDateTimeEvents(EventType.USER_ACTIVATE_ACCOUNT)
klickTippSendFieldToUser(registeredEvents, 'GDD date of registration')
const receiveTransactionEvents = await lastDateTimeEvents(EventType.TRANSACTION_RECEIVE)
klickTippSendFieldToUser(receiveTransactionEvents, 'GDD last received')
const contributionCreateEvents = await lastDateTimeEvents(EventType.TRANSACTION_SEND)
klickTippSendFieldToUser(contributionCreateEvents, 'GDD last sent')
const linkRedeemedEvents = await lastDateTimeEvents(EventType.TRANSACTION_LINK_REDEEM)
klickTippSendFieldToUser(linkRedeemedEvents, 'GDD last invited')
const confirmContributionEvents = await lastDateTimeEvents(EventType.ADMIN_CONTRIBUTION_CONFIRM)
klickTippSendFieldToUser(confirmContributionEvents, 'GDD last created')
}
void exportEventDataToKlickTipp()
// void retrieveNotRegisteredEmails()