def mutate(root, info, email, company_id): company = CompanyModel.find_by_id(company_id) if not company: raise Exception("company not found") user = User.find_by_email(email) if user: if user.company: raise Exception("user already belongs to a company") msg = f"We would like you to join our company '{company.name}'.\n" \ f"Please accept thought this link </>" send_email(email, msg) # TODO send invitation return AddMember(ok=True) # TODO create a url for sign up msg = f"We would like you to join our company '{company.name}'.\n" \ f"Please sign up to this link </>" send_email(email, msg) return AddMember(ok=True)
def mutate(root, info, company_id, product_data): company = CompanyModel.find_by_id(company_id) if not company: raise Exception("Company doesn't exist!") product = ProductModel(**product_data, company=company_id) product.save() return NewProduct(product=product)
def mutate(root, info, company_id, role_data): company = CompanyModel.find_by_id(company_id) if not company: raise Exception("Company doesn't exist!") role = EmbeddedRole(**role_data) company.roles.append(role) company.save() return AddRoles(company=company)
def mutate(root, info, company_id, product_id, campaign_data): company = CompanyModel.find_by_id(company_id) if not company: raise Exception("Company not found!") product = ProductModel.find_by_id(product_id) if not product: raise Exception("Product not found!") campaign = CampaignModel(**campaign_data, product=product, company=company) campaign.save() return NewCampaign(campaign=campaign)
def get(): data = UserApplicationsList.parser.parse_args() user_id = User(None, None, None, data['user_email'], None).find_id_by_email() companies = UserCompany(None, user_id, None).find_all_applied_companies() all_companies = [] if companies: for company in companies: all_companies.append( JobData.json(Company.find_by_id(company[2]))) return {"all_applications": all_companies}, 200
def mutate(root, info, company_id, product_category_data): company = CompanyModel.find_by_id(company_id) if not company: raise Exception("Company doesn't exist!") product_category = ProductCategoryModel.find_one_by( "name", product_category_data.name) if product_category: company.product_categories.append(product_category) company.save() return ProductCategory(company=company, product_category=product_category) product_category = ProductCategoryModel(**product_category_data) product_category.save() company.product_categories.append(product_category) company.save() return ProductCategory(company=company)
def resolve_company(root, info, _id): return CompanyModel.find_by_id(_id)