Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • A api
  • Project information
    • Project information
    • Activity
    • Labels
    • Planning hierarchy
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 0
    • Issues 0
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 0
    • Merge requests 0
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • arbitrium
  • api
  • Wiki
  • lixo

Last edited by Gabriel Fanto Stundner May 11, 2018
Page history
This is an old version of this page. You can view the most recent version or browse the history.

lixo

como fazer a função update:

exports.update = function(req, res) {

    // Validate input, in our case we will recive a json if 
    // all changeable informations, in activity's
    // perspective we to recive the ID of activity and the
    // description, so, we check if its not blank
    if(!req.params.activityId) {
        return res.status(400).send({
            message: "Acitivity's ID cannot be empty"
        });
    }
    if(!req.body.description) {
        return res.status(400).send({
            message: "Activity's description cannot be empty"
        });
    }

    // Normally on our project we are using await/async
    // but in that case is pretty simple to use the standart promise
    // so, without await/async but with just then at the and of a function
    AcitivityModel.update(
        { description: req.body.description },
        { where: { id: req.params.activityId } }
    ).then(function(updateStatus) {
        // First of all, what happens above:
        // update is a function that recives two parameters and returns a update status
        // the first of those two parameters is: a map of column: newValue that should be updated
        // the second one is: a map with your where clause
        // its update status return is a array if just one position, where 0 extends for failure
        // and 1 for success

        // Now, about the promises, when we finish a function we can add a .then at its end
        // making the "then" function just happen after our main function, we also can take
        // whatever the main function send back to the caller, so, we have a new function
        // reciving the 'updateStatus' that was the result from the update

        if(updateStatus[0] === 0) {
            // 0 means failure, so throw a error
            return res.status(404).send({
                message: "Acitivity not found with ID " + req.params.activityId + "."
            });
        } else if(updateStatus[0] === 1) {
            // 1 means success, so throw a success message
            return res.status(200).send({
                message: "Acitivity with ID equals to " + req.params.activityId + " updated successfully."
            });
        } else {
            // Just to be sure that non special situation might pass
            return res.status(500).send({
                message: "Error updating activity with ID " + req.params.activityId + "."
            });
        }
    }).catch(function(err) {
        // Checking anykind of exceptions
        if(err.kind === 'ObjectId') {
            return res.status(404).send({
                message: "Acitivity not found with ID " + req.params.activityId + "."
            });
        }
        return res.status(500).send({
            message: "Error updating activity with ID " + req.params.activityId + "."
        });
    });
};
Clone repository
  • Back
    • Detalhamento das Rotas de Activity
    • Especificacao de Rotas
  • Banco
    • Modelagem
  • Front
    • Definicao
    • Design
    • Tutorial VueJS
  • Gerenciamento
    • Configuracao
      • Definicao de Branches e Fluxo do Git
      • Git Rebase
      • Git Squash
    • Cronograma AGES 2018 1
    • Horarios do Time
    • Sprints
      • Dailies
      • Planning
      • Retrospectivas
  • Requisitos
    • Regras de Negocio
View All Pages