Skip to content

Commit

Permalink
Add some logs
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedwiper committed Jun 21, 2024
1 parent 7c084d7 commit 7dec171
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config/dist/config.service';
import { EntityNotFoundError } from '@shared/common';
import { Counted, EntityId } from '@shared/domain/types';
import { LegacyLogger } from '@src/core/logger';
import bcrypt from 'bcryptjs';
import { AccountConfig } from '../../account-config';
import { AccountRepo } from '../../repo/micro-orm/account.repo';
Expand All @@ -15,7 +16,8 @@ export class AccountServiceDb {
constructor(
private readonly accountRepo: AccountRepo,
private readonly idmService: IdentityManagementService,
private readonly configService: ConfigService<AccountConfig, true>
private readonly configService: ConfigService<AccountConfig, true>,
private readonly logger: LegacyLogger
) {}

async findById(id: EntityId): Promise<Account> {
Expand Down Expand Up @@ -62,6 +64,7 @@ export class AccountServiceDb {
}

async updateLastLogin(accountId: EntityId, lastLogin: Date): Promise<Account> {
this.logger.debug(`Updating last login for ${accountId} to ${lastLogin.toISOString()}`);
const internalId = await this.getInternalId(accountId);
const account = await this.accountRepo.findById(internalId);
account.lastLogin = lastLogin;
Expand Down
10 changes: 7 additions & 3 deletions apps/server/src/modules/account/repo/micro-orm/account.repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { EntityManager, ObjectId } from '@mikro-orm/mongodb';
import { Injectable } from '@nestjs/common';
import { SortOrder } from '@shared/domain/interface';
import { Counted, EntityId } from '@shared/domain/types';
import { AccountEntity } from '../../domain/entity/account.entity';
import { AccountDoToEntityMapper } from './mapper/account-do-to-entity.mapper';
import { LegacyLogger } from '@src/core/logger';
import { Account } from '../../domain/account';
import { AccountEntity } from '../../domain/entity/account.entity';
import { AccountEntityToDoMapper } from './mapper';
import { AccountDoToEntityMapper } from './mapper/account-do-to-entity.mapper';
import { AccountScope } from './scope/account-scope';

@Injectable()
export class AccountRepo {
constructor(private readonly em: EntityManager) {}
constructor(private readonly em: EntityManager, private readonly logger: LegacyLogger) {}

get entityName() {
return AccountEntity;
Expand All @@ -21,6 +22,9 @@ export class AccountRepo {
const saveEntity = AccountDoToEntityMapper.mapToEntity(account);
const existing = await this.em.findOne(AccountEntity, { id: account.id });

this.logger.debug('existing', JSON.stringify(existing));
this.logger.debug('Saving account', JSON.stringify(saveEntity));

let saved: AccountEntity;
if (existing) {
saved = this.em.assign(existing, saveEntity);
Expand Down

0 comments on commit 7dec171

Please sign in to comment.