Skip to content

Commit

Permalink
feat: add operation state module
Browse files Browse the repository at this point in the history
Signed-off-by: Anmol Sharma <anmolsharma0234@gmail.com>
  • Loading branch information
theanmolsharma committed May 5, 2024
1 parent 713caa5 commit 624137d
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ConfigModule, ConfigService } from '@nestjs/config';
import configuration from '@/configuration';
import { TransactionsModule } from '@/transactions/transactions.module';
import { commandHandlers } from '@/commands/handlers';
import { OperationStateModule } from '@/operation-state/operation-state.module';

@Module({
imports: [
Expand All @@ -29,6 +30,7 @@ import { commandHandlers } from '@/commands/handlers';
}),
}),
TransactionsModule,
OperationStateModule,
],
controllers: [AppController],
providers: [AppService, ...commandHandlers],
Expand Down
10 changes: 10 additions & 0 deletions src/operation-state/operation-state.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Column, Entity, PrimaryColumn } from 'typeorm';

@Entity()
export class OperationState {
@PrimaryColumn('text')
id: string;

@Column('jsonb')
state: any;
}
12 changes: 12 additions & 0 deletions src/operation-state/operation-state.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { OperationState } from '@/operation-state/operation-state.entity';
import { OperationStateService } from '@/operation-state/operation-state.service';

@Module({
imports: [TypeOrmModule.forFeature([OperationState])],
controllers: [],
providers: [OperationStateService],
exports: [OperationStateService],
})
export class OperationStateModule {}
23 changes: 23 additions & 0 deletions src/operation-state/operation-state.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Injectable } from '@nestjs/common';
import { Repository } from 'typeorm';
import { OperationState } from '@/operation-state/operation-state.entity';
import { InjectRepository } from '@nestjs/typeorm';

@Injectable()
export class OperationStateService {
constructor(
@InjectRepository(OperationState)
private readonly operationStateRepository: Repository<OperationState>,
) {}

async getOperationState(id: string): Promise<OperationState> {
return this.operationStateRepository.findOneBy({ id: id });
}

async setOperationState(id: string, state: any): Promise<OperationState> {
const operationState = new OperationState();
operationState.id = id;
operationState.state = state;
return this.operationStateRepository.save(operationState);
}
}

0 comments on commit 624137d

Please sign in to comment.