Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
741 B
1
Indexable
Never
const MAX = 300
      const cursor = await this.stockModel
        .find({
          prices: { $ne: null },
        })
        .cursor()
      let document
      while ((document = await cursor.next())) {
        const increase = (document?.prices[0]?.price[0] || 0) * percent
        const price =
          increase > MAX
            ? (document?.prices[0]?.price[0] || 0) + MAX
            : (document?.prices[0]?.price[0] || 0) + increase
        await this.stockModel.updateOne(
          {
            _id: document._id,
          },
          {
            $set: {
              'prices.0.price.0': price,
              salePriceString: price?.toString() || '0',
            },
          },
        )
      }