src/admin-profile/admin-profile.service.ts
Properties |
|
Methods |
|
constructor(adminModel: Model<AdminDocument>)
|
||||||
|
Parameters :
|
| Async findByEmail | ||||||
findByEmail(email: string)
|
||||||
|
Parameters :
Returns :
unknown
|
| Async getCustodial |
getCustodial(email: string, address?: string)
|
|
Returns :
Promise<CustodialDocument>
|
| Async saveAdmin | |||||||||
saveAdmin(email: string, wallets: WalletDocument[])
|
|||||||||
|
Parameters :
Returns :
unknown
|
| Private Readonly internalCustodialService |
Type : InternalCustodialService
|
Decorators :
@Inject(InternalCustodialService)
|
import { Inject, Injectable } from "@nestjs/common";
import { InjectModel } from "@nestjs/mongoose";
import { Model } from "mongoose";
import { Admin, AdminDocument } from "./schemas/admin.schema";
import { WalletDocument } from "src/wallet/schemas/wallet.schema";
import { InternalCustodialService } from "src/shared/custodial/internalCustodial.service";
import { CustodialDocument } from "src/shared/custodial/schemas/custodial.schema";
@Injectable()
export class AdminProfileService {
@Inject(InternalCustodialService)
private readonly internalCustodialService: InternalCustodialService;
constructor(
@InjectModel(Admin.name)
private readonly adminModel: Model<AdminDocument>,
) {}
async saveAdmin(email: string, wallets: WalletDocument[]) {
const admin = new this.adminModel({
email,
wallets,
});
return admin.save();
}
async findByEmail(email: string) {
return this.adminModel.findOne({ email });
}
async getCustodial(
email: string,
address?: string,
): Promise<CustodialDocument> {
let walletAddress: string;
if (address) {
walletAddress = address;
} else {
const admin = await this.findByEmail(email);
walletAddress = admin.wallets[0].address;
}
return await this.internalCustodialService.findOne(walletAddress);
}
}