moved Entry VO away from implementations
This commit is contained in:
@ -85,7 +85,6 @@ class Backend {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// We have the file path. Fetch and parse the file.
|
|
||||||
getEntry(collection, slug) {
|
getEntry(collection, slug) {
|
||||||
return this.implementation.getEntry(collection, slug, new Collection(collection).entryPath(slug))
|
return this.implementation.getEntry(collection, slug, new Collection(collection).entryPath(slug))
|
||||||
.then(loadedEntry => this.entryWithFormat(collection, slug)(createEntry(
|
.then(loadedEntry => this.entryWithFormat(collection, slug)(createEntry(
|
||||||
@ -112,14 +111,31 @@ class Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unpublishedEntries(page, perPage) {
|
unpublishedEntries(page, perPage) {
|
||||||
return this.implementation.unpublishedEntries(page, perPage).then(response => ({
|
return this.implementation.unpublishedEntries(page, perPage)
|
||||||
pagination: response.pagination,
|
.then(loadedEntries => (
|
||||||
entries: response.entries.map(this.entryWithFormat('editorialWorkflow')),
|
loadedEntries.map((loadedEntry) => {
|
||||||
}));
|
const entry = createEntry('draft', loadedEntry.slug, loadedEntry.file.path, { raw: loadedEntry.data })
|
||||||
|
entry.metaData = loadedEntry.metaData;
|
||||||
|
return entry;
|
||||||
|
})
|
||||||
|
))
|
||||||
|
.then((entries) => {
|
||||||
|
const filteredEntries = entries.filter(entry => entry !== null);
|
||||||
|
return {
|
||||||
|
pagination: 0,
|
||||||
|
entries: filteredEntries.map(this.entryWithFormat('editorialWorkflow')),
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
unpublishedEntry(collection, slug) {
|
unpublishedEntry(collection, slug) {
|
||||||
return this.implementation.unpublishedEntry(collection, slug).then(this.entryWithFormat(collection));
|
return this.implementation.unpublishedEntry(collection, slug)
|
||||||
|
.then(loadedEntry => this.entryWithFormat(collection, slug)(createEntry(
|
||||||
|
collection.get('name'),
|
||||||
|
slug,
|
||||||
|
loadedEntry.file.path,
|
||||||
|
{ raw: loadedEntry.data }
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
persistEntry(config, collection, entryDraft, MediaFiles, options) {
|
persistEntry(config, collection, entryDraft, MediaFiles, options) {
|
||||||
|
@ -154,7 +154,7 @@ export default class API {
|
|||||||
metaData = data;
|
metaData = data;
|
||||||
return this.readFile(data.objects.entry, null, data.branch);
|
return this.readFile(data.objects.entry, null, data.branch);
|
||||||
})
|
})
|
||||||
.then(file => ({ metaData, file }))
|
.then(fileData => ({ metaData, fileData }))
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
@ -79,16 +79,19 @@ export default class GitHub {
|
|||||||
const promises = [];
|
const promises = [];
|
||||||
branches.map((branch) => {
|
branches.map((branch) => {
|
||||||
promises.push(new Promise((resolve, reject) => {
|
promises.push(new Promise((resolve, reject) => {
|
||||||
const contentKey = branch.ref.split('refs/heads/cms/').pop();
|
const slug = branch.ref.split('refs/heads/cms/').pop();
|
||||||
return sem.take(() => this.api.readUnpublishedBranchFile(contentKey).then((data) => {
|
return sem.take(() => this.api.readUnpublishedBranchFile(slug).then((data) => {
|
||||||
if (data === null || data === undefined) {
|
if (data === null || data === undefined) {
|
||||||
resolve(null);
|
resolve(null);
|
||||||
sem.leave();
|
sem.leave();
|
||||||
} else {
|
} else {
|
||||||
const entryPath = data.metaData.objects.entry;
|
const path = data.metaData.objects.entry;
|
||||||
const entry = createEntry('draft', contentKey, entryPath, { raw: data.file });
|
resolve({
|
||||||
entry.metaData = data.metaData;
|
slug,
|
||||||
resolve(entry);
|
file: { path },
|
||||||
|
data: data.fileData,
|
||||||
|
metaData: data.metaData,
|
||||||
|
});
|
||||||
sem.leave();
|
sem.leave();
|
||||||
}
|
}
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
@ -98,18 +101,12 @@ export default class GitHub {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
return Promise.all(promises);
|
return Promise.all(promises);
|
||||||
}).then((entries) => {
|
})
|
||||||
const filteredEntries = entries.filter(entry => entry !== null);
|
|
||||||
return {
|
|
||||||
pagination: 0,
|
|
||||||
entries: filteredEntries,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unpublishedEntry(collection, slug) {
|
unpublishedEntry(collection, slug) {
|
||||||
return this.unpublishedEntries().then(response => (
|
return this.unpublishedEntries().then(response => (
|
||||||
response.entries.filter((entry) => {
|
response.filter((entry) => {
|
||||||
return entry.metaData && entry.slug === slug;
|
return entry.metaData && entry.slug === slug;
|
||||||
})[0]
|
})[0]
|
||||||
));
|
));
|
||||||
|
Reference in New Issue
Block a user