import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { ClientEntity } from './client.entity'; @Injectable() export class ClientService { constructor( @InjectRepository(ClientEntity) private clientRepository: Repository ) { } public async save(client: Partial) { return await this.clientRepository.save(client); } public async delete(sessionId: string) { return await this.clientRepository.softDelete({ sessionId }); } public async updateBestDifficulty(sessionId: string, bestDifficulty: number) { return await this.clientRepository.update({ sessionId }, { bestDifficulty }); } public async connectedClientCount(): Promise { return await this.clientRepository.count(); } public async getByAddress(address: string): Promise { return await this.clientRepository.find({ where: { address } }) } public async getByName(address: string, clientName: string): Promise { return await this.clientRepository.find({ where: { address, clientName } }) } public async getBySessionId(address: string, clientName: string, sessionId: string): Promise { return await this.clientRepository.findOne({ where: { address, clientName, sessionId } }) } public async deleteAll() { return await this.clientRepository.softDelete({}) } }