Beispiel #1
0
def InsertTeamMember(team_id, user_id):
    exists_user = False
    all_member = findteamMember(team_id)
    if all_member == 'error':
        return ['failed', 'error could not find member in team', 200]
    for member in all_member:
        if int(member[0]) == int(user_id):
            exists_user = True
    if exists_user == True:
        return ['failed', 'error member already in team member', 200]
    try:
        ps_connection = InitDB()
        if (ps_connection):
            ps_cursor = ps_connection.cursor()
            query = (
                "  insert into team_has_users ( team_id ,user_id ) values ( %s , %s )"
            )
            ps_cursor.execute(query, (
                team_id,
                user_id,
            ))
            ps_connection.commit()
            ps_cursor.close()
            CloseDB(ps_connection)
            return 'success'
    except Exception as e:
        return ['failed', 'user not in user table', 200]
Beispiel #2
0
def insertUser_details(params, user_public_id):
    try:
        user_id = findUserIdfromPublic_id(user_public_id)
        ps_connection = InitDB()
        if (ps_connection):
            ps_cursor = ps_connection.cursor()
            query = (
                "  insert into userdetails( userdetails_employee_id , userdetails_firstname , userdetails_lastname , userdetails_phone , userdetails_email , userdetails_position ,user_id ) values ( %s , %s , %s ,%s ,%s ,%s ,%s) "
            )
            ps_cursor.execute(query, (
                params["userdetails_employee_id"],
                params["userdetails_firstname"],
                params["userdetails_lastname"],
                params["userdetails_phone"],
                params["userdetails_email"],
                params["userdetails_position"],
                user_id,
            ))
            ps_connection.commit()
            ps_cursor.close()
            CloseDB(ps_connection)
            return 'success'
    except Exception as e:
        print(e)
        return e
Beispiel #3
0
def RemoveTeam(team_id):
    try:
        ps_connection = InitDB()
        if (ps_connection):
            ps_cursor = ps_connection.cursor()
            query = ("  delete from team where team_id = %s  ")
            ps_cursor.execute(query, (team_id, ))
            ps_connection.commit()
            ps_cursor.close()
            CloseDB(ps_connection)
            return 'success'
    except Exception as e:
        print(e)
        return 'error'
Beispiel #4
0
def registerAdmin(username ,password ,company_id):
	hashed_password = generate_password_hash(password, method='sha256')
	admin_public_id = str(uuid.uuid4()) 
	try:
		ps_connection  = InitDB()
		if(ps_connection):
			ps_cursor = ps_connection.cursor()
			query = ("  insert into admin( admin_public_id , admin_username , admin_password ,admin_is_active,company_id ) values ( %s , %s , %s ,%s ,%s )" )
			ps_cursor.execute(query, (admin_public_id,  username , hashed_password , '1', company_id , ) ) 
			ps_connection.commit()
			ps_cursor.close()
			CloseDB(ps_connection)      
			return 'success'
	except Exception as e :
	   return 'error'
Beispiel #5
0
def EditTeam(team_name, company_id):
    try:
        ps_connection = InitDB()
        if (ps_connection):
            ps_cursor = ps_connection.cursor()
            query = (
                "  UPDATE  team SET  team_name = %s WHERE company_id = %s ")
            ps_cursor.execute(query, (
                team_name,
                company_id,
            ))
            ps_connection.commit()
            ps_cursor.close()
            CloseDB(ps_connection)
            return 'success'
    except Exception as e:
        return 'error'
Beispiel #6
0
def RemoveTeamMember(team_id, user_id):
    try:
        ps_connection = InitDB()
        if (ps_connection):
            ps_cursor = ps_connection.cursor()
            query = (
                "  delete from team_has_users where team_id = %s and user_id = %s "
            )
            ps_cursor.execute(query, (
                team_id,
                user_id,
            ))
            ps_connection.commit()
            ps_cursor.close()
            CloseDB(ps_connection)
            return 'success'
    except Exception as e:
        return 'error'
Beispiel #7
0
def InsertTeam(team_name, team_avatar, admin_id, company_id):
    dt = datetime.datetime.now(tz)
    team_uuid = str(uuid.uuid4())
    try:
        ps_connection = InitDB()
        if (ps_connection):
            ps_cursor = ps_connection.cursor()
            query = (
                "  insert into team ( team_public_id , team_name , team_avatar ,team_is_active,created_on , admin_id , company_id ) values ( %s , %s , %s ,%s ,%s ,%s ,%s )"
            )
            ps_cursor.execute(query, (team_uuid, team_name, team_avatar, '1',
                                      dt, admin_id, company_id))
            ps_connection.commit()
            ps_cursor.close()
            CloseDB(ps_connection)
            return 'success'
    except Exception as e:
        print(e)
        return 'error'
Beispiel #8
0
def update_userdetails(params, user_public_id):
    try:
        column = ''
        for column_name in params.keys():
            column = str(column) + str(column_name + " = '" +
                                       params[column_name] + "' ,")
        sql_prepare = (column[0:(len(column)) - 1])
        user_id = findUserIdfromPublic_id(user_public_id)
        sql_builder = "UPDATE userdetails SET " + str(
            sql_prepare) + " WHERE user_id = %s "
        ps_connection = InitDB()
        if (ps_connection):
            ps_cursor = ps_connection.cursor()
            ps_cursor.execute(sql_builder, (user_id, ))
            ps_connection.commit()
            ps_cursor.close()
            CloseDB(ps_connection)
            return ['success', 'Edited : ' + str(user_public_id), 200]
    except Exception as e:
        return ['success', 'failed ' + e.message, 500]
Beispiel #9
0
def RegisterCompany_with_groupsystem(current_user):
    if request.content_type != 'application/json':
        return jsonify({"status": "failed", "message": "Invalid content-type. Must be application/json." }), 400
    try:
        params = request.get_json()
        company_name = params["company_name"]
        uuid_entry = str(uuid.uuid4()) 
        ps_connection  = InitDB()
        if(ps_connection):
            ps_cursor = ps_connection.cursor()
            query = ("  insert into company( company_name , company_public_id , company_is_active ,created_on ) values ( %s , %s , %s ,%s )" )
            ps_cursor.execute(query, (company_name, uuid_entry , '1', datetime.datetime.now() ) )
            ps_connection.commit()
            ps_cursor.close()
            CloseDB(ps_connection)      
            token = request.headers["Authorization"]
            access_token = token.split(" ")[1]
            status_code  = create_storage(access_token ,uuid_entry )    
            if int (status_code) == 201 :   
                return jsonify({"status" : 'success' , "company_public_id" : uuid_entry } ),201
    except (Exception, psycopg2.Error) as error:
        return jsonify({'status' : 'falied' , "message" :  error} ),500
Beispiel #10
0
def register_token(token, member_public_id):
    try:

        ps_connection = InitDB()
        if (ps_connection):
            token = str(token)
            member_public_id = str(member_public_id)
            ps_cursor = ps_connection.cursor()
            query = (
                "INSERT INTO system_token(system_token , member_public_id , created_on)  VALUES (%s , %s , %s ) "
            )
            ps_cursor.execute(query, (
                token,
                member_public_id,
                dt,
            ))
            ps_cursor.close()
            ps_connection.commit()
            CloseDB(ps_connection)
            return 'success'
    except (Exception) as e:
        print(e)
        return e