mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 17:15:03 -07:00
telegram bot
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { Column, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
|
||||
|
||||
import { TrackedEntity } from '../utils/TrackedEntity.entity';
|
||||
|
||||
@Entity()
|
||||
export class TelegramSubscriptionsEntity extends TrackedEntity {
|
||||
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number;
|
||||
|
||||
@Index()
|
||||
@Column({ length: 62, type: 'varchar' })
|
||||
address: string;
|
||||
|
||||
@Column()
|
||||
telegramChatId: number;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { TelegramSubscriptionsEntity } from './telegram-subscriptions.entity';
|
||||
import { TelegramSubscriptionsService } from './telegram-subscriptions.service';
|
||||
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([TelegramSubscriptionsEntity])],
|
||||
providers: [TelegramSubscriptionsService],
|
||||
exports: [TypeOrmModule, TelegramSubscriptionsService],
|
||||
})
|
||||
export class TelegramSubscriptionsModule { }
|
||||
@@ -0,0 +1,27 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { TelegramSubscriptionsEntity } from './telegram-subscriptions.entity';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class TelegramSubscriptionsService {
|
||||
constructor(
|
||||
@InjectRepository(TelegramSubscriptionsEntity)
|
||||
private telegramSubscriptions: Repository<TelegramSubscriptionsEntity>
|
||||
) {
|
||||
|
||||
}
|
||||
|
||||
public async getSubscriptions(address: string) {
|
||||
return await this.telegramSubscriptions.find({ where: { address } })
|
||||
}
|
||||
|
||||
public async saveSubscription(chatId: number, address: string) {
|
||||
return await this.telegramSubscriptions.save({
|
||||
telegramChatId: chatId,
|
||||
address
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user