Skip to content

Commit

Permalink
chore: make validate api adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
MSzalowski committed Jul 31, 2024
1 parent 2373433 commit 227e4ec
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 25 deletions.
1 change: 0 additions & 1 deletion govtool/frontend/src/hooks/forms/useVoteContextForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ export const useVoteContextForm = (
const result = await validateMetadata({
hash: localHash,
url,
noStandard: true,
});

if (result.status) {
Expand Down
1 change: 0 additions & 1 deletion govtool/frontend/src/models/metadataValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ export type MetadataValidationDTO = {
url: string;
hash: string;
standard?: MetadataStandard;
noStandard?: boolean;
};
24 changes: 24 additions & 0 deletions govtool/metadata-validation/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,36 @@ import { ValidateMetadataDTO } from '@dto';
import { ValidateMetadataResult } from '@types';

import { AppService } from './app.service';
import { ApiBody, ApiResponse } from '@nestjs/swagger';

@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}

@Post('validate')
@ApiBody({
schema: {
type: 'object',
properties: {
url: { type: 'string' },
hash: { type: 'string' },
standard: { type: 'string' },
},
required: ['url', 'hash'],
},
})
@ApiResponse({
status: 200,
description: 'Validation result',
schema: {
type: 'object',
properties: {
valid: { type: 'boolean' },
status: { type: 'string' },
metadata: { type: 'object' },
},
},
})
validateMetadata(
@Body() validateMetadataDto: ValidateMetadataDTO,
): Promise<ValidateMetadataResult> {
Expand Down
13 changes: 3 additions & 10 deletions govtool/metadata-validation/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as blake from 'blakejs';
import { ValidateMetadataDTO } from '@dto';
import { LoggerMessage, MetadataValidationStatus } from '@enums';
import { validateMetadataStandard, parseMetadata } from '@utils';
import { MetadataStandard, ValidateMetadataResult } from '@types';
import { ValidateMetadataResult } from '@types';

@Injectable()
export class AppService {
Expand All @@ -15,9 +15,7 @@ export class AppService {
async validateMetadata({
hash,
url,
standard = MetadataStandard.CIP108,
// workaround property to not break the haskell backend
noStandard = false,
standard,
}: ValidateMetadataDTO): Promise<ValidateMetadataResult> {
let status: MetadataValidationStatus;
let metadata: any;
Expand All @@ -30,13 +28,8 @@ export class AppService {
),
);

Logger.debug(LoggerMessage.METADATA_DATA, data);

if (standard && !noStandard) {
if (standard) {
await validateMetadataStandard(data, standard);
}

if (!noStandard) {
metadata = parseMetadata(data.body, standard);
}

Expand Down
2 changes: 0 additions & 2 deletions govtool/metadata-validation/src/dto/validateMetadata.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,4 @@ export class ValidateMetadataDTO {
url: string;

standard?: MetadataStandard;

noStandard?: boolean;
}
9 changes: 4 additions & 5 deletions govtool/metadata-validation/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
cors: true,
logger: ['debug', 'error', 'log'],
logger: ['error', 'log'],
});

const config = new DocumentBuilder()
.setTitle('Submission Tool')
.setDescription('The Submission Tool API description')
.setVersion('1.0')
.addTag('submission')
.setTitle('Metadata Validation Tool')
.setDescription('The Metadata Validation Tool API description')
.setVersion('1.0.11')
.build();

const document = SwaggerModule.createDocument(app, config);
Expand Down
7 changes: 1 addition & 6 deletions govtool/metadata-validation/src/utils/parseMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ export const parseMetadata = (
);
}
}
Logger.debug(LoggerMessage.PARSED_METADATA_BODY, parsedMetadata, {
standard,
});

return parsedMetadata;

case MetadataStandard.CIPQQQ:
Expand All @@ -38,9 +36,6 @@ export const parseMetadata = (
);
}
}
Logger.debug(LoggerMessage.PARSED_METADATA_BODY, parsedMetadata, {
standard,
});
return parsedMetadata;
default:
Logger.warn(LoggerMessage.CANNOT_PARSE_METADATA_BODY, { standard });
Expand Down

0 comments on commit 227e4ec

Please sign in to comment.