import { Request } from 'express' ; import { IVueTablesQuery } from '@/typings/vue-tables-pagination' ; export function getReqProtocolAndHost ( req ) { return `${ req . protocol }://${ req . get ( 'host' ) }` ; } export function getReqUrl ( req ) { return `${ req . protocol }://${ req . get ( 'host' ) }${ req . baseUrl }` ; } export function getVueTablesQuery ( params ) { return { ascending : parseInt ( params [ 'ascending' ] ?? 1 , 10 ) , byColumn : parseInt ( params [ 'byColumn' ] ?? 1 , 10 ) , limit : parseInt ( params [ 'limit' ] ?? 100 , 10 ) , orderBy : params [ 'orderBy' ] , page : parseInt ( params [ 'page' ] ?? 1 , 10 ) , query : JSON . parse ( params [ 'query' ] ?? '{}' ) , } ; } param req param param export function getQueryAsNumber ( req , param ) ; param req param param param defaultValue export function getQueryAsNumber ( req , param , defaultValue ) ; export function getQueryAsNumber ( req , param , defaultValue = undefined as number | undefined ) { const value = req . query [ param ] ; if ( value !== undefined && typeof value === 'string' && value . length > 0 ) { return Number ( value ) ; } return defaultValue ; } param req param param export function getQueryAsString ( req , param ) ; export function getQueryAsString < T > ( req , param ) ; param req param param param defaultValue export function getQueryAsString ( req , param , defaultValue ) ; export function getQueryAsString < T > ( req , param , defaultValue ) ; export function getQueryAsString ( req , param , defaultValue ? ) { const value = req . query [ param ] ; if ( typeof value === 'string' && value . length > 0 ) { return value ; } return defaultValue ; } export function getQueryAsStringArray ( req , param , defaultValue = new Array < string > ( ) ) { const value = req . query [ param ] ; return Array . isArray ( value ) ? ( value as string [ ] ) : defaultValue ; }