I've added some data using a Post request and now I'm trying to retrieve all the data from the table using a Get request. However, it seems that the last data I added is not being included in the response. Is there a specific approach I should take to ensure I get the updated data?
Below is the code snippet from my controller:
app.ajoutProjet = function () {
// Add a new project using the CreatProjet() service that utilizes Post method
Projet.createProjet(app.ajoutData);
// Retrieve all projects
Projet.getProjet().then(function(result){
for(var i=0; i<result.data.projetsListe.length; i++){
// Check if the project name matches the one we just added
if(result.data.projetsListe[i].NomProjet == app.ajoutData.NomProjet){
app.ajoutData.projet_id = result.data.projetsListe[i].IdProjet;
CP.createCP(app.ajoutData);
}
}
});
app.successMsg = 'Project added...Redirection';
EDIT:
Here is the Project Service code:
// Create a new project
createProjet: function (ajoutData) {
return $http.post('/api/projets', ajoutData);
},
// Retrieve all projects
getProjet: function () {
return $http.get('/api/projets');
}
Although the project is successfully created, it is not being included in the list of projects returned by the Get request. Any suggestions?
EDIT
Details of my Post method:
router.post('/projets', function(req, res){
projet.Projet.sync({force: false}).then(function () {
// Table created
return projet.Projet.create({
IdProjet: req.body.IdProjet,
NomProjet: req.body.NomProjet,
ResponsableApitech: req.body.ResponsableApitech,
ResponsableClient: req.body.ResponsableClient,
client_id: req.body.client_id,
estArchive: req.body.estArchive
});
});
});