import { Model } from 'mongoose' ; import { Injectable } from '@nestjs/common' ; import { InjectModel } from '@nestjs/mongoose' ; import { LoggerService } from '@fc/logger' ; import { IInteraction } from '../interfaces' ; import { Account } from '../schemas' ; @ Injectable ( ) export class AccountService { constructor ( private readonly logger , @ InjectModel ( 'Account' ) private model ) { this . logger . setContext ( this . constructor . name ) ; } param identityHash async isBlocked ( identityHash ) { const account = await this . model . findOne ( { identityHash , active : false , } ) ; return account !== null ; } param { IInteraction } interaction returns { Promise < void > } async storeInteraction ( interaction ) { this . logger . debug ( 'Save interaction to database' ) ; const account = await this . getAccountWithInteraction ( interaction ) ; await account . save ( ) ; return account . id ; } param { IInteraction } interaction returns { Promise < Account > } private async getAccountWithInteraction ( interaction ) { const { identityHash } = interaction ; let account = await this . model . findOne ( { identityHash } ) ; if ( ! account ) { account = new this . model ( { identityHash } ) ; } account . idpFederation = { ... account . idpFederation , ... interaction . idpFederation , } ; account . spFederation = { ... account . spFederation , ... interaction . spFederation , } ; account . lastConnection = interaction . lastConnection ; return account ; } see CryptographyFcpService . computeIdentityHash param { string } identityHash returns { Promise < Account > } async getAccountByIdentityHash ( identityHash ) { this . logger . debug ( `Recherche d'un compte avec via son hash` ) ; const account = await this . model . findOne ( { identityHash } ) ; if ( ! account ) { return { id : null } as Account ; } this . logger . trace ( { account } ) ; return account ; } }