From 721bd05e2ddf5f75f75c0a09b5ee11373b0019e3 Mon Sep 17 00:00:00 2001 From: Tim Beyer Date: Wed, 2 Jan 2019 15:37:34 +0100 Subject: [PATCH] fix: respect shouldPublish when it is set to false --- src/lib/action/entry-derive.ts | 4 +++- src/lib/entities/entry.ts | 4 ++-- src/lib/utils/is-defined.ts | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/lib/utils/is-defined.ts diff --git a/src/lib/action/entry-derive.ts b/src/lib/action/entry-derive.ts index 164b12719..c6b206672 100644 --- a/src/lib/action/entry-derive.ts +++ b/src/lib/action/entry-derive.ts @@ -2,6 +2,8 @@ import EntryDerive from '../interfaces/entry-derive' import { APIAction } from './action' import { OfflineAPI } from '../offline-api' import { ContentType } from '../entities/content-type' +import isDefined from '../utils/is-defined' + import Entry from '../entities/entry' import * as _ from 'lodash' @@ -22,7 +24,7 @@ class EntryDeriveAction extends APIAction { this.derivedContentType = entryDerivation.derivedContentType this.deriveEntryForLocale = entryDerivation.deriveEntryForLocale this.identityKey = entryDerivation.identityKey - this.shouldPublish = entryDerivation.shouldPublish || true + this.shouldPublish = isDefined(entryDerivation.shouldPublish) ? entryDerivation.shouldPublish : true } async applyTo (api: OfflineAPI) { diff --git a/src/lib/entities/entry.ts b/src/lib/entities/entry.ts index 78043f8e3..d25ff719b 100644 --- a/src/lib/entities/entry.ts +++ b/src/lib/entities/entry.ts @@ -1,6 +1,6 @@ import { cloneDeep } from 'lodash' import APIEntry from '../interfaces/api-entry' -import { isNullOrUndefined } from 'util' +import isDefined from '../utils/is-defined' class Entry { private _id: string @@ -64,7 +64,7 @@ class Entry { } get isPublished () { - return !isNullOrUndefined(this._publishedVersion) + return isDefined(this._publishedVersion) } get publishedVersion () { diff --git a/src/lib/utils/is-defined.ts b/src/lib/utils/is-defined.ts new file mode 100644 index 000000000..30bd17077 --- /dev/null +++ b/src/lib/utils/is-defined.ts @@ -0,0 +1,3 @@ +export default function isDefined (value: T | undefined | null): value is T { + return value !== undefined && value !== null +}