diff --git a/backend/src/graphql/resolver/UserResolver.ts b/backend/src/graphql/resolver/UserResolver.ts index 3aa7e7fd5..437d7072e 100644 --- a/backend/src/graphql/resolver/UserResolver.ts +++ b/backend/src/graphql/resolver/UserResolver.ts @@ -27,6 +27,7 @@ import { LoginUserRepository } from '../../typeorm/repository/LoginUser' import { Setting } from '../enum/Setting' import { UserRepository } from '../../typeorm/repository/User' import { LoginUser } from '@entity/LoginUser' +import { LoginElopageBuys } from '@entity/LoginElopageBuys' import { LoginUserBackup } from '@entity/LoginUserBackup' import { LoginEmailOptIn } from '@entity/LoginEmailOptIn' import { sendEMail } from '../../util/sendEMail' @@ -600,12 +601,17 @@ export class UserResolver { return new CheckEmailResponse(result.data) } + @Authorized() @Query(() => Boolean) async hasElopage(@Ctx() context: any): Promise { - const result = await apiGet(CONFIG.LOGIN_API_URL + 'hasElopage?session_id=' + context.sessionId) - if (!result.success) { - throw new Error(result.data) + // const result = await apiGet(CONFIG.LOGIN_API_URL + 'hasElopage?session_id=' + context.sessionId) + const userRepository = getCustomRepository(UserRepository) + const userEntity = await userRepository.findByPubkeyHex(context.pubKey).catch() + if (!userEntity) { + return false } - return result.data.hasElopage + + const elopageBuyCount = await LoginElopageBuys.count({ payerEmail: userEntity.email }) + return elopageBuyCount > 0 } } diff --git a/database/entity/0003-login_server_tables/LoginElopageBuys.ts b/database/entity/0003-login_server_tables/LoginElopageBuys.ts new file mode 100644 index 000000000..fc0d6c355 --- /dev/null +++ b/database/entity/0003-login_server_tables/LoginElopageBuys.ts @@ -0,0 +1,52 @@ +import { BaseEntity, Entity, PrimaryGeneratedColumn, Column } from 'typeorm' + +@Entity('login_elopage_buys') +export class LoginElopageBuys extends BaseEntity { + @PrimaryGeneratedColumn('increment', { unsigned: true }) + id: number + + @Column({ name: 'elopage_user_id', nullable: false }) + elopageUserId: number + + @Column({ name: 'affiliate_program_id', nullable: false }) + affiliateProgramId: number + + @Column({ name: 'publisher_id', nullable: false }) + publisherId: number + + @Column({ name: 'order_id', nullable: false }) + orderId: number + + @Column({ name: 'product_id', nullable: false }) + productId: number + + @Column({ name: 'product_price', nullable: false }) + productPrice: number + + @Column({ + name: 'payer_email', + length: 255, + nullable: false, + charset: 'utf8', + collation: 'utf8_bin', + }) + payerEmail: string + + @Column({ + name: 'publisher_email', + length: 255, + nullable: false, + charset: 'utf8', + collation: 'utf8_bin', + }) + publisherEmail: string + + @Column({ nullable: false }) + payed: boolean + + @Column({ name: 'success_date', nullable: false }) + successDate: Date + + @Column({ length: 255, nullable: false }) + event: string +} diff --git a/database/entity/LoginElopageBuys.ts b/database/entity/LoginElopageBuys.ts new file mode 100644 index 000000000..6a1f3230b --- /dev/null +++ b/database/entity/LoginElopageBuys.ts @@ -0,0 +1 @@ +export { LoginElopageBuys } from './0003-login_server_tables/LoginElopageBuys' diff --git a/database/entity/index.ts b/database/entity/index.ts index ff1d34d9e..5e4e98118 100644 --- a/database/entity/index.ts +++ b/database/entity/index.ts @@ -1,4 +1,5 @@ import { Balance } from './Balance' +import { LoginElopageBuys } from './LoginElopageBuys' import { LoginEmailOptIn } from './LoginEmailOptIn' import { LoginUser } from './LoginUser' import { LoginUserBackup } from './LoginUserBackup' @@ -12,9 +13,10 @@ import { UserTransaction } from './UserTransaction' export const entities = [ Balance, + LoginElopageBuys, + LoginEmailOptIn, LoginUser, LoginUserBackup, - LoginEmailOptIn, Migration, Transaction, TransactionCreation,