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 to
*/
function genNumRange (from: number, to: number) {
if (from === null || from === undefined) {
from = to;
} else if (to === null || to === undefined) {
to = from;
function genNumRange (range: { min: number, max: number}) :string {
if (!range || (!range.max && !range.min)) {
return null;
} else if (range.min === null || range.min === undefined) {
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
*/
export function genBoxDimensions (cargoBike: any) {
cargoBike.dimensionsAndLoad.boxLengthRange = genNumRange(cargoBike.dimensionsAndLoad.minBoxLength, cargoBike.dimensionsAndLoad.maxBoxLength);
cargoBike.dimensionsAndLoad.boxWidthRange = genNumRange(cargoBike.dimensionsAndLoad.minBoxWidth, cargoBike.dimensionsAndLoad.maxBoxWidth);
cargoBike.dimensionsAndLoad.boxHeightRange = genNumRange(cargoBike.dimensionsAndLoad.minBoxHeight, cargoBike.dimensionsAndLoad.maxBoxHeight);
// delete this so update cargo bike works
delete cargoBike.dimensionsAndLoad.minBoxLength;
delete cargoBike.dimensionsAndLoad.maxBoxLength;
delete cargoBike.dimensionsAndLoad.minBoxWidth;
delete cargoBike.dimensionsAndLoad.maxBoxWidth;
delete cargoBike.dimensionsAndLoad.minBoxHeight;
delete cargoBike.dimensionsAndLoad.maxBoxHeight;
if (!cargoBike.dimensionsAndLoad) { return; }
cargoBike.dimensionsAndLoad.boxLengthRange = genNumRange(cargoBike.dimensionsAndLoad.boxLengthRange);
cargoBike.dimensionsAndLoad.boxWidthRange = genNumRange(cargoBike.dimensionsAndLoad.boxWidthRange);
cargoBike.dimensionsAndLoad.boxHeightRange = genNumRange(cargoBike.dimensionsAndLoad.boxHeightRange);
}
/**

@ -161,45 +161,12 @@ export default {
isLockedByMe: (parent: any, __: any, { req }: { req: any }) => isLockedByMe(parent, { req }),
isLocked: (parent: any, __: any, { req }: { req: any }) => isLocked(parent, { req })
},
DimensionsAndLoad: {
minBoxLength: (parent: any) => {
if (!parent.boxLengthRange || parent.boxLengthRange === 'empty') {
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;
NumRange: {
min: (parent: string) => {
return parent.split(',')[0].replace('[', '');
},
maxBoxWidth: (parent: any) => {
if (!parent.boxWidthRange || parent.boxWidthRange === 'empty') {
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;
max: (parent: string) => {
return parent.split(',')[1].replace(']', '');
}
},
Equipment: {

@ -33,6 +33,7 @@ export default gql`
The kind of currency depends on the database.
"""
scalar Money
"The CargoBike type is central to the graph. You could call it the root."
type CargoBike {
id: ID!
@ -266,17 +267,28 @@ export default gql`
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."
type DimensionsAndLoad {
hasCoverBox: Boolean
"cover box can be locked"
lockable: Boolean
minBoxLength: Float
maxBoxLength: Float
minBoxWidth: Float
maxBoxWidth: Float
minBoxHeight: Float
maxBoxHeight: Float
boxLengthRange: NumRange
boxWidthRange: NumRange
boxHeightRange: NumRange
maxWeightBox: Float
maxWeightLuggageRack: Float
maxWeightTotal: Float
@ -289,12 +301,9 @@ export default gql`
input DimensionsAndLoadCreateInput {
hasCoverBox: Boolean
lockable: Boolean
minBoxLength: Float
maxBoxLength: Float
minBoxWidth: Float
maxBoxWidth: Float
minBoxHeight: Float
maxBoxHeight: Float
boxLengthRange: NumRangeInput
boxWidthRange: NumRangeInput
boxHeightRange: NumRangeInput
maxWeightBox: Float
maxWeightLuggageRack: Float
maxWeightTotal: Float
@ -307,12 +316,9 @@ export default gql`
input DimensionsAndLoadUpdateInput {
hasCoverBox: Boolean
lockable: Boolean
minBoxLength: Float
maxBoxLength: Float
minBoxWidth: Float
maxBoxWidth: Float
minBoxHeight: Float
maxBoxHeight: Float
boxLengthRange: NumRangeInput
boxWidthRange: NumRangeInput
boxHeightRange: NumRangeInput
maxWeightBox: Float
maxWeightLuggageRack: Float
maxWeightTotal: Float

Loading…
Cancel
Save