@@ -21,7 +21,7 @@ export const postData = {
21
21
async create ( application , publication , properties , draftMode = false ) {
22
22
debug ( `Create %O` , { draftMode, properties } ) ;
23
23
24
- const { posts , timeZone } = application ;
24
+ const { timeZone } = application ;
25
25
const { me, postTypes, syndicationTargets } = publication ;
26
26
27
27
// Add syndication targets
@@ -67,9 +67,10 @@ export const postData = {
67
67
const postData = { path, properties } ;
68
68
69
69
// Add data to posts collection (or replace existing if present)
70
- if ( posts ) {
70
+ const postsCollection = application ?. collections ?. get ( "posts" ) ;
71
+ if ( postsCollection ) {
71
72
const query = { "properties.url" : properties . url } ;
72
- await posts . replaceOne ( query , postData , { upsert : true } ) ;
73
+ await postsCollection . replaceOne ( query , postData , { upsert : true } ) ;
73
74
}
74
75
75
76
return postData ;
@@ -84,10 +85,10 @@ export const postData = {
84
85
async read ( application , url ) {
85
86
debug ( `Read ${ url } ` ) ;
86
87
87
- const { posts } = application ;
88
88
const query = { "properties.url" : url } ;
89
+ const postsCollection = application ?. collections ?. get ( "posts" ) ;
89
90
90
- const postData = await posts . findOne ( query ) ;
91
+ const postData = await postsCollection . findOne ( query ) ;
91
92
if ( ! postData ) {
92
93
throw IndiekitError . notFound ( url ) ;
93
94
}
@@ -108,8 +109,9 @@ export const postData = {
108
109
async update ( application , publication , url , operation ) {
109
110
debug ( `Update ${ url } %O` , { operation } ) ;
110
111
111
- const { posts , timeZone } = application ;
112
+ const { timeZone } = application ;
112
113
const { me, postTypes } = publication ;
114
+ const postsCollection = application ?. collections ?. get ( "posts" ) ;
113
115
114
116
// Read properties
115
117
let { path : _originalPath , properties } = await this . read ( application , url ) ;
@@ -171,7 +173,7 @@ export const postData = {
171
173
// Update data in posts collection
172
174
const postData = { _originalPath, path, properties } ;
173
175
const query = { "properties.url" : url } ;
174
- await posts . replaceOne ( query , postData ) ;
176
+ await postsCollection . replaceOne ( query , postData ) ;
175
177
176
178
return postData ;
177
179
} ,
@@ -188,8 +190,9 @@ export const postData = {
188
190
async delete ( application , publication , url ) {
189
191
debug ( `Delete ${ url } ` ) ;
190
192
191
- const { posts , timeZone } = application ;
193
+ const { timeZone } = application ;
192
194
const { postTypes } = publication ;
195
+ const postsCollection = application ?. collections ?. get ( "posts" ) ;
193
196
194
197
// Read properties
195
198
const { properties } = await this . read ( application , url ) ;
@@ -222,7 +225,7 @@ export const postData = {
222
225
// Update data in posts collection
223
226
const postData = { path, properties, _deletedProperties } ;
224
227
const query = { "properties.url" : url } ;
225
- await posts . replaceOne ( query , postData ) ;
228
+ await postsCollection . replaceOne ( query , postData ) ;
226
229
227
230
return postData ;
228
231
} ,
@@ -240,8 +243,8 @@ export const postData = {
240
243
async undelete ( application , publication , url , draftMode ) {
241
244
debug ( `Undelete ${ url } %O` , { draftMode } ) ;
242
245
243
- const { posts } = application ;
244
246
const { postTypes } = publication ;
247
+ const postsCollection = application ?. collections ?. get ( "posts" ) ;
245
248
246
249
// Read deleted properties
247
250
const { _deletedProperties } = await this . read ( application , url ) ;
@@ -270,7 +273,7 @@ export const postData = {
270
273
// Update data in posts collection
271
274
const postData = { path, properties } ;
272
275
const query = { "properties.url" : url } ;
273
- await posts . replaceOne ( query , postData ) ;
276
+ await postsCollection . replaceOne ( query , postData ) ;
274
277
275
278
return postData ;
276
279
} ,
0 commit comments