Skip to content

Commit

Permalink
feat: Allowed passing json in schema along with accepting string (#552
Browse files Browse the repository at this point in the history
)
  • Loading branch information
chavda-bhavik authored Apr 26, 2024
2 parents fcb4723 + 1efbf30 commit abf562e
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { SchemaDto } from 'app/common/dtos/Schema.dto';

@Injectable()
export class ValidRequest {
constructor(private projectRepository: ProjectRepository, private templateRepository: TemplateRepository) {}
constructor(
private projectRepository: ProjectRepository,
private templateRepository: TemplateRepository
) {}

async execute(command: ValidRequestCommand): Promise<{ success: boolean }> {
try {
Expand All @@ -35,14 +38,15 @@ export class ValidRequest {
}

if (command.schema) {
const parsedSchema: SchemaDto = JSON.parse(command.schema);
const parsedSchema: SchemaDto[] =
typeof command.schema === 'string' ? JSON.parse(command.schema) : command.schema;

const errors: string[] = [];
if (!Array.isArray(parsedSchema)) {
throw new DocumentNotFoundException(
'Schema',
command.schema,
'Invalid schema input. An array of objects is expected.'
'Invalid schema input. An array of schema object columns is expected.'
);
}

Expand Down

0 comments on commit abf562e

Please sign in to comment.