将实体置于草稿模式 Strapi

Bring entities on draft mode Strapi

场景

我正在尝试从端点获取所有实体,草稿模式的实体和已发布模式的实体。 我知道如果我想 post 草稿模式,我必须 post published_at on null body request.

如果我这样做:

/posts?published_at_null=true 

那 return 是一个空数组。

问题

我该如何对 return ALL post 进行处理?

您将必须创建一个自定义控件来获取所有 entries.you 无法使用现有 restapi url 获取草稿数据。

const { sanitizeEntity } = require('strapi-utils');

module.exports = {
  async findUnpublished(ctx) {

    //getting all the existing articles, no meter if they have unpublished status
    let result = await strapi.query('posts').find();
    
    //sanitize them to hide all private fields
    let articles = sanitizeEntity(result, {
        model: strapi.models['posts'],
    });
    
    //return result to the /findUnpublished API
    ctx.send(articles);
  }
};

它在文档中

https://strapi.io/documentation/developer-docs/latest/developer-resources/content-api/content-api.html#publication-state

但快速回答,URL + '?_publicationState=preview'

https://forum.strapi.io/t/draft-and-posted-entities/3576/2