-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: second opinion indexer handler (#256)
second opinion indexer handler
- Loading branch information
1 parent
8e87af6
commit 30a6067
Showing
21 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/indexer/events/opinion-requestor/commands/opinion-requested/opinion-requested.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { BlockMetaData } from '../../../../models/block-meta-data'; | ||
import { OpinionRequestor } from '@indexer/models/opinion-requestor'; | ||
|
||
export class OpinionRequestedCommandIndexer { | ||
accountId: string; | ||
opinionRequestor: OpinionRequestor; | ||
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) { | ||
this.accountId = data[0].toString(); | ||
this.opinionRequestor = new OpinionRequestor(data[1].toHuman()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/indexer/events/opinion-requestor/commands/opinion-requested/opinion-requested.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { ElasticsearchService } from '@nestjs/elasticsearch'; | ||
import { OpinionRequestedCommandIndexer } from './opinion-requested.command'; | ||
|
||
@Injectable() | ||
@CommandHandler(OpinionRequestedCommandIndexer) | ||
export class OpinionRequestedHandler | ||
implements ICommandHandler<OpinionRequestedCommandIndexer> | ||
{ | ||
constructor(private readonly elasticsearchService: ElasticsearchService) {} | ||
|
||
async execute(command: OpinionRequestedCommandIndexer) { | ||
const { opinionRequestor, blockMetaData } = command; | ||
|
||
await this.elasticsearchService.create({ | ||
index: 'opinion-requestor', | ||
id: opinionRequestor.id, | ||
refresh: 'wait_for', | ||
body: { | ||
...opinionRequestor, | ||
blockMetaData: blockMetaData, | ||
}, | ||
}); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...questor/commands/opinion-requestor-info-updated/opinion-requestor-info-updated.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { BlockMetaData } from '../../../../models/block-meta-data'; | ||
import { OpinionRequestor } from '@indexer/models/opinion-requestor'; | ||
|
||
export class OpinionRequestorInfoUpdatedCommandIndexer { | ||
accountId: string; | ||
opinionRequestor: OpinionRequestor; | ||
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) { | ||
this.accountId = data[0].toString(); | ||
this.opinionRequestor = new OpinionRequestor(data[1].toHuman()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...questor/commands/opinion-requestor-info-updated/opinion-requestor-info-updated.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { ElasticsearchService } from '@nestjs/elasticsearch'; | ||
import { OpinionRequestorInfoUpdatedCommandIndexer } from './opinion-requestor-info-updated.command'; | ||
|
||
@Injectable() | ||
@CommandHandler(OpinionRequestorInfoUpdatedCommandIndexer) | ||
export class OpinionRequestorInfoUpdatedHandler | ||
implements ICommandHandler<OpinionRequestorInfoUpdatedCommandIndexer> | ||
{ | ||
constructor(private readonly elasticsearchService: ElasticsearchService) {} | ||
|
||
async execute(command: OpinionRequestorInfoUpdatedCommandIndexer) { | ||
const { opinionRequestor, blockMetaData } = command; | ||
|
||
await this.elasticsearchService.update({ | ||
index: 'opinion-requestor', | ||
id: opinionRequestor.id, | ||
refresh: 'wait_for', | ||
body: { | ||
doc: { | ||
blockMetaData: blockMetaData, | ||
}, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export * from './commands/opinion-requested/opinion-requested.command'; | ||
export * from './commands/opinion-requestor-info-updated/opinion-requestor-info-updated.command'; | ||
|
||
import { OpinionRequestedHandler } from './commands/opinion-requested/opinion-requested.handler'; | ||
import { OpinionRequestorInfoUpdatedHandler } from './commands/opinion-requestor-info-updated/opinion-requestor-info-updated.handler'; | ||
|
||
export const OpinionRequestorCommandHandlers = [ | ||
OpinionRequestedHandler, | ||
OpinionRequestorInfoUpdatedHandler, | ||
]; |
11 changes: 11 additions & 0 deletions
11
src/indexer/events/opinion/commands/opinion-added/opinion-added.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { BlockMetaData } from '../../../../models/block-meta-data'; | ||
import { Opinion } from '@indexer/models/opinion'; | ||
|
||
export class OpinionAddedCommandIndexer { | ||
accountId: string; | ||
opinion: Opinion; | ||
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) { | ||
this.accountId = data[0].toString(); | ||
this.opinion = new Opinion(data[1].toHuman()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/indexer/events/opinion/commands/opinion-added/opinion-added.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { ElasticsearchService } from '@nestjs/elasticsearch'; | ||
import { OpinionAddedCommandIndexer } from './opinion-added.command'; | ||
|
||
@Injectable() | ||
@CommandHandler(OpinionAddedCommandIndexer) | ||
export class OpinionAddedHandler | ||
implements ICommandHandler<OpinionAddedCommandIndexer> | ||
{ | ||
constructor(private readonly elasticsearchService: ElasticsearchService) {} | ||
|
||
async execute(command: OpinionAddedCommandIndexer) { | ||
const { opinion, blockMetaData } = command; | ||
|
||
await this.elasticsearchService.create({ | ||
index: 'opinion', | ||
id: opinion.id, | ||
refresh: 'wait_for', | ||
body: { | ||
...opinion, | ||
blockMetaData: blockMetaData, | ||
}, | ||
}); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/indexer/events/opinion/commands/opinion-removed/opinion-removed.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { BlockMetaData } from '../../../../models/block-meta-data'; | ||
|
||
export class OpinionRemovedCommandIndexer { | ||
accountId: string; | ||
hash: string; | ||
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) { | ||
this.accountId = data[0].toString(); | ||
this.hash = data[1].toString(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/indexer/events/opinion/commands/opinion-removed/opinion-removed.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { ElasticsearchService } from '@nestjs/elasticsearch'; | ||
import { OpinionRemovedCommandIndexer } from './opinion-removed.command'; | ||
|
||
@Injectable() | ||
@CommandHandler(OpinionRemovedCommandIndexer) | ||
export class OpinionRemovedHandler | ||
implements ICommandHandler<OpinionRemovedCommandIndexer> | ||
{ | ||
constructor(private readonly elasticsearchService: ElasticsearchService) {} | ||
|
||
async execute(command: OpinionRemovedCommandIndexer) { | ||
const { hash } = command; | ||
|
||
await this.elasticsearchService.delete({ | ||
index: 'opinion', | ||
id: hash, | ||
}); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/indexer/events/opinion/commands/opinion-status-updated/opinion-status-updated.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { BlockMetaData } from '../../../../models/block-meta-data'; | ||
|
||
export class OpinionStatusUpdatedCommandIndexer { | ||
accountId: string; | ||
hash: string; | ||
status: string; | ||
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) { | ||
this.accountId = data[0].toString(); | ||
this.hash = data[1].toString(); | ||
this.status = data[2].toString(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/indexer/events/opinion/commands/opinion-status-updated/opinion-status-updated.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { OpinionStatusUpdatedCommandIndexer } from './opinion-status-updated.command'; | ||
|
||
@Injectable() | ||
@CommandHandler(OpinionStatusUpdatedCommandIndexer) | ||
export class OpinionStatusUpdatedHandler | ||
implements ICommandHandler<OpinionStatusUpdatedCommandIndexer> | ||
{ | ||
constructor(private readonly elasticsearchService: ElasticsearchService) {} | ||
|
||
async execute(command: OpinionStatusUpdatedCommandIndexer) { | ||
const { hash, status, blockMetaData } = command; | ||
|
||
await this.elasticsearchService.update({ | ||
index: 'opinion', | ||
id: hash, | ||
refresh: 'wait_for', | ||
body: { | ||
doc: { | ||
status: status, | ||
blockMetaData: blockMetaData, | ||
}, | ||
}, | ||
}); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/indexer/events/opinion/commands/opinion-updated/opinion-updated.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { BlockMetaData } from '../../../../models/block-meta-data'; | ||
import { Opinion } from '@indexer/models/opinion'; | ||
|
||
export class OpinionUpdatedCommandIndexer { | ||
accountId: string; | ||
opinion: Opinion; | ||
constructor(data: Array<any>, public readonly blockMetaData: BlockMetaData) { | ||
this.accountId = data[0].toString(); | ||
this.opinion = new Opinion(data[1].toHuman()); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/indexer/events/opinion/commands/opinion-updated/opinion-updated.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { ElasticsearchService } from '@nestjs/elasticsearch'; | ||
import { OpinionUpdatedCommandIndexer } from './opinion-updated.command'; | ||
|
||
@Injectable() | ||
@CommandHandler(OpinionUpdatedCommandIndexer) | ||
export class OpinionUpdatedHandler | ||
implements ICommandHandler<OpinionUpdatedCommandIndexer> | ||
{ | ||
constructor(private readonly elasticsearchService: ElasticsearchService) {} | ||
|
||
async execute(command: OpinionUpdatedCommandIndexer) { | ||
const { | ||
opinion: { info, id }, | ||
blockMetaData, | ||
} = command; | ||
|
||
await this.elasticsearchService.update({ | ||
index: 'opinion', | ||
id: id, | ||
refresh: 'wait_for', | ||
body: { | ||
doc: { | ||
info: { | ||
...info, | ||
}, | ||
blockMetaData: blockMetaData, | ||
}, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export * from './commands/opinion-added/opinion-added.command'; | ||
export * from './commands/opinion-removed/opinion-removed.command'; | ||
export * from './commands/opinion-status-updated/opinion-status-updated.command'; | ||
export * from './commands/opinion-updated/opinion-updated.command'; | ||
|
||
import { OpinionAddedHandler } from './commands/opinion-added/opinion-added.handler'; | ||
import { OpinionRemovedHandler } from './commands/opinion-removed/opinion-removed.handler'; | ||
import { OpinionStatusUpdatedHandler } from './commands/opinion-status-updated/opinion-status-updated.handler'; | ||
import { OpinionUpdatedHandler } from './commands/opinion-updated/opinion-updated.handler'; | ||
|
||
export const OpinionCommandHandlers = [ | ||
OpinionAddedHandler, | ||
OpinionRemovedHandler, | ||
OpinionStatusUpdatedHandler, | ||
OpinionUpdatedHandler, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { RequestorInfo } from './info'; | ||
|
||
export class OpinionRequestor { | ||
constructor(data: any) { | ||
this.id = data.id; | ||
this.account_id = data.account_id; | ||
this.info = new RequestorInfo(data.info); | ||
this.created_at = data.created_at | ||
? new Date(Number(String(data.created_at).split(',').join(''))) | ||
: null; | ||
this.updated_at = data.updated_at | ||
? new Date(Number(String(data.updated_at).split(',').join(''))) | ||
: null; | ||
} | ||
|
||
id: string; | ||
account_id: string; | ||
info: RequestorInfo; | ||
created_at: Date; | ||
updated_at: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
export class RequestorInfo { | ||
constructor(data: any) { | ||
this.category = data.category; | ||
this.description = data.description; | ||
this.genetic_data_ids = data.genetic_data_ids; | ||
this.opinion_ids = data.opinion_ids; | ||
this.myriad_url = data.myriad_url; | ||
} | ||
|
||
category: string; | ||
description: string; | ||
genetic_data_ids: string[]; | ||
opinion_ids: string[]; | ||
myriad_url: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { OpinionInfo } from './info'; | ||
|
||
export class Opinion { | ||
constructor(data: any) { | ||
this.id = data.id; | ||
this.requestor_id = data.requestor_id; | ||
this.professional_id = data.professional_id; | ||
this.info = new OpinionInfo(data.info); | ||
this.status = data.status; | ||
this.created_at = data.created_at; | ||
} | ||
|
||
id: string; | ||
requestor_id: string; | ||
professional_id: string; | ||
info: OpinionInfo; | ||
status: string; | ||
created_at: Date; | ||
} |
Oops, something went wrong.