Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- const Fusion = require('./models/mongo/fusion');
- const { Absystech,Atoutcoms,Att,Op,Col,Fn,Like } = require('./db/sequelize.js');
- //get
- module.exports.get = async({body},res)=>{
- const fusions = "%"+body.fusion+"%" ;
- try{
- if (!fusions){
- return alert('donnée manquante');
- }
- else if (fusions != null){
- var data = await Fusion.findOne({"fusion":{[Op.Like]:fusions}});
- if (!data){
- return res.json('societe inexistante')
- }
- else{
- return res.json(data);
- }
- }
- }
- catch(err) {
- console.log(err)
- return res.json(err)
- };
- }
- //post
- module.exports.pos = async ({ body }, res)=>{
- const fusion = body.fusion;
- const optimaAbsystech = body.absystech;
- const optimaAtoutcom = body.atoutcoms;
- const optimaAtt = body.att;
- try {
- if (fusion !=null ){
- var conf = await Fusion.findOne({'fusion':fusion})
- if (!conf){
- var newfusion = new Fusion({
- fusion : fusion,
- refs : {
- optimaAbsystech,
- optimaAtoutcom,
- optimaAtt,
- }
- })
- await newfusion.save();
- return res.json(newfusion)
- } else if (conf !=null) {
- return res.json('fusion preexistante')
- }
- }
- }
- catch(err){
- console.log(err)
- return res.json(err)
- }
- }
- //patch
- module.exports.pat = async({body},res)=>{
- const fusion = body.fusion;
- const optimaAbsystech = body.absystech;
- const optimaAtoutcom = body.atoutcoms;
- const optimaAtt = body.att;
- try{
- if (!fusion){
- return res.json('donnée manquante')
- }
- else {
- const conf = await Fusion.findOne({fusion});
- if (conf !=null) {
- const dataToUp = {refs:{optimaAbsystech ,optimaAtoutcom ,optimaAtt}}
- Fusion.findOneAndUpdate({fusion},dataToUp);
- console.log()
- } else{
- return res.json('aucune societe ne correspond')
- }
- }
- }
- catch(err){
- console.log(err)
- return res.json('erreur')
- }
- }
- //ne fonctionne pas pour le moment
- //delete
- module.exports.del=async({body},res)=>{
- const fusion = body.fusion;
- if (fusion != null){
- let del = await Fusion.findOneAndDelete({fusion})
- res.json(del)
- }
- else{
- return res.json('donées manquante')
- }
- ;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement