Example #1
0
 def post(self):
     data = api.payload 
     activity = Activity(vin=data['vin'], scan_time=data['scan_time'])
     data['act_id'] = time.time()
     activity.act_id = int(data['act_id'])
     if Van.objects(vin=activity.vin).first():
         activity.save()
         resp = Activity.objects.aggregate(*[
             { '$match': { 'act_id' : activity.act_id } },
             {
                 '$project': {
                     '_id': '$$REMOVE', 
                     'vin': '$vin', 
                     'act_id': '$act_id', 
                     'scan_time': {
                         '$dateToString': {
                             'format': '%Y-%m-%d %H:%M:%S', 
                             'date': '$scan_time'
                         }
                     }
                 }
             }
         ])
         resp_string = encoder.encode(list(resp))
         return json.loads(resp_string), 200
         # return jsonify(Activity.objects(act_id=activity.act_id))
     else:
         abort(400, 'This vin does not exist')
Example #2
0
 def get(self, idx=None):
     
     resp = None
     if idx is None:
         resp = Company.objects.aggregate(*[
             {
                 '$lookup': {
                     'from': 'van', 
                     'localField': 'company_id', 
                     'foreignField': 'company_id', 
                     'as': 'vans'
                 }
             }, {
                 '$unwind': {
                     'path': '$vans', 
                     'preserveNullAndEmptyArrays': False
                 }
             }, {
                 '$project': {
                     '_id': '$$REMOVE', 
                     'company_id': '$company_id', 
                     'company_name': '$company_name', 
                     'van_id': '$vans.van_id',
                     'vin': '$vans.vin'
                 }
             }
         ])
     else:
         resp = Company.objects.aggregate(*[
             { '$match': { 'company_id' : idx } },
             {
                 '$lookup': {
                     'from': 'van', 
                     'localField': 'company_id', 
                     'foreignField': 'company_id', 
                     'as': 'vans'
                 }
             }, {
                 '$unwind': {
                     'path': '$vans', 
                     'preserveNullAndEmptyArrays': False
                 }
             }, {
                 '$project': {
                     '_id': '$$REMOVE',  
                     'company_name': '$company_name', 
                     'van_id': '$vans.van_id',  
                     'vin': '$vans.vin'
                 }
             }
         ])
     resp_string = encoder.encode(list(resp))
     return json.loads(resp_string), 200
Example #3
0
 def get(self, txt: str, txt_: str, txt_1: str):
 
     resp = Products.objects.aggregate(*[
         {
             '$match': {
                 'name': {
                     '$regex': f'(?=.*{txt}.)(?=.*{txt_}.)(?=.*{txt_1}.).*', 
                     '$options':'i'
                 }
             }
         }
     ])
     
     resp_string = encoder.encode(list(resp))
     
     return json.loads(resp_string), 200
Example #4
0
 def get(self, txt: str):
 
     resp = Products.objects.aggregate(*[
         {
             '$match': {
                 'name': {
                     '$regex': '.*' + txt + '.*', 
                     '$options':'i'
                 }
             }
         }
     ])
     
     resp_string = encoder.encode(list(resp))
     
     return json.loads(resp_string), 200
Example #5
0
 def get(self):
     resp = Activity.objects.aggregate(*[
             {
                 '$project': {
                     '_id': '$$REMOVE', 
                     'vin': '$vin', 
                     'act_id': '$act_id', 
                     'scan_time': {
                         '$dateToString': {
                             'format': '%Y-%m-%d %H:%M:%S', 
                             'date': '$scan_time'
                         }
                     }
                 }
             }
         ])
     resp_string = encoder.encode(list(resp))
     return json.loads(resp_string), 200
Example #6
0
 def get(self, idx=None):
     
     resp = None
     if idx is None:
         resp = Company.objects.aggregate(*[
             {
                 '$lookup': {
                     'from': 'van', 
                     'localField': 'company_id', 
                     'foreignField': 'company_id', 
                     'as': 'vans'
                 }
             }, {
                 '$unwind': {
                     'path': '$vans', 
                     'includeArrayIndex': 'index', 
                     'preserveNullAndEmptyArrays': False
                 }
             }, {
                 '$project': {
                     '_id': '$$REMOVE', 
                     'company_id': '$company_id', 
                     'company_name': '$company_name', 
                     'van_id': '$vans.van_id', 
                     'vin': '$vans.vin'
                 }
             }, {
                 '$lookup': {
                     'from': 'activity', 
                     'localField': 'van_id', 
                     'foreignField': 'van_id', 
                     'as': 'activities'
                 }
             }, {
                 '$unwind': {
                     'path': '$activities', 
                     'preserveNullAndEmptyArrays': False
                 }
             }, {
                 '$project': {
                     'company_id': '$company_id', 
                     'company_name': '$company_name', 
                     'van_id': '$van_id', 
                     'vin': '$vin',  
                     'scan_time': {
                         '$dateToString': {
                             'format': '%Y-%m-%d %H:%M:%S', 
                             'date': '$activities.scan_time'
                         }
                     }
                 }
             }
         ])
     else:
         resp = Company.objects.aggregate(*[
             { '$match': { 'company_id' : idx } },
             {
                 '$lookup': {
                     'from': 'van', 
                     'localField': 'company_id', 
                     'foreignField': 'company_id', 
                     'as': 'vans'
                 }
             }, {
                 '$unwind': {
                     'path': '$vans', 
                     'includeArrayIndex': 'index', 
                     'preserveNullAndEmptyArrays': False
                 }
             }, {
                 '$project': {
                     '_id': '$$REMOVE', 
                     'company_id': '$company_id', 
                     'company_name': '$company_name', 
                     'van_id': '$vans.van_id', 
                     'vin': '$vans.vin'
                 }
             }, {
                 '$lookup': {
                     'from': 'activity', 
                     'localField': 'van_id', 
                     'foreignField': 'van_id', 
                     'as': 'activities'
                 }
             }, {
                 '$unwind': {
                     'path': '$activities', 
                     'preserveNullAndEmptyArrays': False
                 }
             }, {
                 '$project': {
                     'company_name': '$company_name', 
                     'van_id': '$van_id', 
                     'vin': '$vin',
                     'scan_time': {
                         '$dateToString': {
                             'format': '%Y-%m-%d %H:%M:%S', 
                             'date': '$activities.scan_time'
                         }
                     }
                 }
             }
         ])
     resp_string = encoder.encode(list(resp))
     return json.loads(resp_string), 200
Example #7
0
    def get(self, idx=None):
        
        resp = None
        if idx is None:
            resp = Company.objects.aggregate(*[
    {
        '$lookup': {
            'from': 'schedule_wave', 
            'localField': 'company_id', 
            'foreignField': 'company_id', 
            'as': 'waves'
        }
    }, {
        '$unwind': {
            'path': '$waves', 
            'includeArrayIndex': 'index', 
            'preserveNullAndEmptyArrays': False
        }
    }, {
        '$project': {
            '_id': '$$REMOVE',
            'company_id': '$company_id', 
            'company_name': '$company_name', 
            'wave_id': '$waves.wave_id', 
            'wave_status': '$waves.status', 
            'start_time': {
                '$dateToString': {
                    'format': '%Y-%m-%d %H:%M:%S', 
                    'date': '$waves.start_time'
                }
            }, 
            'end_time': {
                '$dateToString': {
                    'format': '%Y-%m-%d %H:%M:%S', 
                    'date': '$waves.end_time'
                }
            }
        }
    }
])
        else:
            resp = Company.objects.aggregate(*[
                { '$match': { 'company_id' : idx } },
                {
                    '$lookup': {
                        'from': 'schedule_wave', 
                        'localField': 'company_id', 
                        'foreignField': 'company_id', 
                        'as': 'waves'
                    }
                }, {
                    '$unwind': {
                        'path': '$waves', 
                        'includeArrayIndex': 'index', 
                        'preserveNullAndEmptyArrays': False
                    }
                }, {
                    '$project': {
                        '_id': '$$REMOVE', 
                        'wave_id': '$waves.wave_id', 
                        'wave_status': '$waves.status', 
                        'start_time': {
                            '$dateToString': {
                                'format': '%Y-%m-%d %H:%M:%S', 
                                'date': '$waves.start_time'
                            }
                        }, 
                        'end_time': {
                            '$dateToString': {
                                'format': '%Y-%m-%d %H:%M:%S', 
                                'date': '$waves.end_time'
                            }
                        }
                    }
                }
            ])
        
        resp_string = encoder.encode(list(resp))
        
        return json.loads(resp_string), 200