File

src/admin/admin.service.ts

Index

Properties
Methods

Methods

Async create
create(email: string)
Parameters :
Name Type Optional
email string No
Async findByEmail
findByEmail(email: string)
Parameters :
Name Type Optional
email string No
Returns : unknown

Properties

Private Readonly adminProfileService
Type : AdminProfileService
Decorators :
@Inject(AdminProfileService)
Private Readonly walletService
Type : WalletService
Decorators :
@Inject(WalletService)
import { Inject, Injectable } from "@nestjs/common";
import { WalletService } from "../wallet/wallet.service";
import { AdminDocument } from "../admin-profile/schemas/admin.schema";
import { Roles } from "src/common/constants";
import { ContractName, TransactionNames } from "src/common/interfaces";
import { transactionSubmitter, getContractByName } from "src/common/provider";
import { AdminProfileService } from "../admin-profile/admin-profile.service";

@Injectable()
export class AdminService {
  @Inject(WalletService)
  private readonly walletService: WalletService;

  @Inject(AdminProfileService)
  private readonly adminProfileService: AdminProfileService;

  async create(email: string): Promise<AdminDocument> {
    const defaultWallet = await this.walletService.create({
      walletLabel: "Default wallet",
    });

    await transactionSubmitter({
      signerKey: process.env.RELAYER_KEY,
      contractAddress: getContractByName[ContractName.RoleRegistry].address,
      contractName: ContractName.RoleRegistry,
      transactionName: TransactionNames.grantRole,
      args: [Roles.Admin, defaultWallet.address],
    });

    return this.adminProfileService.saveAdmin(email, [defaultWallet]);
  }

  async findByEmail(email: string) {
    return this.adminProfileService.findByEmail(email);
  }
}

results matching ""

    No results matching ""