Beispiel #1
0
 def get(self, id):
     #GET the Product by Id
     product = Product.find_by_id(id)
     if product:
         return product.json()
     else:
         return {'message' : 'product not found'}, 404
Beispiel #2
0
 def put(self):
     data = ProductResource.parser.parse_args()
     product = Product.find_by_id(data['id'])
     if not product:
         return {'message' : "Product with id: '{}' does not exist. Please create the Product first ".format(id)}
     else:
         product.price = data['price']
         product.save_to_db()
         return product.json()
Beispiel #3
0
    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)
Beispiel #4
0
    def post(self):
        '''CREATE a new Product instance in the database'''
        order_request = request.json['orders']
        order = Order(order_request['status'], order_request['date'],
                      order_request['customer_id'])
        product_list = order_request['products']

        for prod in product_list:
            product = Product.find_by_id(prod['id'])
            order_product = OrderProduct(prod['quantity'],
                                         int(prod['quantity']) * product.price)
            order_product.product = product
            order.products.append(order_product)
        order.save_to_db()

        return {'message': 'Order created successfully'}
Beispiel #5
0
 def resolve_product(root, info, _id):
     return ProductModel.find_by_id(_id)