From fe7bab46753991da7cb918ab19a75bc3337b67b0 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Wed, 9 Apr 2025 10:36:56 +0200 Subject: [PATCH] posts and comments created by the factory set the observe relation (#8344) --- backend/src/db/factories.ts | 7 ++++++- backend/src/models/Post.ts | 11 +++++++++++ backend/src/models/User.ts | 11 +++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/backend/src/db/factories.ts b/backend/src/db/factories.ts index 459a8d186..86f51a259 100644 --- a/backend/src/db/factories.ts +++ b/backend/src/db/factories.ts @@ -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 }) diff --git a/backend/src/models/Post.ts b/backend/src/models/Post.ts index e206ea1f5..75081b728 100644 --- a/backend/src/models/Post.ts +++ b/backend/src/models/Post.ts @@ -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 }, + }, + }, } diff --git a/backend/src/models/User.ts b/backend/src/models/User.ts index 9b828e27e..fa357775a 100644 --- a/backend/src/models/User.ts +++ b/backend/src/models/User.ts @@ -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 }, + }, + }, }