Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 4x 1x 1x 1x | const joi = require('joi') const classificationDefinitionSchema = joi.object({ type: joi.string().valid('classBreaksDef', 'uniqueValueDef').error(new Error('invalid classification type')), baseSymbol: joi.object({ type: joi.string().valid('esriSMS', 'esriSLS', 'esriSFS').required().error(new Error('baseSymbol requires a type')) }).optional().unknown() }).unknown() function validateClassificationDefinition (definition, geometryType, breaks) { validateDefinitionShape(definition) validateDefinitionSymbolAgainstGeometry(definition.baseSymbol, geometryType) validateUniqueValueFields(definition.uniqueValueFields, breaks) } function validateDefinitionShape (definition) { const { error } = classificationDefinitionSchema.validate(definition) Iif (error) { error.code = 400 throw error } } function validateDefinitionSymbolAgainstGeometry (baseSymbol = {}, geometryType) { const { type: symbolType } = baseSymbol Eif (!symbolType) { return } if (symbolLookup(geometryType) !== symbolType) { const error = new Error('Classification defintion uses a base symbol that is incompatiable with dataset geometry') error.code = 400 throw error } } function symbolLookup (geometryType) { switch (geometryType) { case 'esriGeometryPoint': case 'esriGeometryMultipoint': return 'esriSMS' case 'esriGeometryPolyline': return 'esriSLS' case 'esriGeometryPolygon': return 'esriSFS' default: } } function validateUniqueValueFields (uniqueValueFields, breaks) { if (!uniqueValueFields) { return } const breakFieldNames = Object.keys(breaks[0]) Iif (uniqueValueFields.some(fieldName => !breakFieldNames.includes(fieldName))) { const error = new Error(`Unique value fields are incongruous: ${breakFieldNames} ${uniqueValueFields}`) error.code = 400 throw error } } module.exports = validateClassificationDefinition |