src/admin/admin.service.ts
Properties |
|
Methods |
|
| Async create | ||||||
create(email: string)
|
||||||
|
Defined in src/admin/admin.service.ts:17
|
||||||
|
Parameters :
Returns :
Promise<AdminDocument>
|
| Async findByEmail | ||||||
findByEmail(email: string)
|
||||||
|
Defined in src/admin/admin.service.ts:33
|
||||||
|
Parameters :
Returns :
unknown
|
| Private Readonly adminProfileService |
Type : AdminProfileService
|
Decorators :
@Inject(AdminProfileService)
|
|
Defined in src/admin/admin.service.ts:15
|
| Private Readonly walletService |
Type : WalletService
|
Decorators :
@Inject(WalletService)
|
|
Defined in src/admin/admin.service.ts:12
|
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);
}
}