<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: umasankar-swain</title>
    <description>The latest articles on DEV Community by umasankar-swain (@umasankarswain).</description>
    <link>https://dev.to/umasankarswain</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F938640%2Fe9f930ec-0957-4231-bd6e-68bbb4979b37.png</url>
      <title>DEV Community: umasankar-swain</title>
      <link>https://dev.to/umasankarswain</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/umasankarswain"/>
    <language>en</language>
    <item>
      <title>How to update a record and delete that same record before update (nest js &amp; mongoDB)</title>
      <dc:creator>umasankar-swain</dc:creator>
      <pubDate>Wed, 19 Oct 2022 06:22:14 +0000</pubDate>
      <link>https://dev.to/umasankarswain/how-to-update-a-record-and-delete-that-same-record-before-update-nest-js-mongodb-349m</link>
      <guid>https://dev.to/umasankarswain/how-to-update-a-record-and-delete-that-same-record-before-update-nest-js-mongodb-349m</guid>
      <description>&lt;p&gt;I want to update a record by its id but before update, i want to delete the previously stored data on that same record.What would be the process?&lt;/p&gt;

&lt;p&gt;controller.ts&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   public updateVendorServiceSpecialPrice = async (req: Request, res: Response, next: NextFunction): Promise&amp;lt;Response | void&amp;gt; =&amp;gt; {
    try {
        if (req.body.vendorServiceId!='') {
            let results = await this.ServicesService.updateVendorServicesSpecialPrice(req.params.vendorServiceId, req.body);
            if (results != false) {
                this.success(res, 'Updated Successfully', 200, results._id);
            }
        } 
        return await this.error(res, 'Something Went Wrong!.', 500);
    } catch (e) {
        next(e)
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;service.ts&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public async updateVendorServicesSpecialPrice(
    vendorServiceId: any,
    data: any
): Promise&amp;lt;any | Error&amp;gt; {
    try {
        return new Promise((resolve, reject) =&amp;gt; {
            vendorServiceSpecialPriceSchema.findByIdAndUpdate(
                vendorServiceId,
                { ...data },
                (err: any, success: any) =&amp;gt; {
                    if (err) {
                        reject(err);
                    }
                    if (!success) {
                        resolve(false);
                    } else {
                        resolve(success);
                    }
                }
            );
        });
    } catch (e) {
        console.log('service error\n', e);
        throw e;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;I am trying in this way to solve this,may be I am wrong,what would br the right process:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    public async updateVendorServicesSpecialPrice(
    vendorServiceId: any,
    data: any
): Promise&amp;lt;any | Error&amp;gt; {
    try {
        return new Promise((resolve, reject) =&amp;gt; {
            vendorServiceSpecialPriceSchema.deleteOne({vendorServiceId})
            vendorServiceSpecialPriceSchema.findOneAndUpdate(
                vendorServiceId,
                { ...data },
                { returnNewDocument: true },
                (err: any, success: any) =&amp;gt; {
                    if (err) {
                        reject(err);
                    }
                    if (!success) {
                        resolve(false);
                    } else {
                        resolve(success);
                    }
                }
            );
        });
    } catch (e) {
        console.log('service error\n', e);
        throw e;
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Thanks for your time....&lt;/p&gt;

</description>
      <category>nestjs</category>
      <category>node</category>
      <category>mongodb</category>
      <category>javascript</category>
    </item>
    <item>
      <title>How to check any property of State has any null value or not</title>
      <dc:creator>umasankar-swain</dc:creator>
      <pubDate>Fri, 07 Oct 2022 06:24:24 +0000</pubDate>
      <link>https://dev.to/umasankarswain/how-to-check-any-property-of-state-has-any-null-value-or-not-2ngm</link>
      <guid>https://dev.to/umasankarswain/how-to-check-any-property-of-state-has-any-null-value-or-not-2ngm</guid>
      <description>&lt;p&gt;Here is the state of my App:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [state, setState] = useState({
    priceType: 0,
    recurrenceType: 0,
    start_date: '',
    end_date: '',
    minCapacity: 0,
    maxCapacity: 0,
    price: 0,
    min: 0,
    max: 0,
    days: []
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the code of condition in which I am trying to achive, if any property of the state has null value then return true otherwise return false.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const isNullish = Object.values(state).every(value =&amp;gt; {
        if (value==='' &amp;amp;&amp;amp; value===0 &amp;amp;&amp;amp; value === []) {
          return true;
        }
        return false;
      });
console.log(isNullish)
console.log(state)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the chalenge is whenever I execute that code in my app it returns false although the properties has no value.Below is the console output of above code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;false
SpecialPrice.jsx:124 {priceType: 0, recurrenceType: 0, start_date: '', end_date: '', 
minCapacity: 0, …}
days: []
end_date: ""
max: 0maxCapacity: 0
min: 0
minCapacity: 0
price: 0
priceType: 0
recurrenceType: 0
start_date: ""
[[Prototype]]: Object
SpecialPrice.jsx:129 []
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For better understanding I have attached a screenshot here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1lgOTs5l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wxc0prqowz5v5r3f221k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1lgOTs5l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wxc0prqowz5v5r3f221k.png" alt="Image description" width="880" height="272"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks in advance....&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
