Skip to content

Commit

Permalink
fix: avoid nullish coalescing operator
Browse files Browse the repository at this point in the history
  • Loading branch information
tada5hi committed Jan 18, 2023
1 parent 0168e7d commit 2f98bc1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/parameter/fields/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function parseQueryFields<T extends ObjectLiteral = ObjectLiteral>(
data: unknown,
options?: FieldsParseOptions<T>,
) : FieldsParseOutput {
options ??= {};
options = options || {};

const defaultDomainFields = groupArrayByKeyPath(
flattenParseAllowedOption(options.default),
Expand Down Expand Up @@ -85,7 +85,7 @@ export function parseQueryFields<T extends ObjectLiteral = ObjectLiteral>(
data = { [DEFAULT_ID]: data };
}

options.mapping ??= {};
options.mapping = options.mapping || {};
const reverseMapping = buildReverseRecord(options.mapping);

if (keys.length === 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/parameter/filters/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function parseQueryFilters<T extends ObjectLiteral = ObjectLiteral>(
data: unknown,
options?: FiltersParseOptions<T>,
) : FiltersParseOutput {
options = options ?? {};
options = options || {};
options.mapping = options.mapping || {};
options.relations = options.relations || [];

Expand Down
2 changes: 1 addition & 1 deletion src/parameter/pagination/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function parseQueryPagination(
data: unknown,
options?: PaginationParseOptions,
) : PaginationParseOutput {
options ??= {};
options = options || {};

const pagination : PaginationParseOutput = {};

Expand Down
6 changes: 4 additions & 2 deletions src/parameter/relations/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function parseQueryRelations<T extends ObjectLiteral = ObjectLiteral>(
data: unknown,
options?: RelationsParseOptions<T>,
): RelationsParseOutput {
options ??= {};
options = options || {};

// If it is an empty array nothing is allowed
if (
Expand All @@ -30,7 +30,9 @@ export function parseQueryRelations<T extends ObjectLiteral = ObjectLiteral>(

options.mapping = options.mapping || {};
options.pathMapping = options.pathMapping || {};
options.includeParents ??= true;
if (typeof options.includeParents === 'undefined') {
options.includeParents = true;
}

let items: string[] = [];

Expand Down
2 changes: 1 addition & 1 deletion src/parameter/sort/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function parseQuerySort<T extends ObjectLiteral = ObjectLiteral>(
data: unknown,
options?: SortParseOptions<T>,
) : SortParseOutput {
options = options ?? {};
options = options || {};

// If it is an empty array nothing is allowed
if (typeof options.allowed !== 'undefined') {
Expand Down
12 changes: 6 additions & 6 deletions src/parse/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function parseQuery<T extends ObjectLiteral = ObjectLiteral>(
input: ParseInput,
options?: ParseOptions<T>,
) : ParseOutput {
options ??= {};
options = options || {};

const mergeWithGlobalOptions = <T extends {[key: string]: any} & {defaultPath?: string} >(data?: T) : T => {
if (typeof data !== 'undefined') {
Expand Down Expand Up @@ -55,7 +55,7 @@ export function parseQuery<T extends ObjectLiteral = ObjectLiteral>(

switch (key) {
case Parameter.RELATIONS: {
const value = input[Parameter.RELATIONS] ?? input[URLParameter.RELATIONS];
const value = input[Parameter.RELATIONS] || input[URLParameter.RELATIONS];
if (value && isQueryParameterEnabled(options[Parameter.RELATIONS])) {
relations = parseQueryParameter(
key,
Expand All @@ -68,7 +68,7 @@ export function parseQuery<T extends ObjectLiteral = ObjectLiteral>(
break;
}
case Parameter.FIELDS: {
const value = input[Parameter.FIELDS] ?? input[URLParameter.FIELDS];
const value = input[Parameter.FIELDS] || input[URLParameter.FIELDS];
if (value && isQueryParameterEnabled(options[Parameter.FIELDS])) {
output[Parameter.FIELDS] = parseQueryParameter(
key,
Expand All @@ -80,7 +80,7 @@ export function parseQuery<T extends ObjectLiteral = ObjectLiteral>(
break;
}
case Parameter.FILTERS: {
const value = input[Parameter.FILTERS] ?? input[URLParameter.FILTERS];
const value = input[Parameter.FILTERS] || input[URLParameter.FILTERS];
if (value && isQueryParameterEnabled(options[Parameter.FILTERS])) {
output[Parameter.FILTERS] = parseQueryParameter(
key,
Expand All @@ -92,7 +92,7 @@ export function parseQuery<T extends ObjectLiteral = ObjectLiteral>(
break;
}
case Parameter.PAGINATION: {
const value = input[Parameter.PAGINATION] ?? input[URLParameter.PAGINATION];
const value = input[Parameter.PAGINATION] || input[URLParameter.PAGINATION];
if (value && isQueryParameterEnabled(options[Parameter.PAGINATION])) {
output[Parameter.PAGINATION] = parseQueryParameter(
key,
Expand All @@ -104,7 +104,7 @@ export function parseQuery<T extends ObjectLiteral = ObjectLiteral>(
break;
}
case Parameter.SORT: {
const value = input[Parameter.SORT] ?? input[URLParameter.SORT];
const value = input[Parameter.SORT] || input[URLParameter.SORT];
if (value && isQueryParameterEnabled(options[Parameter.SORT])) {
output[Parameter.SORT] = parseQueryParameter(
key,
Expand Down

0 comments on commit 2f98bc1

Please sign in to comment.