Handled our forced null conversion in bookshelf

refs https://github.com/TryGhost/Arch/issues/47

We've configured bookshelf to force empty strings to null, but this is
undesired behaviour here, so unfortunately we have to leak some business
logic into the repository.

This needs to be done to correctly support our filter validation logic.
This commit is contained in:
Fabien "egg" O'Carroll 2023-08-23 13:06:16 +07:00 committed by Fabien 'egg' O'Carroll
parent 359617462a
commit 27bfa30f97

View File

@ -66,13 +66,17 @@ module.exports = class BookshelfCollectionsRepository {
#modelToCollection(model) { #modelToCollection(model) {
const json = model.toJSON(); const json = model.toJSON();
let filter = json.filter;
if (json.type === 'automatic' && typeof filter !== 'string') {
filter = '';
}
return Collection.create({ return Collection.create({
id: json.id, id: json.id,
slug: json.slug, slug: json.slug,
title: json.title, title: json.title,
description: json.description, description: json.description,
filter: json.filter, filter: filter,
type: json.type, type: json.type,
featureImage: json.feature_image, featureImage: json.feature_image,
posts: json.collectionPosts.map(collectionPost => collectionPost.post_id), posts: json.collectionPosts.map(collectionPost => collectionPost.post_id),