order.mjs 789 B

1234567891011121314151617181920212223242526272829303132
  1. import axios from 'axios'
  2. import qs from 'qs'
  3. const http = axios.create({
  4. baseURL: 'http://localhost:8080'
  5. })
  6. const { data: token } = await http.post(
  7. 'http://localhost:8080/auth/login',
  8. qs.stringify({
  9. username: '15077886171',
  10. password: '123456'
  11. })
  12. )
  13. http.defaults.headers.common['Authorization'] = `Bearer ${token}`
  14. const {
  15. data: { content: list }
  16. } = await http.post('/product/list', {
  17. page: 0,
  18. size: 20,
  19. sort: 'delayTo,asc;sales,desc;',
  20. query: { batchId: '11548', status: 'IN_STOCK' }
  21. })
  22. for (let i = 0; i < 3; i++) {
  23. http.post('/order/createOrder', `productId=${list[0].id}`)
  24. .then(res => {
  25. console.log('success')
  26. })
  27. .catch(e => {
  28. console.log(e.response.data.error)
  29. })
  30. }