Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs');
  2. const Fusion = require('./models/mongo/fusion');
  3. const { Absystech,Atoutcoms,Att,Op,Col,Fn,Like } = require('./db/sequelize.js');
  4.  
  5. //get
  6. module.exports.get = async({body},res)=>{    
  7.     const fusions = "%"+body.fusion+"%" ;
  8.     try{    
  9.         if (!fusions){
  10.             return alert('donnée manquante');
  11.         }
  12.         else if (fusions != null){        
  13.             var data = await Fusion.findOne({"fusion":{[Op.Like]:fusions}});                
  14.             if (!data){
  15.                 return res.json('societe inexistante')
  16.             }
  17.             else{
  18.                 return res.json(data);
  19.             }
  20.         }            
  21.     }
  22.     catch(err) {
  23.             console.log(err)
  24.             return res.json(err)
  25.     };
  26. }
  27.        
  28. //post
  29. module.exports.pos = async ({ body }, res)=>{
  30.  
  31.     const fusion = body.fusion;
  32.     const optimaAbsystech = body.absystech;
  33.     const optimaAtoutcom = body.atoutcoms;
  34.     const optimaAtt = body.att;
  35.  
  36.     try {
  37.         if (fusion !=null ){
  38.             var conf = await Fusion.findOne({'fusion':fusion})
  39.             if (!conf){
  40.                 var newfusion = new Fusion({
  41.                     fusion : fusion,
  42.                     refs : {
  43.                         optimaAbsystech,
  44.                         optimaAtoutcom,
  45.                         optimaAtt,
  46.                     }                
  47.                 })
  48.                 await newfusion.save();
  49.  
  50.                 return res.json(newfusion)
  51.             } else if (conf !=null) {
  52.                 return res.json('fusion preexistante')
  53.               }
  54.         }        
  55.     }
  56.     catch(err){
  57.         console.log(err)
  58.         return res.json(err)
  59.     }
  60. }
  61.  
  62. //patch
  63. module.exports.pat = async({body},res)=>{
  64.     const fusion = body.fusion;
  65.     const optimaAbsystech = body.absystech;
  66.     const optimaAtoutcom = body.atoutcoms;
  67.     const optimaAtt = body.att;
  68.    
  69.  
  70.     try{
  71.         if (!fusion){
  72.             return res.json('donnée manquante')
  73.         }
  74.         else {
  75.             const conf = await Fusion.findOne({fusion});
  76.             if (conf !=null) {
  77.                 const dataToUp = {refs:{optimaAbsystech ,optimaAtoutcom ,optimaAtt}}
  78.                 Fusion.findOneAndUpdate({fusion},dataToUp);
  79.                 console.log()
  80.             } else{
  81.                 return res.json('aucune societe ne correspond')
  82.             }
  83.         }
  84.     }
  85.     catch(err){
  86.         console.log(err)
  87.         return res.json('erreur')        
  88.     }
  89. }
  90. //ne fonctionne pas pour le moment
  91.  
  92. //delete
  93. module.exports.del=async({body},res)=>{
  94.     const fusion = body.fusion;
  95.     if (fusion != null){
  96.     let del = await Fusion.findOneAndDelete({fusion})
  97.     res.json(del)
  98.     }
  99.     else{
  100.         return res.json('donées manquante')
  101.     }
  102. ;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement