Refactor readUnpublishedBranchFile with resolvePromiseProperties

This commit is contained in:
Benaiah Mischenko
2017-03-20 12:28:04 -07:00
parent 1dc2841609
commit 1aa02eb42a

View File

@ -1,7 +1,7 @@
import LocalForage from "localforage"; import LocalForage from "localforage";
import { Base64 } from "js-base64"; import { Base64 } from "js-base64";
import _ from "lodash"; import _ from "lodash";
import { filterPromises } from "../../lib/promiseHelper"; import { filterPromises, resolvePromiseProperties } from "../../lib/promiseHelper";
import AssetProxy from "../../valueObjects/AssetProxy"; import AssetProxy from "../../valueObjects/AssetProxy";
import { SIMPLE, EDITORIAL_WORKFLOW, status } from "../../constants/publishModes"; import { SIMPLE, EDITORIAL_WORKFLOW, status } from "../../constants/publishModes";
import { APIError, EditorialWorkflowError } from "../../valueObjects/errors"; import { APIError, EditorialWorkflowError } from "../../valueObjects/errors";
@ -159,24 +159,18 @@ export default class API {
} }
readUnpublishedBranchFile(contentKey) { readUnpublishedBranchFile(contentKey) {
let metaData, fileData; const metaDataPromise = this.retrieveMetadata(contentKey)
const unpublishedPromise = this.retrieveMetadata(contentKey) .then(data => (data.objects.entry.path ? data : Promise.reject(null)));
.then((data) => { return resolvePromiseProperties({
metaData = data; metaData: metaDataPromise,
if (data.objects.entry.path) { fileData: metaDataPromise.then(
return this.readFile(data.objects.entry.path, null, data.branch); data => this.readFile(data.objects.entry.path, null, data.branch)),
} isModification: metaDataPromise.then(
return Promise.reject(null); data => this.isUnpublishedEntryModification(data.objects.entry.path, this.branch)),
}) })
.then((file) => {
fileData = file;
return this.isUnpublishedEntryModification(metaData.objects.entry.path);
})
.then(isModification => ({ metaData, fileData, isModification }))
.catch(() => { .catch(() => {
throw new EditorialWorkflowError('content is not under editorial workflow', true); throw new EditorialWorkflowError('content is not under editorial workflow', true);
}); });
return unpublishedPromise;
} }
isUnpublishedEntryModification(path, branch) { isUnpublishedEntryModification(path, branch) {