-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
avniproject/avni-client#1142 - check for mandatory object fields to b…
…e not null during create and update.
- Loading branch information
1 parent
d518fe7
commit 8d70e06
Showing
8 changed files
with
99 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import _ from "lodash"; | ||
|
||
// https://www.mongodb.com/docs/realm/sdk/react-native/model-data/data-types/property-types/#std-label-react-native-supported-property-types | ||
const inBuiltPropertyTypes = ["bool", "int", "float", "double", "string", "decimal128", "objectId", "data", "date", "list", "linkingObjects", "dictionary", "set", "mixed", "uuid"]; | ||
|
||
class DefinedObjectSchema { | ||
properties; | ||
|
||
static getNonOptionalObjectProperties(definedSchema) { | ||
return Object.keys(definedSchema.properties).filter((key) => { | ||
const value = definedSchema.properties[key]; | ||
const isSimpleDefinition = typeof value === 'string'; | ||
const type = isSimpleDefinition ? value : value["type"]; | ||
const contains = _.some(inBuiltPropertyTypes, (x) => type.replace("?", "") === x); | ||
return !contains && (isSimpleDefinition ? true : !value["optional"]); | ||
}); | ||
} | ||
} | ||
|
||
export default DefinedObjectSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import DefinedObjectSchema from "../src/framework/DefinedObjectSchema"; | ||
import {assert} from 'chai'; | ||
|
||
const schema = { | ||
name: "Foo", | ||
primaryKey: "uuid", | ||
properties: { | ||
uuid: "string", | ||
subjectType: "SubjectType", | ||
name: "string", | ||
age: "float", | ||
wage: "float?", | ||
middleName: {type: "string", optional: true}, | ||
profilePicture: {type: "string", optional: false}, | ||
dateOfBirth: {type: "date", optional: true}, | ||
gender: {type: "Gender", optional: true}, | ||
registrationDate: "date", | ||
lowestAddressLevel: {type: "AddressLevel", optional: false}, | ||
enrolments: {type: "list", objectType: "Bar"}, | ||
registrationLocation: {type: "Point", optional: true} | ||
} | ||
}; | ||
|
||
it('should getNonOptionalObjectProperties', function () { | ||
const nonOptionalObjectProperties = DefinedObjectSchema.getNonOptionalObjectProperties(schema); | ||
assert.equal(nonOptionalObjectProperties.length, 2); | ||
assert.equal(nonOptionalObjectProperties[0], "subjectType"); | ||
assert.equal(nonOptionalObjectProperties[1], "lowestAddressLevel"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {EntityMappingConfig} from "../src"; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
petmongrels
Author
Contributor
|
||
|
||
xit('should get all non optional object properties', function () { | ||
let instance = EntityMappingConfig.getInstance(); | ||
console.log(instance.mandatoryObjectSchemaProperties.map((x) => `${x.definedSchema.name} --> ${x.propertyName}`)); | ||
}); |
Looks like the
.length
is fetched on the wrong object