posts and comments created by the factory set the observe relation (#8344)

This commit is contained in:
Moriz Wahl 2025-04-09 10:36:56 +02:00 committed by GitHub
parent f782032563
commit fe7bab4675
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 28 additions and 1 deletions

View File

@ -175,6 +175,7 @@ Factory.define('post')
])
await Promise.all([
post.relateTo(author, 'author'),
post.relateTo(author, 'observes'),
// Promise.all(categories.map((c) => c.relateTo(post, 'post'))),
Promise.all(tags.map((t) => t.relateTo(post, 'post'))),
])
@ -210,7 +211,11 @@ Factory.define('comment')
options.author,
options.post,
])
await Promise.all([comment.relateTo(author, 'author'), comment.relateTo(post, 'post')])
await Promise.all([
comment.relateTo(author, 'author'),
comment.relateTo(post, 'post'),
post.relateTo(author, 'observes'),
])
return comment
})

View File

@ -58,4 +58,15 @@ export default {
},
pinned: { type: 'boolean', default: null, valid: [null, true] },
postType: { type: 'string', default: 'Article', valid: ['Article', 'Event'] },
observes: {
type: 'relationship',
relationship: 'OBSERVES',
target: 'User',
direction: 'in',
properties: {
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
updatedAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
active: { type: 'boolean', default: true },
},
},
}

View File

@ -163,4 +163,15 @@ export default {
type: 'string',
allow: [null],
},
observes: {
type: 'relationship',
relationship: 'OBSERVES',
target: 'Post',
direction: 'out',
properties: {
createdAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
updatedAt: { type: 'string', isoDate: true, default: () => new Date().toISOString() },
active: { type: 'boolean', default: true },
},
},
}