found blocks services and tables

This commit is contained in:
Ben Wilson
2023-07-12 22:53:26 -04:00
parent cf3f414475
commit ddc7907919
7 changed files with 115 additions and 7 deletions
+49
View File
@@ -0,0 +1,49 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { DataSource, Repository } from 'typeorm';
import { BlocksEntity } from './blocks.entity';
@Injectable()
export class BlocksService {
constructor(
private dataSource: DataSource,
@InjectRepository(BlocksEntity)
private blocksRepository: Repository<BlocksEntity>,
) {
}
public async save(block: Partial<BlocksEntity>) {
await this.blocksRepository.save(block);
}
public async getFoundBlocks() {
return await this.blocksRepository.find({
select: {
height: true,
minerAddress: true,
worker: true,
sessionId: true
}
});
}
public async getFoundBlocksByAddress(address: string) {
return await this.blocksRepository.find({
select: {
height: true,
minerAddress: true,
worker: true,
sessionId: true
},
where: {
minerAddress: address
}
});
}
}