@@ -428,8 +428,8 @@ <h3 id="methods">
428428
429429 < tr >
430430 < td class ="col-md-4 ">
431- < div class ="io-line "> Defined in < a href ="" data-line ="352 "
432- class ="link-to-prism "> src/management/identities/validations/identities.validation.service.ts:352 </ a > </ div >
431+ < div class ="io-line "> Defined in < a href ="" data-line ="353 "
432+ class ="link-to-prism "> src/management/identities/validations/identities.validation.service.ts:353 </ a > </ div >
433433 </ td >
434434 </ tr >
435435
@@ -468,8 +468,8 @@ <h3 id="methods">
468468
469469 < tr >
470470 < td class ="col-md-4 ">
471- < div class ="io-line "> Defined in < a href ="" data-line ="407 "
472- class ="link-to-prism "> src/management/identities/validations/identities.validation.service.ts:407 </ a > </ div >
471+ < div class ="io-line "> Defined in < a href ="" data-line ="408 "
472+ class ="link-to-prism "> src/management/identities/validations/identities.validation.service.ts:408 </ a > </ div >
473473 </ td >
474474 </ tr >
475475
@@ -956,8 +956,8 @@ <h3 id="methods">
956956
957957 < tr >
958958 < td class ="col-md-4 ">
959- < div class ="io-line "> Defined in < a href ="" data-line ="304 "
960- class ="link-to-prism "> src/management/identities/validations/identities.validation.service.ts:304 </ a > </ div >
959+ < div class ="io-line "> Defined in < a href ="" data-line ="305 "
960+ class ="link-to-prism "> src/management/identities/validations/identities.validation.service.ts:305 </ a > </ div >
961961 </ td >
962962 </ tr >
963963
@@ -1071,7 +1071,7 @@ <h3 id="inputs">
10711071 </ tr >
10721072 < tr >
10731073 < td class ="col-md-4 ">
1074- < i > Default value : </ i > < code > new Ajv({allErrors: true })</ code >
1074+ < i > Default value : </ i > < code > new Ajv({ allErrors: true })</ code >
10751075 </ td >
10761076 </ tr >
10771077 < tr >
@@ -1137,32 +1137,32 @@ <h3 id="inputs">
11371137
11381138
11391139 < div class ="tab-pane fade tab-source-code " id ="source ">
1140- < pre class ="line-numbers compodoc-sourcecode "> < code class ="language-typescript "> import {BadRequestException, Injectable, Logger, OnApplicationBootstrap} from '@nestjs/common';
1141- import {parse} from 'yaml';
1142- import {existsSync, readFileSync, readdirSync, writeFileSync} from 'fs';
1143- import {ConfigObjectSchemaDTO} from './_dto/config.dto';
1144- import {diff} from 'radash';
1145- import {AdditionalFieldsPart} from '../_schemas/_parts/additionalFields.part.schema';
1140+ < pre class ="line-numbers compodoc-sourcecode "> < code class ="language-typescript "> import { BadRequestException, Injectable, Logger, OnApplicationBootstrap } from '@nestjs/common';
1141+ import { parse } from 'yaml';
1142+ import { existsSync, readFileSync, readdirSync, writeFileSync } from 'fs';
1143+ import { ConfigObjectSchemaDTO } from './_dto/config.dto';
1144+ import { diff } from 'radash';
1145+ import { AdditionalFieldsPart } from '../_schemas/_parts/additionalFields.part.schema';
11461146import Ajv from 'ajv';
11471147import addFormats from 'ajv-formats';
11481148import validSchema from './_config/validSchema';
11491149import ajvErrors from 'ajv-errors';
1150- import {ValidationConfigException, ValidationSchemaException} from '~/_common/errors/ValidationException';
1151- import {additionalFieldsPartDto} from '../_dto/_parts/additionalFields.dto';
1150+ import { ValidationConfigException, ValidationSchemaException } from '~/_common/errors/ValidationException';
1151+ import { additionalFieldsPartDto } from '../_dto/_parts/additionalFields.dto';
11521152
11531153/**
11541154 * Service responsible for validating identities.
11551155 */
11561156@Injectable()
11571157export class IdentitiesValidationService implements OnApplicationBootstrap {
1158- private ajv: Ajv = new Ajv({allErrors: true });
1158+ private ajv: Ajv = new Ajv({ allErrors: true });
11591159 private validateSchema;
11601160 private logger: Logger;
11611161
11621162 public constructor() {
11631163 addFormats(this.ajv);
11641164 ajvErrors(this.ajv);
1165- this.ajv.addFormat('number',/^\d*$/);
1165+ this.ajv.addFormat('number', /^\d*$/);
11661166 this.validateSchema = this.ajv.compile(validSchema);
11671167 this.logger = new Logger(IdentitiesValidationService.name);
11681168 }
@@ -1232,26 +1232,26 @@ <h3 id="inputs">
12321232 * check objectclasses and add missing keys
12331233 * @param data
12341234 */
1235- public async checkAndCreateObjectClasses(data){
1235+ public async checkAndCreateObjectClasses(data) {
12361236 const objectClasses = data.objectClasses || [];
12371237 const attributes = data.attributes || {};
12381238 const attributesKeys = Object.keys(attributes);
1239- for(const objectclass of objectClasses) {
1240- if (! attributesKeys.includes(objectclass)) {
1241- this.logger.log( objectclass + " attribute not found creating");
1242- await this.createAttributes(objectclass,data);
1239+ for (const objectclass of objectClasses) {
1240+ if (!attributesKeys.includes(objectclass)) {
1241+ this.logger.log(objectclass + " attribute not found creating");
1242+ await this.createAttributes(objectclass, data);
12431243 }
12441244 }
12451245 }
1246- private async createAttributes(key:string,data:any){
1246+ private async createAttributes(key: string, data: any) {
12471247
12481248 // Validate the key to prevent prototype pollution
12491249 if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
12501250 this.logger.error('Invalid key: ' + key);
12511251 throw new BadRequestException('Invalid key: ' + key);
12521252 }
12531253 const path = this.resolveConfigPath(key);
1254- if (path === null){
1254+ if (path === null) {
12551255 this.logger.error('schema for ' + key + ' does not exist');
12561256 throw new BadRequestException('schema for ' + key + ' does not exist');
12571257 }
@@ -1287,7 +1287,7 @@ <h3 id="inputs">
12871287 public async transformAttribute(key: string, attribute: any, data: any) {
12881288
12891289 const path = this.resolveConfigPath(key);
1290- if (path === null){
1290+ if (path === null) {
12911291 this.logger.error('schema for ' + key + ' does not exist');
12921292 throw new BadRequestException('schema for ' + key + ' does not exist');
12931293 }
@@ -1299,42 +1299,42 @@ <h3 id="inputs">
12991299 if (typeof data[key][index] === 'undefined' || data[key][index] === null) {
13001300 data[key][index] = [];
13011301 }
1302- if (!(data[key][index] instanceof Array)){
1303- data[key][index]=[data[key][index]];
1302+ if (!(data[key][index] instanceof Array)) {
1303+ data[key][index] = [data[key][index]];
13041304 }
13051305 if (typeof def['items'] !== 'undefined') {
1306- //test si toutes les valeurs sont du bon type
1307- for(const elems in data[key][index]){
1308- if (typeof data[key][index][elems] !== def['items']['type']){
1309- switch(def['items']['type']){
1310- case 'string':
1311- data[key][index][elems]=String(data[key][index][elems]);
1312- break;
1313- case 'number':
1314- data[key][index][elems]=await this.transformNumber(data[key][index][elems])
1315- break;
1316- }
1306+ //test si toutes les valeurs sont du bon type
1307+ for (const elems in data[key][index]) {
1308+ if (typeof data[key][index][elems] !== def['items']['type']) {
1309+ switch (def['items']['type']) {
1310+ case 'string':
1311+ data[key][index][elems] = String(data[key][index][elems]);
1312+ break;
1313+ case 'number':
1314+ data[key][index][elems] = await this.transformNumber(data[key][index][elems])
1315+ break;
13171316 }
13181317 }
1318+ }
13191319 }
13201320 break;
13211321 case 'number':
13221322 if (typeof data[key][index] === 'undefined' || data[key][index] === null) {
13231323 data[key][index] = 0;
13241324 }
1325- if (typeof data[key][index] !== 'number'){
1325+ if (typeof data[key][index] !== 'number') {
13261326 //on ne convertit pas si la chaine est vide
1327- if (typeof data[key][index] === 'string' && data[key][index] !== ""){
1328- data[key][index]=await this.transformNumber(data[key][index])
1327+ if (typeof data[key][index] === 'string' && data[key][index] !== "") {
1328+ data[key][index] = await this.transformNumber(data[key][index])
13291329 }
13301330 }
13311331 break;
13321332 case 'string':
13331333 if (typeof data[key][index] === 'undefined' || data[key][index] === null) {
13341334 data[key][index] = "";
13351335 }
1336- if (typeof data[key][index] !== 'string'){
1337- data[key][index]=String(data[key][index]);
1336+ if (typeof data[key][index] !== 'string') {
1337+ data[key][index] = String(data[key][index]);
13381338 }
13391339 break;
13401340 }
@@ -1346,12 +1346,12 @@ <h3 id="inputs">
13461346 * @param value
13471347 * @private
13481348 */
1349- private async transformNumber(value){
1350- if (typeof value === 'string'){
1351- const tr=parseFloat(value)
1352- if (! isNaN(tr)){
1349+ private async transformNumber(value) {
1350+ if (typeof value === 'string') {
1351+ const tr = parseFloat(value)
1352+ if (!isNaN(tr)) {
13531353 return tr
1354- }else{
1354+ } else {
13551355 return 0
13561356 }
13571357 }
@@ -1402,15 +1402,16 @@ <h3 id="inputs">
14021402 }
14031403
14041404 // Check for invalid schema
1405+ this.logger.verbose(`Validating schema ${key}.yml`);
14051406 const schema: ConfigObjectSchemaDTO = parse(readFileSync(path, 'utf8'));
14061407 if (!this.validateSchema(schema)) {
14071408 validations['message'] = `Schema ${key}.yml invalide: ${this.ajv.errorsText(this.validateSchema.errors)}`;
14081409 throw new ValidationConfigException(validations);
14091410 }
14101411 //verification des required, il faut que l'entree soit presente dans les proprietes
14111412 if (schema.hasOwnProperty('required')) {
1412- for (const required of schema['required']){
1413- if (! schema['properties'].hasOwnProperty(required)){
1413+ for (const required of schema['required']) {
1414+ if (!schema['properties'].hasOwnProperty(required)) {
14141415 validations['message'] = `Schema ${key}.yml invalide : required : ${required} without property`;
14151416 throw new ValidationConfigException(validations);
14161417 }
@@ -1429,9 +1430,9 @@ <h3 id="inputs">
14291430 }
14301431
14311432 if (reject) {
1432- throw new ValidationSchemaException({validations});
1433+ throw new ValidationSchemaException({ validations });
14331434 }
1434- return Promise.resolve({message: 'Validation succeeded'});
1435+ return Promise.resolve({ message: 'Validation succeeded' });
14351436 }
14361437
14371438 /**
@@ -1473,23 +1474,23 @@ <h3 id="inputs">
14731474 this.logger.debug(`Additionalfields object validation: ${JSON.stringify(data[key])}`);
14741475 //limitation de la taille du data pour le pb de deny of service de ajv
14751476 //voir (https://ajv.js.org/security.html)
1476- if (Object.keys(data[key]).length >500){
1477+ if (Object.keys(data[key]).length > 500) {
14771478 this.logger.error('Request too large');
14781479 throw new BadRequestException('Request too large');
14791480 }
1480- const ok= await this.ajv.validate(schema,data[key]);
1481+ const ok = await this.ajv.validate(schema, data[key]);
14811482 if (ok === false) {
14821483 const retErrors = {};
14831484 for (const err of this.ajv.errors) {
1484- retErrors[err['instancePath'].substring(1)]= err['instancePath'].substring(1) + ' ' + err['message']
1485+ retErrors[err['instancePath'].substring(1)] = err['instancePath'].substring(1) + ' ' + err['message']
14851486 }
1486- return(retErrors)
1487+ return (retErrors)
14871488 }
14881489 return null
14891490 }
14901491
14911492 public async findAll(): Promise<any> {
1492- this.logger.debug(['findAll', JSON.stringify(Object.values({...arguments}))].join(' '));
1493+ this.logger.debug(['findAll', JSON.stringify(Object.values({ ...arguments }))].join(' '));
14931494 const hardConfigPath = './src/management/identities/validations/_config';
14941495 const dynamicConfigPath = './configs/identities/validations';
14951496 // Retrieve files from each directory and tag them with their source
@@ -1538,7 +1539,7 @@ <h3 id="inputs">
15381539 const filePath = `${fileObj.path}/${fileObj.file}`;
15391540 const data = parse(readFileSync(filePath, 'utf-8'));
15401541 const key = fileObj.file.replace('.yml', '');
1541- result.push({[key]: data, source: fileObj.source, name: key});
1542+ result.push({ [key]: data, source: fileObj.source, name: key });
15421543 }
15431544 return [result, files.length];
15441545 }
@@ -1550,13 +1551,13 @@ <h3 id="inputs">
15501551 filePath = './validation/inetorgperson.json';
15511552 if (!existsSync(filePath)) {
15521553 const message = `File not found /validation/inetorgperson.json`;
1553- throw new ValidationConfigException({message});
1554+ throw new ValidationConfigException({ message });
15541555 }
15551556 } else {
15561557 filePath = this.resolveConfigPath(schema);
15571558 if (!existsSync(filePath)) {
15581559 const message = `File not found: ${filePath}`;
1559- throw new ValidationConfigException({message});
1560+ throw new ValidationConfigException({ message });
15601561 }
15611562 }
15621563 return parse(readFileSync(filePath, 'utf-8'));
0 commit comments