Skip to content

Commit

Permalink
feat: health professional indexer (#255)
Browse files Browse the repository at this point in the history
* health professional indexer

* update indexer module and route
  • Loading branch information
rubenkristian authored Jan 4, 2023
1 parent afef91f commit 8e87af6
Show file tree
Hide file tree
Showing 23 changed files with 427 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { AvailabilityStatus } from '@indexer/models/availability-status';
import { BlockMetaData } from '../../../../models/block-meta-data';

export class HealthProfessionalAvailabilityStatusCommandIndexer {
availabilityStatus: AvailabilityStatus;
accountId: string;
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) {
this.accountId = data[0].toString();
this.availabilityStatus = data[1].toString() as AvailabilityStatus;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Injectable } from '@nestjs/common';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { ElasticsearchService } from '@nestjs/elasticsearch';
import { HealthProfessionalAvailabilityStatusCommandIndexer } from './health-professional-availability-status-updated.command';

@Injectable()
@CommandHandler(HealthProfessionalAvailabilityStatusCommandIndexer)
export class HealthProfessionalAvailabilityStatusHandler
implements
ICommandHandler<HealthProfessionalAvailabilityStatusCommandIndexer>
{
constructor(private readonly elasticsearchService: ElasticsearchService) {}

async execute(
command: HealthProfessionalAvailabilityStatusCommandIndexer,
): Promise<any> {
const { accountId, availabilityStatus, blockMetaData } = command;

await this.elasticsearchService.update({
id: accountId,
index: 'health-professional',
refresh: 'wait_for',
body: {
doc: {
availability_status: availabilityStatus,
blockMetaData: blockMetaData,
},
},
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HealthProfessionalInfo } from '@indexer/models/health-professional/info';
import { BlockMetaData } from '../../../../models/block-meta-data';

export class HealthProfessionalInfoUpdatedCommandIndexer {
healthProfessionalInfo: HealthProfessionalInfo;
accountId: string;
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) {
this.accountId = data[0].toString();
this.healthProfessionalInfo = new HealthProfessionalInfo(data[1]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Injectable } from '@nestjs/common';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { ElasticsearchService } from '@nestjs/elasticsearch';
import { HealthProfessionalInfoUpdatedCommandIndexer } from './health-professional-info-updated.command';

@Injectable()
@CommandHandler(HealthProfessionalInfoUpdatedCommandIndexer)
export class HealthProfessionalInfoUpdatedHandler
implements ICommandHandler<HealthProfessionalInfoUpdatedCommandIndexer>
{
constructor(private readonly elasticsearchService: ElasticsearchService) {}

async execute(
command: HealthProfessionalInfoUpdatedCommandIndexer,
): Promise<any> {
const { accountId, healthProfessionalInfo, blockMetaData } = command;

await this.elasticsearchService.update({
id: accountId,
index: 'health-professional',
refresh: 'wait_for',
body: {
doc: {
info: {
...healthProfessionalInfo,
},
blockMetaData: blockMetaData,
},
},
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { HealthProfessional } from '@indexer/models/health-professional';
import { BlockMetaData } from '../../../../models/block-meta-data';

export class HealthProfessionalRegisteredCommandIndexer {
healthProfessional: HealthProfessional;
accountId: string;
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) {
this.accountId = data[0].toString();
this.healthProfessional = new HealthProfessional(data[1]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Injectable } from '@nestjs/common';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { ElasticsearchService } from '@nestjs/elasticsearch';
import { HealthProfessionalRegisteredCommandIndexer } from './health-professional-registered.command';

@Injectable()
@CommandHandler(HealthProfessionalRegisteredCommandIndexer)
export class HealthProfessionalRegisteredHandler
implements ICommandHandler<HealthProfessionalRegisteredCommandIndexer>
{
constructor(private readonly elasticsearchService: ElasticsearchService) {}

async execute(
command: HealthProfessionalRegisteredCommandIndexer,
): Promise<any> {
const { accountId, healthProfessional, blockMetaData } = command;

await this.elasticsearchService.create({
id: accountId,
index: 'health-professional',
refresh: 'wait_for',
body: {
...healthProfessional,
blockMetaData: blockMetaData,
},
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { BlockMetaData } from '../../../../models/block-meta-data';

export class HealthProfessionalStakedCommandIndexer {
balance: string;
accountId: string;
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) {
this.accountId = data[0].toString();
this.balance = data[1].toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { StakeStatus } from '@indexer/models/stake-status';
import { Injectable } from '@nestjs/common';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { ElasticsearchService } from '@nestjs/elasticsearch';
import { HealthProfessionalStakedCommandIndexer } from './health-professional-staked.command';

@Injectable()
@CommandHandler(HealthProfessionalStakedCommandIndexer)
export class HealthProfessionalStakedHandler
implements ICommandHandler<HealthProfessionalStakedCommandIndexer>
{
constructor(private readonly elasticsearchService: ElasticsearchService) {}

async execute(command: HealthProfessionalStakedCommandIndexer): Promise<any> {
const { accountId, balance, blockMetaData } = command;

await this.elasticsearchService.create({
id: accountId,
index: 'health-professional',
refresh: 'wait_for',
body: {
stake_amount: balance,
stake_status: StakeStatus.Staked,
blockMetaData: blockMetaData,
},
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { HealthProfessional } from '@indexer/models/health-professional';
import { BlockMetaData } from '../../../../models/block-meta-data';

export class HealthProfessionalUnregisteredCommandIndexer {
accountId: string;
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) {
this.accountId = data[0].toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Injectable } from '@nestjs/common';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { ElasticsearchService } from '@nestjs/elasticsearch';
import { HealthProfessionalUnregisteredCommandIndexer } from './health-professional-unregistered.command';

@Injectable()
@CommandHandler(HealthProfessionalUnregisteredCommandIndexer)
export class HealthProfessionalUnregisteredHandler
implements ICommandHandler<HealthProfessionalUnregisteredCommandIndexer>
{
constructor(private readonly elasticsearchService: ElasticsearchService) {}

async execute(
command: HealthProfessionalUnregisteredCommandIndexer,
): Promise<any> {
const { accountId } = command;

await this.elasticsearchService.delete({
id: accountId,
index: 'health-professional',
refresh: 'wait_for',
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { BlockMetaData } from '../../../../models/block-meta-data';

export class HealthProfessionalUnstakedAmountCommandIndexer {
balance: string;
accountId: string;
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) {
this.accountId = data[0].toString();
this.balance = data[1].toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { StakeStatus } from '@indexer/models/stake-status';
import { Injectable } from '@nestjs/common';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { ElasticsearchService } from '@nestjs/elasticsearch';
import { HealthProfessionalUnstakedAmountCommandIndexer } from './health-professional-unstaked-amount.command';

@Injectable()
@CommandHandler(HealthProfessionalUnstakedAmountCommandIndexer)
export class HealthProfessionalUnstakedAmountHandler
implements ICommandHandler<HealthProfessionalUnstakedAmountCommandIndexer>
{
constructor(private readonly elasticsearchService: ElasticsearchService) {}

async execute(
command: HealthProfessionalUnstakedAmountCommandIndexer,
): Promise<any> {
const { accountId, balance, blockMetaData } = command;

await this.elasticsearchService.create({
id: accountId,
index: 'health-professional',
refresh: 'wait_for',
body: {
stake_amount: balance,
stake_status: StakeStatus.Unstaked,
blockMetaData: blockMetaData,
},
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { BlockMetaData } from '../../../../models/block-meta-data';

export class HealthProfessionalUnstakedCommandIndexer {
accountId: string;
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) {
this.accountId = data[0].toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { StakeStatus } from '@indexer/models/stake-status';
import { Injectable } from '@nestjs/common';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { ElasticsearchService } from '@nestjs/elasticsearch';
import { HealthProfessionalUnstakedCommandIndexer } from './health-professional-unstaked.command';

@Injectable()
@CommandHandler(HealthProfessionalUnstakedCommandIndexer)
export class HealthProfessionalUnstakedHandler
implements ICommandHandler<HealthProfessionalUnstakedCommandIndexer>
{
constructor(private readonly elasticsearchService: ElasticsearchService) {}

async execute(
command: HealthProfessionalUnstakedCommandIndexer,
): Promise<any> {
const { accountId, blockMetaData } = command;

await this.elasticsearchService.create({
id: accountId,
index: 'health-professional',
refresh: 'wait_for',
body: {
stake_status: StakeStatus.Unstaked,
blockMetaData: blockMetaData,
},
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { VerificationStatus } from '@indexer/models/verification-status';
import { BlockMetaData } from '../../../../models/block-meta-data';

export class HealthProfessionalVerificationStatusCommandIndexer {
verificationStatus: VerificationStatus;
accountId: string;
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) {
this.accountId = data[0].toString();
this.verificationStatus = data[1].toString() as VerificationStatus;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Injectable } from '@nestjs/common';
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
import { ElasticsearchService } from '@nestjs/elasticsearch';
import { HealthProfessionalVerificationStatusCommandIndexer } from './health-professional-verification-status-updated.command';

@Injectable()
@CommandHandler(HealthProfessionalVerificationStatusCommandIndexer)
export class HealthProfessionalVerificationStatusHandler
implements
ICommandHandler<HealthProfessionalVerificationStatusCommandIndexer>
{
constructor(private readonly elasticsearchService: ElasticsearchService) {}

async execute(
command: HealthProfessionalVerificationStatusCommandIndexer,
): Promise<any> {
const { accountId, verificationStatus, blockMetaData } = command;

await this.elasticsearchService.update({
id: accountId,
index: 'health-professional',
refresh: 'wait_for',
body: {
doc: {
availability_status: verificationStatus,
blockMetaData: blockMetaData,
},
},
});
}
}
28 changes: 28 additions & 0 deletions src/indexer/events/health-professional/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export * from './commands/health-professional-availability-status-updated/health-professional-availability-status-updated.command';
export * from './commands/health-professional-info-updated/health-professional-info-updated.command';
export * from './commands/health-professional-registered/health-professional-registered.command';
export * from './commands/health-professional-staked/health-professional-staked.command';
export * from './commands/health-professional-unregistered/health-professional-unregistered.command';
export * from './commands/health-professional-unstaked/health-professional-unstaked.command';
export * from './commands/health-professional-unstaked-amount/health-professional-unstaked-amount.command';
export * from './commands/health-professional-verification-status-updated/health-professional-verification-status-updated.command';

import { HealthProfessionalAvailabilityStatusHandler } from './commands/health-professional-availability-status-updated/health-professional-availability-status-updated.handler';
import { HealthProfessionalInfoUpdatedHandler } from './commands/health-professional-info-updated/health-professional-info-updated.handler';
import { HealthProfessionalRegisteredHandler } from './commands/health-professional-registered/health-professional-registered.handler';
import { HealthProfessionalStakedHandler } from './commands/health-professional-staked/health-professional-staked.handler';
import { HealthProfessionalUnregisteredHandler } from './commands/health-professional-unregistered/health-professional-unregistered.handler';
import { HealthProfessionalUnstakedHandler } from './commands/health-professional-unstaked/health-professional-unstaked.handler';
import { HealthProfessionalUnstakedAmountHandler } from './commands/health-professional-unstaked-amount/health-professional-unstaked-amount.handler';
import { HealthProfessionalVerificationStatusHandler } from './commands/health-professional-verification-status-updated/health-professional-verification-status-updated.handler';

export const HealthProfessionalHandlers = [
HealthProfessionalAvailabilityStatusHandler,
HealthProfessionalInfoUpdatedHandler,
HealthProfessionalRegisteredHandler,
HealthProfessionalStakedHandler,
HealthProfessionalUnregisteredHandler,
HealthProfessionalUnstakedHandler,
HealthProfessionalUnstakedAmountHandler,
HealthProfessionalVerificationStatusHandler,
];
Empty file.
1 change: 1 addition & 0 deletions src/indexer/indexer.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ export class IndexerHandler
'menstrual-calendar',
'menstrual-cycle-log',
'menstrual-subscription',
'health-professional',
];

for (const i of indices) {
Expand Down
2 changes: 2 additions & 0 deletions src/indexer/indexer.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { GeneticAnalysisCommandHandlers } from './events/genetic-analysis';
import { GeneticAnalysisOrderCommandHandlers } from './events/genetic-analysis-order';
import { MenstrualCalendarCommandHandlers } from './events/menstrual-calendar';
import { MenstrualSubscriptionCommandHandlers } from './events/menstrual-subscription';
import { HealthProfessionalHandlers } from './events/health-professional';

// eslint-disable-next-line @typescript-eslint/no-var-requires
require('dotenv').config();
Expand All @@ -41,6 +42,7 @@ require('dotenv').config();
...GeneticAnalysisOrderCommandHandlers,
...MenstrualCalendarCommandHandlers,
...MenstrualSubscriptionCommandHandlers,
...HealthProfessionalHandlers,
],
})
export class IndexerModule {}
Loading

0 comments on commit 8e87af6

Please sign in to comment.