0
votes

I'm trying to write a CRON in strapi to query product that is post_status: "Draft" and username blocked is false. If true, it should not show and results. The username has a one to many relations with the product.

"use strict";


module.exports = {
  "*/1 * * * *": async () => {
    const draftProductToPublishToFacebook = await strapi.api.product.services.product.find(
      {
        post_status: "Draft",
        published_at_lt: new Date(),
        username: {
          blocked: false,
        },
      }
    );
  },
};

Sample data

{
    post_status: 'Draft',
    _id: 5eef02af7761f1425dd0ccec,
    stock_status: 'test',
    product_status: 'publish',
    __v: 0,
    username: {
      confirmed: true,
      blocked: false,
      _id: 5eef05985f864742725ab8e1,
      username: 'test2',
      email: '[email protected]',
      provider: 'local',
      createdAt: 2020-06-21T07:00:40.996Z,
      updatedAt: 2020-07-17T01:24:58.918Z,
      __v: 0,
      role: 5ee30d5424f89d5253877e90,
      id: '5eef05985f864742725ab8e1'
    },
    published_at: 2020-08-02T00:20:00.000Z,
    id: '5eef02af7761f1425dd0ccec'
  }

The error I'm getting (node:3652) UnhandledPromiseRejectionWarning: CastError: Cast to ObjectId failed for value "{ blocked: false }" at path "username" for model "product"

Thanks

1

1 Answers

0
votes
'username.blocked': false

should work.