Updating customer profile Api using node and graphql

Here we need to pass the customer email and token and the fields which are going to update.

updateCustomerProfile: ({ CUSTOMER_EMAIL, TOKEN, FIRST_NAME, LAST_NAME, COMPANY_NAME, PHONE }) => {
        return token_check.token_verify(CUSTOMER_EMAIL, TOKEN)
            .then((data) => {


                if (data == "TOKEN_INVALID" || data == "TOKEN_EXPIRED" || data == "RECORD_NOT_FOUND")
                    return { summary: { status: "SUCCESS", reason: data } }


                else if (data == "TOKEN_VALID") {
                    return customer.findOne({ where: { email: CUSTOMER_EMAIL } })
                        .then((row) => {
                            if (!row)
                                return { summary: { status: "SUCCESS", reason: "RECORD_NOT_FOUND" } }
                            else {

                                return customer.update({
                                    date_modified: new Date(),

                                    first_name: FIRST_NAME,
                                    last_name: LAST_NAME,
                                    company_name: COMPANY_NAME,
                                    phone: PHONE
                                }, {
                                    where: { email: CUSTOMER_EMAIL }
                                }).then((result) => {

                                    if (result[0] == 1)

                                        return { summary: { status: "SUCCESS", reason: "RECORD_UPDATED" } }
                                    else
                                        return { summary: { status: "SUCCESS", reason: "RECORD_NOT_UPDATED" } }

                                }).catch(function (error) {
                                    //console.log(error);
                                    return { summary: { status: "SUCCESS", reason: "RECORD_NOT_FOUND" } }

                                });


                            }
                        })
                        .catch(function (error) {
                            // console.log(error);
                            return { summary: { status: "SUCCESS", reason: "RECORD_NOT_FOUND" } }

                        });

                }

            })
            .catch(function (error) {
                // console.log(error);
                return { summary: { status: "SUCCESS", reason: "RECORD_NOT_FOUND" } }

            });


    },

Leave a comment

Your email address will not be published. Required fields are marked *