mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
66 lines
1.7 KiB
TypeScript
66 lines
1.7 KiB
TypeScript
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<ClientEntity>
|
|
) {
|
|
|
|
}
|
|
|
|
public async save(client: Partial<ClientEntity>) {
|
|
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<number> {
|
|
return await this.clientRepository.count();
|
|
}
|
|
|
|
public async getByAddress(address: string): Promise<ClientEntity[]> {
|
|
return await this.clientRepository.find({
|
|
where: {
|
|
address
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
public async getByName(address: string, clientName: string): Promise<ClientEntity[]> {
|
|
return await this.clientRepository.find({
|
|
where: {
|
|
address,
|
|
clientName
|
|
}
|
|
})
|
|
}
|
|
|
|
public async getBySessionId(address: string, clientName: string, sessionId: string): Promise<ClientEntity> {
|
|
return await this.clientRepository.findOne({
|
|
where: {
|
|
address,
|
|
clientName,
|
|
sessionId
|
|
}
|
|
})
|
|
}
|
|
|
|
public async deleteAll() {
|
|
return await this.clientRepository.softDelete({})
|
|
}
|
|
} |