Ejemplo n.º 1
0
async def timer_toogle(taskH_id):
    try:
        Now = datetime.datetime.now()
        f_taskH = TaskHistoryDB.find_one({'_id': ObjectId(taskH_id)})

        # 멈춤
        if f_taskH['Status'] is 'working':
            TaskHistoryDB.update_one({'_id': ObjectId(taskH_id)}, {
                '$set': {
                    'Status': 'pause',
                    'Time':
                    str(Now - f_taskH['StartDate'] - f_taskH['RestTime']),
                    'TmpDate': Now
                }
            })

        # 재시작
        elif f_taskH['Status'] is 'pause':
            TaskHistoryDB.update_one({'_id': ObjectId(taskH_id)}, {
                '$set': {
                    'Status': 'working',
                    'RestTime':
                    str(Now - f_taskH['TmpDate'] + f_taskH['RestTime'])
                }
            })
        return ''
    except:
        traceback.print_exc()
        return '', 500
Ejemplo n.º 2
0
async def task_delete(taskH_id):
    try:
        find_TskH = TaskHistoryDB.find_one({'_id': ObjectId(taskH_id)})
        if find_TskH is None:
            return dumps({'err': '요청하신 업무는 없습니다.'}), 401

        TaskHistoryDB.delete_one({'_id': ObjectId(taskH_id)})
        return ''
    except:
        traceback.print_exc()
        return '', 500
Ejemplo n.º 3
0
async def W_Login():
    Data = await request.get_json()
    try:
        req_email = Data['email']
        req_psw = Data['password']

        if req_email is None or req_email == '':
            return '', 400
        if req_psw is None or req_psw == '':
            return '', 400

        find_user = userDB.find_one({'Id': req_email})

        if find_user != None:
            if find_user['Password'] == hashlib.md5(
                    req_psw.encode()).hexdigest():

                AccessToken = accessJWT(str(find_user['_id']))
                RefreshToken = refreshJWT(str(find_user['_id']))
                print(AccessToken)
                print(RefreshToken)
                User = userDB.aggregate([{
                    '$match': {
                        '_id': ObjectId(str(find_user['_id']))
                    }
                }, {
                    '$lookup': {
                        'from': 'Department',
                        'localField': 'Department',
                        'foreignField': '_id',
                        'as': 'DepartmentInfo'
                    }
                }, {
                    '$unwind': {
                        'path': "$DepartmentInfo",
                        'preserveNullAndEmptyArrays': True
                    }
                }, {
                    '$project': {
                        'Password': 0,
                        '_id': 0
                    }
                }])

                return dumps({
                    'token': AccessToken,
                    'rtoken': RefreshToken,
                    'User': User
                })
        return '', 401
    except:
        traceback.print_exc()
        return '', 500
Ejemplo n.º 4
0
async def timer_start(taskH_id):
    try:
        Now = datetime.datetime.now()
        TaskHistoryDB.update_one(
            {'_id': ObjectId(taskH_id)},
            {'$set': {
                'Status': 'working',
                'StartDate': Now
            }})
        return ''
    except:
        traceback.print_exc()
        return '', 500
Ejemplo n.º 5
0
async def ResetAuth():

    Data = json.load(await request.get_date())
    try:
        TokenInfo = refreshJWT(Data['Token'])
        if TokenInfo is not False:
            return dumps({
                'token': accessJWT(TokenInfo),
                'rtoken': refreshJWT(TokenInfo)
            })
        else:
            return '', 400
    except:
        traceback.print_exc()
        return '', 500
Ejemplo n.º 6
0
async def timer_switch(taskH_id):
    try:
        Now = datetime.datetime.now()
        f_taskH = TaskHistoryDB.find_one({'_id': ObjectId(taskH_id)})

        TaskHistoryDB.update_one({'_id': ObjectId(taskH_id)}, {
            '$set': {
                'Status': 'pause',
                'Time': str(Now - f_taskH['StartDate'] - f_taskH['RestTime']),
                'TmpDate': Now
            }
        })
        return ''
    except:
        traceback.print_exc()
        return '', 500
Ejemplo n.º 7
0
 async def patch(self):
     Data = json.loads(await request.get_data())
     Now = datetime.datetime.now() 
     try:
         find_Atd = AttemdanceDB.find_one({'_id': ObjectId(Data['Atdid'])})
         if find_Atd is 'None':
             return '', 401
         AttemdanceDB.update_one({'_id': ObjectId(Data['Atdid'])},
                                     {'$set':
                                         {'EndDate': Now,
                                          'Time': str(Now - find_Atd['StartDate'])}
                                     })
         return ''
     except :
         traceback.print_exc()
         return '', 500
Ejemplo n.º 8
0
 async def post(self):
     Data = await request.get_json()
     Now = datetime.datetime.now()  
     try:
         req_id = Data['id']
         print('test: ',req_id)
         if req_id is None:
             return dumps({'H':0, 'M':0, 'S':0})
         else:
             find_time = AttemdanceDB.find_one({'_id': ObjectId(req_id)})
             start = find_time['StartDate']
             Time = str(Now - start)
             Result = datetime.datetime.strptime(Time.split('.')[0],'%H:%M:%S')
             Sec  = (Result.hour*60*60) + (Result.minute*60) + (Result.second)
             return dumps(Sec)
             # return dumps({'H': Result.hour, 'M':Result.minute, 'S':Result.second}), 200
     except :
         traceback.print_exc()
         return '', 500
Ejemplo n.º 9
0
async def task_create(task_id):
    Data = await request.get_json()
    Now = datetime.datetime.now()
    try:
        req_dsc = Data['dscription']
        TaskHistoryDB.insert_one({
            'StartDate': Now,
            'EndDate': None,
            'TmpDate': None,
            'Time': None,
            'Status': 'ready',
            'Task': ObjectId(task_id),
            'Description': req_dsc,
            'User': ObjectId('606d71d2a96b3d38380aed1b'),
            # 'User': ObjectId(UserId['_id']),
            'RestTime': None
        })
        return ''
    except:
        traceback.print_exc()
        return '', 500
Ejemplo n.º 10
0
async def teask_list_get():
    try:
        # find_user = userDB.find_one({'_id': ObjectId(UserId)})
        find_user = userDB.find_one(
            {'_id': ObjectId('606d71d2a96b3d38380aed1b')})
        if find_user is None:
            return '', 401
        agg_TaskList = departmentDB.aggregate([
            {
                '$match': {
                    '_id': ObjectId("606fb0585f35166a1fdd41fc")
                }
                # '$match' : {'_id': ObjectId(find_user['Department']) }
            },
            {
                '$lookup': {
                    'from': 'Tasks',
                    'localField': 'TaskList',
                    'foreignField': '_id',
                    'as': 'TaskInfo'
                }
            },
            {
                '$project': {
                    '_id': 0,
                    'Administor': 0,
                    'Department': 0,
                    'TaskList': 0
                }
            }
            # {
            #      $project: { TaskInfo: 1 }
            # }
        ])
        TL = list(agg_TaskList)
        return dumps(TL[0])
        # return dumps(agg_TaskList)
    except:
        traceback.print_exc()
        return '', 500
Ejemplo n.º 11
0
    async def get(self):
    # async def post(self, UserId):
        Now = datetime.datetime.now()  
        Data = await request.get_json()
        try:
            AttemdanceDB.insert_one({
                    'StartDate': Now,
                    'EndDate': None,
                    'Time': None,
                    # 'User': ObjectId(UserId)
                    'User': ObjectId("606d71d2a96b3d38380aed1b")
                })

            find_time = AttemdanceDB.find_one({
                'EndDate': None,
                'User': ObjectId("606d71d2a96b3d38380aed1b")
            })

            return dumps({'TimeOid': find_time['_id'], 'H':0, 'M': 0, 'S': 0}), 205
        except:
            traceback.print_exc()
            return '', 500
Ejemplo n.º 12
0
async def task_get(taskH_id):
    try:
        agg_taskH = TaskHistoryDB.aggregate([{
            '$match': {
                '_id': ObjectId(taskH_id)
            }
        }, {
            '$lookup': {
                'from': 'Tasks',
                'localField': 'Task',
                'foreignField': '_id',
                'as': 'TaskInfo'
            }
        }, {
            '$unwind': {
                'path': '$TaskInfo',
                'preserveNullAndEmptyArrays': True
            }
        }])
        return dumps(agg_taskH)
    except:
        traceback.print_exc()
        return '', 500