From 4a89b758de931dea02b794576d489353e879bc39 Mon Sep 17 00:00:00 2001 From: leonnicolas Date: Sun, 29 Nov 2020 13:56:06 +0100 Subject: [PATCH] src/dataSource/db/utils.ts: use template strings --- src/datasources/db/utils.ts | 11 +++++------ src/resolvers/lendingStationResolvers.ts | 6 +++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/datasources/db/utils.ts b/src/datasources/db/utils.ts index 8e6bd96..7262417 100644 --- a/src/datasources/db/utils.ts +++ b/src/datasources/db/utils.ts @@ -31,14 +31,13 @@ export function genDateRange (struct: any) { } else if (struct.dateRange.to === struct.dateRange.from) { throw new UserInputError('Date Range can not be empty, provide different dates.'); } - struct.dateRange = '[' + struct.dateRange.from + ',' + struct.dateRange.to + ')'; + struct.dateRange = `[${struct.dateRange.from},${struct.dateRange.to})`; } /** * This function helps prepare the cargoBike struct, to be used in an update or create. * It creates the numrange attributes than can be understood by postgres. - * @param from - * @param to + * @param range */ function genNumRange (range: { min: number, max: number}) :string { if (!range || (!range.max && !range.min)) { @@ -51,7 +50,7 @@ function genNumRange (range: { min: number, max: number}) :string { if (range.min < 0) { throw new UserInputError('Minimal value must be greater or equal to 0'); } - return range.min ? '[' + range.min + ',' + range.max + ']' : null; + return `[${range.min},${range.max}]`; } /** @@ -277,10 +276,10 @@ export class ActionLogger { // sometimes updates[value] is an array, e.g. timePeriods that are saved as a simple array in postgres if (updates[value] && typeof updates[value] === 'object' && !Array.isArray(updates[value])) { Object.keys(updates[value]).forEach(subValue => { - ret.push(alias + '."' + value + subValue[0].toUpperCase() + subValue.substr(1).toLowerCase() + '"'); + ret.push(`${alias}."${value}${subValue[0].toUpperCase()}${subValue.substr(1).toLowerCase()}"`); }); } else { - ret.push(alias + '."' + value + '"'); + ret.push(`${alias}."${value}"`); } }); return ret; diff --git a/src/resolvers/lendingStationResolvers.ts b/src/resolvers/lendingStationResolvers.ts index 8cc3467..f17d87f 100644 --- a/src/resolvers/lendingStationResolvers.ts +++ b/src/resolvers/lendingStationResolvers.ts @@ -105,11 +105,11 @@ export default { } }, DateRange: { - from (parent: any) { - return (parent as string).split(',')[0].replace('[', ''); + from (parent: string) { + return parent.split(',')[0].replace('[', ''); }, to (parent: string) { - const str = (parent as string).split(',')[1].replace(')', ''); + const str = parent.split(',')[1].replace(')', ''); return (str.length > 0) ? str : null; } },