Skip to content

Commit

Permalink
Simplify logic and improve readability.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariy Miseldzhani committed Dec 21, 2024
1 parent 346d787 commit fc420ad
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 274 deletions.
17 changes: 1 addition & 16 deletions api-gateway/src/api/service/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1740,19 +1740,6 @@ export class ContractsApi {
required: true,
example: '0.0.0000000',
})
@ApiQuery({
name: 'pageIndex',
type: Number,
description: 'The number of pages to skip before starting to collect the result set',
required: false,
example: 0,
})
@ApiQuery({
name: 'pageSize',
type: Number,
description: 'The numbers of items to return',
example: 20,
})
@ApiOkResponse({
description: 'Successful operation.',
isArray: true,
Expand All @@ -1774,13 +1761,11 @@ export class ContractsApi {
@AuthUser() user: IAuthUser,
@Response() res: any,
@Query('contractTopicId') contractTopicId: string,
@Query('pageIndex') pageIndex?: number,
@Query('pageSize') pageSize?: number,
): Promise<any[]> {
try {
const owner = new EntityOwner(user);
const guardians = new Guardians();
const [vcs, count] = await guardians.getRetireVCsFromIndexer(owner, contractTopicId, pageIndex, pageSize);
const [vcs, count] = await guardians.getRetireVCsFromIndexer(owner, contractTopicId);
return res.header('X-Total-Count', count).send(vcs);
} catch (error) {
await InternalException(error, this.logger);
Expand Down
11 changes: 3 additions & 8 deletions api-gateway/src/helpers/guardians.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1851,21 +1851,16 @@ export class Guardians extends NatsService {
/**
* Get retire VCs from Indexer
* @param owner
* @param pageIndex
* @param pageSize
* @param contractTopicId
* @returns Retire VCs from Indexer and count
*/
public async getRetireVCsFromIndexer(
owner: IOwner,
contractTopicId: string,
pageIndex?: any,
pageSize?: any
contractTopicId: string
): Promise<[IRetirementMessage[], number]> {
return await this.sendMessage(ContractAPI.GET_RETIRE_VCS_FROM_INDEXER, {
owner,
contractTopicId,
pageIndex,
pageSize,
contractTopicId
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ export class MessagesReportBlockComponent implements OnInit {
);
private lines!: Line[] | null;

gridSize: number = 0;

mintTokenId: string;
mintTokenSerials: string[] = [];
groupedByContractRetirements: any = [];
indexerAvailable: boolean = false;
retirementMessages: any[] = [];

constructor(
private element: ElementRef,
private fb: UntypedFormBuilder,
Expand Down Expand Up @@ -374,16 +382,13 @@ export class MessagesReportBlockComponent implements OnInit {
}, 100);
}


gridSize: number = 0;

mintTokenId: string;
mintTokenSerials: string[] = [];
groupedByContractRetirements: any = [];
indexerAvailable: boolean = false;
retirementMessages: any[] = [];

private loadRetirementMessages() {
this._messages2.forEach(message => {
if (message.__ifMintMessage) {
this.mintTokenId = message.__tokenId;
}
});

this.contractService
.getContracts({
type: ContractType.RETIRE
Expand Down Expand Up @@ -415,25 +420,6 @@ export class MessagesReportBlockComponent implements OnInit {
this.loading = false;
const retires = results.map((item: any) => item.body)

// const tokenRetires = retires.map((retirements: IRetirementMessage[]) => {
// const ret = retirements.filter((item: IRetirementMessage) => item.documents[0].credentialSubject.some((subject: any) =>
// subject.tokens.some((token: any) =>
// token.tokenId === this.mintTokenId
// && token.serials.some((serial: string) => this.mintTokenSerials.includes(serial)
// ))));
// return ret
// });

// this.groupedByContractRetirements = Array.from(
// new Map(allRetireMessages
// .map((item: any) => [item.documents[0].credentialSubject[0].contractId, []])
// )).map(([contractId, documents]) => ({
// contractId,
// selectedItemIndex: 0,
// __ifRetireMessage: true,
// documents: allRetireMessages.filter((item: any) => item.documents[0].credentialSubject[0].contractId === contractId)
// }))

let allRetireMessages: any = [];
retires.forEach((retirements: any[]) => {
retirements.forEach((item: any) => {
Expand Down Expand Up @@ -465,6 +451,7 @@ export class MessagesReportBlockComponent implements OnInit {
lastOrderMessageTopic2++;
});

// Todo: Need filtration by serials and token user
this.retirementMessages = [...allRetireMessages];

this._gridTemplateColumns1 = 'repeat(' + (this.gridSize + this.retirementMessages.length + 1) + ', 230px)';
Expand Down Expand Up @@ -498,12 +485,6 @@ export class MessagesReportBlockComponent implements OnInit {
}
}

this._messages2.forEach(message => {
if (message.__ifMintMessage) {
this.mintTokenId = message.__tokenId;
}
});

this.gridSize = 0;
this._messages2.sort((a, b) => a.__order > b.__order ? 1 : -1);
for (let index = 0; index < this._messages2.length; index++) {
Expand Down Expand Up @@ -925,7 +906,7 @@ export class MessagesReportBlockComponent implements OnInit {
styleClass: 'guardian-dialog',
data: {
row: null,
document: message.document || message.documents[0],
document: message.document || message.documents?.[0],
title: 'VC Document',
type: 'VC',
viewDocument: true,
Expand Down
Loading

0 comments on commit fc420ad

Please sign in to comment.