data persistance init

This commit is contained in:
Ben Wilson
2023-06-23 22:30:54 -04:00
parent b963eaa514
commit 080471e52d
16 changed files with 2760 additions and 188 deletions
+51
View File
@@ -0,0 +1,51 @@
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(id: string) {
return await this.clientRepository.softDelete({ id });
}
public async updateBestDifficulty(id: string, bestDifficulty: number) {
return await this.clientRepository.update(id, { 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 getByAddressAndName(address: string, id: string): Promise<ClientEntity> {
return await this.clientRepository.findOne({
where: {
address,
id
}
})
}
}