Skip to content

Commit

Permalink
Fixes in validators, fixes in parsing Oracle Discovery DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
macnablocky committed Jun 27, 2024
1 parent 7e66275 commit 68953ae
Show file tree
Hide file tree
Showing 6 changed files with 2,327 additions and 2,603 deletions.
4,901 changes: 2,304 additions & 2,597 deletions packages/apps/dashboard/admin/yarn.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { Transform } from 'class-transformer';
import { jwtDecode } from 'jwt-decode';
import { JwtUserData } from '../utils/jwt-token.model';

Expand All @@ -22,3 +23,12 @@ export const JwtPayload = createParamDecorator(
}
},
);

export function TransformToArray() {
return Transform(({ value }) => {
if (!value) {
return undefined;
}
return Array.isArray(value) ? value : [value];
});
}
3 changes: 2 additions & 1 deletion packages/apps/human-app/server/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { ConfigService } from '@nestjs/config';
import { Logger } from '@nestjs/common';
import { Logger, ValidationPipe } from '@nestjs/common';
import { EnvironmentConfigService } from './common/config/environment-config.service';
import { GlobalExceptionsFilter } from './common/filter/global-exceptions.filter';

Expand Down Expand Up @@ -31,6 +31,7 @@ async function bootstrap() {
const port = envConfigService.port;

app.useGlobalFilters(new GlobalExceptionsFilter());
app.useGlobalPipes(new ValidationPipe({ transform: true }));

await app.listen(port, host, async () => {
logger.log(`Human APP server is running on http://${host}:${port}`);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { IOperator } from '@human-protocol/sdk';
import { AutoMap } from '@automapper/classes';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsString } from 'class-validator';
import { Transform } from 'class-transformer';

export class OracleDiscoveryResponse implements IOperator {
address: string;
Expand All @@ -15,11 +17,12 @@ export class OracleDiscoveryResponse implements IOperator {
}
}
export class OracleDiscoveryDto {
@AutoMap()
@ApiPropertyOptional()
@ApiPropertyOptional({ type: [String], isArray: true })
@Transform(({ value }) => (Array.isArray(value) ? value : Array(value)))
selected_job_types?: string[];
}
export class OracleDiscoveryCommand {
@AutoMap()
@Transform(({ value }) => (Array.isArray(value) ? value : [value]))
selectedJobTypes?: string[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class OracleDiscoveryController {
@ApiOperation({ summary: 'Oracles discovery' })
@UsePipes(new ValidationPipe())
public getOracles(
@Query() dto?: OracleDiscoveryDto,
@Query() dto: OracleDiscoveryDto,
): Promise<OracleDiscoveryResponse[]> {
const command = this.mapper.map(
dto,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export class OracleDiscoveryService {
): Promise<OracleDiscoveryResponse[]> {
const address = this.configService.reputationOracleAddress;
const chainIds = this.configService.chainIdsEnabled;

const filteredOracles = await Promise.all(
chainIds.map(async (chainId) => {
return this.findOraclesByChainId(chainId, address).then((oracles) =>
Expand Down Expand Up @@ -69,18 +68,22 @@ export class OracleDiscoveryService {
!foundOracles ||
foundOracles.length === 0
) {
console.log('DUPA1');
return foundOracles;
}
return foundOracles.filter((oracle) =>
const filteredOracles = foundOracles.filter((oracle) =>
oracle.jobTypes && oracle.jobTypes.length > 0
? this.areJobTypeSetsIntersect(oracle.jobTypes, selectedJobTypes)
: false,
);
return filteredOracles;
}
private areJobTypeSetsIntersect(
oracleJobTypes: string[],
requiredJobTypes: string[],
) {
console.log(requiredJobTypes);
console.log(oracleJobTypes);
return oracleJobTypes.some((job) =>
requiredJobTypes
.map((requiredJob) => requiredJob.toLowerCase())
Expand Down

0 comments on commit 68953ae

Please sign in to comment.