This commit is contained in:
Ben Wilson
2023-06-24 12:54:13 -04:00
parent 080471e52d
commit f61e9f1417
10 changed files with 115 additions and 53 deletions
+17 -14
View File
@@ -1,29 +1,32 @@
import { Column, Entity, OneToMany, PrimaryColumn } from 'typeorm';
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';
import { ClientStatisticsEntity } from '../client-statistics/client-statistics.entity';
import { TrackedEntity } from '../utils/TrackedEntity.entity';
@Entity()
export class ClientEntity extends TrackedEntity {
@PrimaryColumn({ length: 8, type: 'varchar' })
id: string;
@Column({ type: 'datetime' })
startTime: Date;
@PrimaryGeneratedColumn()
id: number;
@Column()
clientName: string;
@Column({ length: 62, type: 'varchar' })
address: string;
@Column()
clientName: string;
@Column({ length: 8, type: 'varchar' })
sessionId: string;
@Column({ type: 'datetime' })
startTime: Date;
@Column({ default: 0 })
bestDifficulty: number
@OneToMany(
() => ClientStatisticsEntity,
clientStatistic => clientStatistic.client
)
clientStatistics?: ClientStatisticsEntity[];
}
}
+11 -6
View File
@@ -21,12 +21,12 @@ export class ClientService {
return await this.clientRepository.save(client);
}
public async delete(id: string) {
return await this.clientRepository.softDelete({ id });
public async delete(sessionId: string) {
return await this.clientRepository.softDelete({ sessionId });
}
public async updateBestDifficulty(id: string, bestDifficulty: number) {
return await this.clientRepository.update(id, { bestDifficulty });
public async updateBestDifficulty(sessionId: string, bestDifficulty: number) {
return await this.clientRepository.update({ sessionId }, { bestDifficulty });
}
public async connectedClientCount(): Promise<number> {
return await this.clientRepository.count();
@@ -40,12 +40,17 @@ export class ClientService {
})
}
public async getByAddressAndName(address: string, id: string): Promise<ClientEntity> {
public async getById(address: string, clientName: string, sessionId: string): Promise<ClientEntity> {
return await this.clientRepository.findOne({
where: {
address,
id
clientName,
sessionId
}
})
}
public async deleteAll() {
return await this.clientRepository.softDelete({})
}
}