src/dataSource/db/utils.ts: use template strings

pull/23/head
leonnicolas 4 years ago
parent 9f032ab0a1
commit 4a89b758de
No known key found for this signature in database
GPG Key ID: 088D0743E2B65C07

@ -31,14 +31,13 @@ export function genDateRange (struct: any) {
} else if (struct.dateRange.to === struct.dateRange.from) { } else if (struct.dateRange.to === struct.dateRange.from) {
throw new UserInputError('Date Range can not be empty, provide different dates.'); 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. * 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. * It creates the numrange attributes than can be understood by postgres.
* @param from * @param range
* @param to
*/ */
function genNumRange (range: { min: number, max: number}) :string { function genNumRange (range: { min: number, max: number}) :string {
if (!range || (!range.max && !range.min)) { if (!range || (!range.max && !range.min)) {
@ -51,7 +50,7 @@ function genNumRange (range: { min: number, max: number}) :string {
if (range.min < 0) { if (range.min < 0) {
throw new UserInputError('Minimal value must be greater or equal to 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 // 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])) { if (updates[value] && typeof updates[value] === 'object' && !Array.isArray(updates[value])) {
Object.keys(updates[value]).forEach(subValue => { 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 { } else {
ret.push(alias + '."' + value + '"'); ret.push(`${alias}."${value}"`);
} }
}); });
return ret; return ret;

@ -105,11 +105,11 @@ export default {
} }
}, },
DateRange: { DateRange: {
from (parent: any) { from (parent: string) {
return (parent as string).split(',')[0].replace('[', ''); return parent.split(',')[0].replace('[', '');
}, },
to (parent: string) { to (parent: string) {
const str = (parent as string).split(',')[1].replace(')', ''); const str = parent.split(',')[1].replace(')', '');
return (str.length > 0) ? str : null; return (str.length > 0) ? str : null;
} }
}, },

Loading…
Cancel
Save