src/* : use numRange for box dimensions

instead of minBoxWidth, etc, use range type NumRange
pull/23/head
leonnicolas 4 years ago
parent 0754fd5f74
commit b0fc6cabe3
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -40,13 +40,33 @@ export function genDateRange (struct: any) {
* @param from * @param from
* @param to * @param to
*/ */
function genNumRange (from: number, to: number) { function genNumRange (range: { min: number, max: number}) :string {
if (from === null || from === undefined) { if (!range || (!range.max && !range.min)) {
from = to; return null;
} else if (to === null || to === undefined) { } else if (range.min === null || range.min === undefined) {
to = from; range.min = range.max;
} else if (range.max === null || range.max === undefined) {
range.max = range.min;
} }
return from ? '[' + from + ',' + to + ']' : null; if (range.min < 0) {
throw new UserInputError('Minimal value must be greater or equal to 0');
}
return range.min ? '[' + range.min + ',' + range.max + ']' : null;
}
export function minNumRange (parent: string) {
if (!parent || parent === 'empty') {
return null;
}
return (parent).split(',')[0].replace('[', '');
}
export function maxNumRange (parent: string) {
if (!parent || parent === 'empty') {
return null;
}
const str = (parent).split(',')[1].replace(']', '');
return (str.length > 0) ? str : null;
} }
/** /**
@ -55,16 +75,10 @@ function genNumRange (from: number, to: number) {
* @param cargoBike * @param cargoBike
*/ */
export function genBoxDimensions (cargoBike: any) { export function genBoxDimensions (cargoBike: any) {
cargoBike.dimensionsAndLoad.boxLengthRange = genNumRange(cargoBike.dimensionsAndLoad.minBoxLength, cargoBike.dimensionsAndLoad.maxBoxLength); if (!cargoBike.dimensionsAndLoad) { return; }
cargoBike.dimensionsAndLoad.boxWidthRange = genNumRange(cargoBike.dimensionsAndLoad.minBoxWidth, cargoBike.dimensionsAndLoad.maxBoxWidth); cargoBike.dimensionsAndLoad.boxLengthRange = genNumRange(cargoBike.dimensionsAndLoad.boxLengthRange);
cargoBike.dimensionsAndLoad.boxHeightRange = genNumRange(cargoBike.dimensionsAndLoad.minBoxHeight, cargoBike.dimensionsAndLoad.maxBoxHeight); cargoBike.dimensionsAndLoad.boxWidthRange = genNumRange(cargoBike.dimensionsAndLoad.boxWidthRange);
// delete this so update cargo bike works cargoBike.dimensionsAndLoad.boxHeightRange = genNumRange(cargoBike.dimensionsAndLoad.boxHeightRange);
delete cargoBike.dimensionsAndLoad.minBoxLength;
delete cargoBike.dimensionsAndLoad.maxBoxLength;
delete cargoBike.dimensionsAndLoad.minBoxWidth;
delete cargoBike.dimensionsAndLoad.maxBoxWidth;
delete cargoBike.dimensionsAndLoad.minBoxHeight;
delete cargoBike.dimensionsAndLoad.maxBoxHeight;
} }
/** /**

@ -161,45 +161,12 @@ export default {
isLockedByMe: (parent: any, __: any, { req }: { req: any }) => isLockedByMe(parent, { req }), isLockedByMe: (parent: any, __: any, { req }: { req: any }) => isLockedByMe(parent, { req }),
isLocked: (parent: any, __: any, { req }: { req: any }) => isLocked(parent, { req }) isLocked: (parent: any, __: any, { req }: { req: any }) => isLocked(parent, { req })
}, },
DimensionsAndLoad: { NumRange: {
minBoxLength: (parent: any) => { min: (parent: string) => {
if (!parent.boxLengthRange || parent.boxLengthRange === 'empty') { return parent.split(',')[0].replace('[', '');
return null;
}
return parent.boxLengthRange ? (parent.boxLengthRange as string).split(',')[0].replace('[', '') : null;
},
maxBoxLength: (parent: any) => {
if (!parent.boxLengthRange || parent.boxLengthRange === 'empty') {
return null;
}
const str = (parent.boxLengthRange as string).split(',')[1].replace(']', '');
return (str.length > 0) ? str : null;
},
minBoxWidth: (parent: any) => {
if (!parent.boxWidthRange || parent.boxWidthRange === 'empty') {
return null;
}
return parent.boxWidthRange ? (parent.boxWidthRange as string).split(',')[0].replace('[', '') : null;
}, },
maxBoxWidth: (parent: any) => { max: (parent: string) => {
if (!parent.boxWidthRange || parent.boxWidthRange === 'empty') { return parent.split(',')[1].replace(']', '');
return null;
}
const str = (parent.boxWidthRange as string).split(',')[1].replace(']', '');
return (str.length > 0) ? str : null;
},
minBoxHeight: (parent: any) => {
if (!parent.boxHeightRange || parent.boxHeightRange === 'empty') {
return null;
}
return parent.boxHeightRange ? (parent.boxHeightRange as string).split(',')[0].replace('[', '') : null;
},
maxBoxHeight: (parent: any) => {
if (!parent.boxHeightRange || parent.boxHeightRange === 'empty') {
return null;
}
const str = (parent.boxHeightRange as string).split(',')[1].replace(']', '');
return (str.length > 0) ? str : null;
} }
}, },
Equipment: { Equipment: {

@ -33,6 +33,7 @@ export default gql`
The kind of currency depends on the database. The kind of currency depends on the database.
""" """
scalar Money scalar Money
"The CargoBike type is central to the graph. You could call it the root." "The CargoBike type is central to the graph. You could call it the root."
type CargoBike { type CargoBike {
id: ID! id: ID!
@ -266,17 +267,28 @@ export default gql`
notes: String notes: String
} }
type NumRange {
min: Float
max: Float
}
"""
If min or max is omitted, the omitted value will be the same as the other given value
So if you pass one as null, both values with be over written with null.
"""
input NumRangeInput {
min: Float
max: Float
}
"How are the dimensions and how much weight can handle a bike. This data is merged in the CargoBike table and the BikeModel table." "How are the dimensions and how much weight can handle a bike. This data is merged in the CargoBike table and the BikeModel table."
type DimensionsAndLoad { type DimensionsAndLoad {
hasCoverBox: Boolean hasCoverBox: Boolean
"cover box can be locked" "cover box can be locked"
lockable: Boolean lockable: Boolean
minBoxLength: Float boxLengthRange: NumRange
maxBoxLength: Float boxWidthRange: NumRange
minBoxWidth: Float boxHeightRange: NumRange
maxBoxWidth: Float
minBoxHeight: Float
maxBoxHeight: Float
maxWeightBox: Float maxWeightBox: Float
maxWeightLuggageRack: Float maxWeightLuggageRack: Float
maxWeightTotal: Float maxWeightTotal: Float
@ -289,12 +301,9 @@ export default gql`
input DimensionsAndLoadCreateInput { input DimensionsAndLoadCreateInput {
hasCoverBox: Boolean hasCoverBox: Boolean
lockable: Boolean lockable: Boolean
minBoxLength: Float boxLengthRange: NumRangeInput
maxBoxLength: Float boxWidthRange: NumRangeInput
minBoxWidth: Float boxHeightRange: NumRangeInput
maxBoxWidth: Float
minBoxHeight: Float
maxBoxHeight: Float
maxWeightBox: Float maxWeightBox: Float
maxWeightLuggageRack: Float maxWeightLuggageRack: Float
maxWeightTotal: Float maxWeightTotal: Float
@ -307,12 +316,9 @@ export default gql`
input DimensionsAndLoadUpdateInput { input DimensionsAndLoadUpdateInput {
hasCoverBox: Boolean hasCoverBox: Boolean
lockable: Boolean lockable: Boolean
minBoxLength: Float boxLengthRange: NumRangeInput
maxBoxLength: Float boxWidthRange: NumRangeInput
minBoxWidth: Float boxHeightRange: NumRangeInput
maxBoxWidth: Float
minBoxHeight: Float
maxBoxHeight: Float
maxWeightBox: Float maxWeightBox: Float
maxWeightLuggageRack: Float maxWeightLuggageRack: Float
maxWeightTotal: Float maxWeightTotal: Float

Loading…
Cancel
Save