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