import { ValidationSchemas } from '~/domain'; import { IGetSchema } from '~/infra/joi/protocols'; export class JoiInitNestedSchema implements IGetSchema.Any { private all: IGetSchema.All = {} as any; public setup = (model: IGetSchema.All): IGetSchema.All => { this.all = model; return this.all; }; public getJoiSchema = ( type: T, rules: ValidationSchemas.Rules ): IGetSchema.ResultSchema => { const getSchema: any = this.all[type]; if (!getSchema) { throw new Error(`GetSchema for [ ${type} ] was not set`); } return getSchema.getSchema(rules); }; }