How to use the rest-hapi.update function in rest-hapi

To help you get started, we’ve selected a few rest-hapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JKHeadley / appy-backend / backend / server / api / auth.js View on Github external
githubId: request.pre.user.githubId,
            key: request.pre.keyHash.key
        }, Config.get('/jwtSecret'), { algorithm: 'HS256', expiresIn: "1m" });

        const _id = request.pre.user._id;

        const update = {
            socialLoginHash: request.pre.keyHash.hash
        };

        // EXPL: We update the user's social Id just in case they didn't have one yet
        if (request.pre.user.facebookId) { update.facebookId = request.pre.user.facebookId }
        if (request.pre.user.googleId) { update.googleId = request.pre.user.googleId }
        if (request.pre.user.githubId) { update.githubId = request.pre.user.githubId }

        return RestHapi.update(User, _id, update, Log)
            .then(function(user) {
                const redirectUrl = clientURL + '/login/social';
                return reply.redirect(redirectUrl + '/?token=' + token);
            })
            .catch(function (error) {
                Log.error(error);
                return reply(Boom.gatewayTimeout('An error occurred.'));
            });
    };
github JKHeadley / appy-backend / backend / server / api / user.js View on Github external
const updateCurrentUserProfileHandler = function (request, reply) {

      const _id = request.auth.credentials.user._id;

      return RestHapi.update(User, _id, request.payload.profile, Log)
        .then(function (user) {
          return reply(user);
        })
        .catch(function (error) {
          Log.error(error);
          return reply(error);
        });
    };
github JKHeadley / appy-backend / server / api / user.js View on Github external
const activateAccountHandler = function (request, reply) {

        const _id = request.params._id;

        return RestHapi.update(User, _id, { isActive: true }, Log)
          .then(function (user) {

            if (!user) {
              return reply(Boom.notFound('Document not found. That is strange.'));
            }

            return reply(user);
          })
          .catch(function (error) {
            Log.error(error);
            return reply(RestHapi.errorHelper.formatResponse(error));
          });
      };
github JKHeadley / appy-backend / server / api / user.api.js View on Github external
const disableAccountHandler = async function(request, h) {
      try {
        const _id = request.params._id

        return await RestHapi.update(User, _id, { isEnabled: false }, Log)
      } catch (err) {
        errorHelper.handleError(err, Log)
      }
    }
github JKHeadley / appy-backend / backend / server / api / user.js View on Github external
const updateCurrentUserPasswordHandler = function (request, reply) {

        const _id = request.auth.credentials.user._id;

        return RestHapi.update(User, _id, { password: request.pre.password.hash, passwordUpdateRequired: false }, Log)
          .then(function (user) {
            return reply(user);
          })
          .catch(function (error) {
            Log.error(error);
            return reply(RestHapi.errorHelper.formatResponse(error));
          });
      };
github JKHeadley / appy-backend / server / models / document.model.js View on Github external
pre: async function(payload, request, Log) {
            try {
              const Document = mongoose.model('document')
              let document = await RestHapi.find(
                Document,
                request.params.ownerId,
                {},
                Log
              )
              const scope = document.scope
              const userId = request.params.childId
              Document.removeDocumentPermissions(scope, userId)
              await RestHapi.update(Document, document._id, { scope }, Log)
              return payload
            } catch (err) {
              errorHelper.handleError(err, Log)
            }
          }
        }
github JKHeadley / appy-backend / backend / server / api / login.js View on Github external
.then(function (keyMatch) {
            if (!keyMatch) {
              reply(Boom.unauthorized('Invalid email or key.'));
              throw 'Invalid email or key.'
            }

            const _id = request.pre.user._id;
            const update = {
              $unset: {
                socialLoginHash: undefined
              }
            };

            return RestHapi.update(User, _id, update, Log);
          })
          .then(function (user) {
github JKHeadley / appy-backend / backend / server / api / login.js View on Github external
.then(function (passwordHash) {

          const _id = request.pre.user._id.toString();
          const update = {
            $set: {
              password: passwordHash.hash
            },
            $unset: {
              resetPassword: undefined
            }
          };

          return RestHapi.update(User, _id, update);
        })
        .then(function (result) {
github JKHeadley / appy-backend / server / models / user.model.js View on Github external
post: async function(document, request, result, logger) {
          const Log = logger.bind()
          try {
            const User = mongoose.model('user')
            if (!document.profileImageUrl) {
              let profileImageUrl =
                'https://www.gravatar.com/avatar/' +
                document._id +
                '?r=PG&d=robohash'
              return await RestHapi.update(
                User,
                document._id,
                { profileImageUrl },
                Log
              )
            } else {
              return document
            }
          } catch (err) {
            errorHelper.handleError(err, Log)
          }
        }
      }
github JKHeadley / appy-backend / server / api / user.api.js View on Github external
const updateCurrentUserProfileHandler = async function(request, h) {
      try {
        const _id = request.auth.credentials.user._id

        return await RestHapi.update(User, _id, request.payload.profile, Log)
      } catch (err) {
        errorHelper.handleError(err, Log)
      }
    }