Improved migration code substantially, wrote migrations for more properties
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { Random } from 'meteor/random';
|
||||
import {
|
||||
FieldToComputeSchema,
|
||||
ComputedOnlyFieldSchema,
|
||||
ComputedFieldSchema,
|
||||
fieldToCompute,
|
||||
computedOnlyField,
|
||||
} from '/imports/api/properties/subSchemas/ComputedFieldSchema.js';
|
||||
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||
|
||||
@@ -21,10 +20,10 @@ const AttributeConsumedSchema = new SimpleSchema({
|
||||
max: STORAGE_LIMITS.variableName,
|
||||
},
|
||||
quantity: {
|
||||
type: FieldToComputeSchema,
|
||||
type: Object,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
}).extend(fieldToCompute('quantity'));
|
||||
|
||||
const ComputedOnlyAttributeConsumedSchema = new SimpleSchema({
|
||||
available: {
|
||||
@@ -41,21 +40,11 @@ const ComputedOnlyAttributeConsumedSchema = new SimpleSchema({
|
||||
optional: true,
|
||||
max: STORAGE_LIMITS.name,
|
||||
},
|
||||
quantity: {
|
||||
type: ComputedOnlyFieldSchema,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
}).extend(computedOnlyField('quantity'));
|
||||
|
||||
const ComputedAttributeConsumedSchema = new SimpleSchema()
|
||||
.extend(AttributeConsumedSchema)
|
||||
.extend(ComputedOnlyAttributeConsumedSchema)
|
||||
.extend({
|
||||
quantity: {
|
||||
type: ComputedFieldSchema,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
.extend(ComputedOnlyAttributeConsumedSchema);
|
||||
|
||||
export {
|
||||
AttributeConsumedSchema,
|
||||
|
||||
@@ -2,34 +2,53 @@ import SimpleSchema from 'simpl-schema';
|
||||
import ErrorSchema from '/imports/api/properties/subSchemas/ErrorSchema.js';
|
||||
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||
|
||||
const FieldToComputeSchema = new SimpleSchema({
|
||||
// This is required, if we don't have a calculation delete the whole object
|
||||
calculation: {
|
||||
type: String,
|
||||
},
|
||||
});
|
||||
// Get schemas that apply fields directly so they can be gracefully extended
|
||||
// because {type: Schema} fields can't be extended
|
||||
function fieldToCompute(field){
|
||||
return new SimpleSchema({
|
||||
// The object should already be set, but set again just in case
|
||||
[field]: {
|
||||
type: Object,
|
||||
optional: true,
|
||||
},
|
||||
// This is required, if we don't have a calculation delete the whole object
|
||||
[`${field}.calculation`]: {
|
||||
type: String,
|
||||
max: STORAGE_LIMITS.calculation,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const ComputedOnlyFieldSchema = new SimpleSchema({
|
||||
value: {
|
||||
type: SimpleSchema.oneOf(String, Number),
|
||||
optional: true,
|
||||
},
|
||||
errors: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
maxCount: STORAGE_LIMITS.errorCount,
|
||||
},
|
||||
'errors.$':{
|
||||
type: ErrorSchema,
|
||||
},
|
||||
});
|
||||
function computedOnlyField(field){
|
||||
return new SimpleSchema({
|
||||
// The object should already be set, but set again just in case
|
||||
[field]: {
|
||||
type: Object,
|
||||
optional: true,
|
||||
},
|
||||
[`${field}.value`]: {
|
||||
type: SimpleSchema.oneOf(String, Number),
|
||||
optional: true,
|
||||
},
|
||||
[`${field}.errors`]: {
|
||||
type: Array,
|
||||
optional: true,
|
||||
maxCount: STORAGE_LIMITS.errorCount,
|
||||
},
|
||||
[`${field}.errors.$`]:{
|
||||
type: ErrorSchema,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const ComputedFieldSchema = new SimpleSchema()
|
||||
.extend(FieldToComputeSchema)
|
||||
.extend(ComputedOnlyFieldSchema)
|
||||
// This should rarely be used, since the other two will merge correctly when
|
||||
// uncomputed and computedOnly schemas are merged
|
||||
function computedField(field){
|
||||
return computedField(field).extend(computedOnlyField(field));
|
||||
}
|
||||
|
||||
export {
|
||||
FieldToComputeSchema,
|
||||
ComputedOnlyFieldSchema,
|
||||
ComputedFieldSchema
|
||||
fieldToCompute,
|
||||
computedOnlyField,
|
||||
computedField,
|
||||
};
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { Random } from 'meteor/random';
|
||||
import {
|
||||
FieldToComputeSchema,
|
||||
ComputedOnlyFieldSchema,
|
||||
ComputedFieldSchema,
|
||||
fieldToCompute,
|
||||
computedOnlyField,
|
||||
} from '/imports/api/properties/subSchemas/ComputedFieldSchema.js';
|
||||
import { storedIconsSchema } from '/imports/api/icons/Icons.js';
|
||||
import STORAGE_LIMITS from '/imports/constants/STORAGE_LIMITS.js';
|
||||
@@ -21,7 +20,7 @@ const ItemConsumedSchema = new SimpleSchema({
|
||||
optional: true,
|
||||
},
|
||||
quantity: {
|
||||
type: FieldToComputeSchema,
|
||||
type: Object,
|
||||
optional: true,
|
||||
},
|
||||
itemId: {
|
||||
@@ -29,17 +28,13 @@ const ItemConsumedSchema = new SimpleSchema({
|
||||
regEx: SimpleSchema.RegEx.Id,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
}).extend(fieldToCompute('quantity'));
|
||||
|
||||
const ComputedOnlyItemConsumedSchema = new SimpleSchema({
|
||||
available: {
|
||||
type: Number,
|
||||
optional: true,
|
||||
},
|
||||
quantity: {
|
||||
type: ComputedOnlyFieldSchema,
|
||||
optional: true,
|
||||
},
|
||||
// This appears both in the computed and uncomputed schema because it can be
|
||||
// set by both a computation or a form
|
||||
itemId: {
|
||||
@@ -62,17 +57,11 @@ const ComputedOnlyItemConsumedSchema = new SimpleSchema({
|
||||
optional: true,
|
||||
max: STORAGE_LIMITS.color,
|
||||
},
|
||||
})
|
||||
}).extend(computedOnlyField('quantity'));
|
||||
|
||||
const ComputedItemConsumedSchema = new SimpleSchema()
|
||||
.extend(ItemConsumedSchema)
|
||||
.extend(ComputedOnlyItemConsumedSchema)
|
||||
.extend({
|
||||
quantity: {
|
||||
type: ComputedFieldSchema,
|
||||
optional: true,
|
||||
},
|
||||
});
|
||||
.extend(ComputedOnlyItemConsumedSchema);
|
||||
|
||||
export {
|
||||
ItemConsumedSchema,
|
||||
|
||||
Reference in New Issue
Block a user