import {actionPromise, gql} from "./index";



const actionOrdersFind = (data) => {

    return async dispatch => {

        const queryJson = JSON.stringify(
            [{"___owner" : data}]
        )

        await dispatch(actionPromise("ordersFind", gql (
            `query orders ($query: String) {
                OrderFind(query: $query){
                  total
                  _id
                  orderGoods {count, _id, price, good {name, _id, price, images {url}}}
                  createdAt
                  owner {
                    login
                    _id
                  }
                  
                }
            }`, {query: queryJson}
        )))
    }
}

const actionOrderFindOne = (_id) => {
    return async dispatch => {
        const queryJson = JSON.stringify([{
            "_id": `${_id}`

          }]);


          await dispatch(actionPromise("oneOrder", gql(
              `query oneOrder($query: String) {
                  OrderFindOne(query: $query) {
                    total
                    _id
                    orderGoods {count, _id, price, good {name, _id, price, images {url}}}
                    createdAt
                  }
              }`, {query: queryJson}
          )))
    }
}



export {actionOrdersFind, actionOrderFindOne};