def delete(self, id): """ Delete a sale """ sale = Db.get_s_by_id(id) email = get_jwt_identity() user = Db.get_user(email=email) store_id = user.store_id if sale.store_id != store_id: msg = 'That record does not exist' return abort(404, msg) sk = sale.json_dump() Db.sales.remove(sale) return {"status": "Deleted!", "data": sk}, 200
def get(self, id): """ Get a specicific sale record """ email = get_jwt_identity() user = Db.get_user(email=email) store_id = user.store_id sale = Db.get_s_by_id(id) if sale.store_id != store_id: msg = 'That record does not exist' return abort(404, msg) sk = sale.json_dump() return {"status": "Success!", "data": sk}, 200
def put(self, id): """ Update a sale """ s = Db.get_s_by_id(id) email = get_jwt_identity() user = Db.get_user(email=email) store_id = user.store_id if s.store_id != store_id: msg = 'Sale does not exist' abort(404, msg) json_data = request.get_json(force=True) sales_validator(json_data) number = json_data['number'] s.number = number return {"status": "Success!", "data": s.json_dump()}, 200