def post(self, campaign_name): db.create_all() db.session.commit() if CampaignModel.find_by_name(campaign_name): return { 'message': "An Record with name '{}' already exists.".format( campaign_name) }, 400 data = self.parser.parse_args() campaign = CampaignModel( campaign_name, **data, ) campaign.created_by = 1 campaign.created_on = datetime.now() campaign.modified_by = 0 campaign.deleted_by = 0 campaign.start_date = datetime.now() campaign.end_date = datetime.now() campaign.days = 1 try: campaign.save_to_db() except Exception as e: return { "message": "An error occurred while inserting the Record.'{}'".format(e) } return campaign.json(), 201
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(self): connection = sqlite3.connect('data.db') cursor = connection.cursor() query = "SELECT * FROM campaigns" result = cursor.execute(query) campaigns = [] for row in result: campaign_model = CampaignModel(row[0], row[1], row[2], row[3]) campaigns.append(campaign_model.json()) connection.close() return {'campaigns': campaigns}
def post(self): data = self.parser.parse_args() campaign = CampaignModel(**data) campaign.created_by = 1 campaign.created_on = datetime.now() campaign.modified_by = 0 campaign.deleted_by = 0 campaign.modified_on = None campaign.deleted_on = None try: validateObj = CampaignModel.validateData(data, request) if type(validateObj) is dict: return {"success": False, "errors": validateObj}, 400 if CampaignModel.find_by_name(data['campaign_name']): return { "success": False, "message": "A campaign with that Record Name already exists" }, 400 campaign_name = data['campaign_name'] description = data['description'] target_locations = data['target_locations'] exclude_locations = data['exclude_locations'] ######################## CHECKING STRING HAS VALUE OR NOT################################################### if (campaign_name.strip() and description.strip() and target_locations.strip() and exclude_locations.strip()): campaign.save_to_db() campaign.token = encodeID(campaign.campaign_id) campaign.save_to_db() else: return { "success": False, "message": "String Should not be empty" } except Exception as e: return { "message": "An error occurred creating the Record.'{}'".format(e) }, 500 return campaign.json(), 201