소스 검색

Refactor cancelStoreNumber.js to use socket.io-client and axios for API requests

xiongzhu 1 년 전
부모
커밋
78bd85ab7c
1개의 변경된 파일39개의 추가작업 그리고 0개의 파일을 삭제
  1. 39 0
      cancelStoreNumber.js

+ 39 - 0
cancelStoreNumber.js

@@ -0,0 +1,39 @@
+import { io } from "socket.io-client"
+import axios from "axios"
+import { setTimeout } from "timers/promises"
+import chalk from "chalk"
+const axiosInstance = axios.create({
+    baseURL: "http://47.98.225.28/api",
+    headers: {
+        Authorization:
+            "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InpvdW1hQWRtaW4iLCJzdWIiOjEsInJvbGVzIjpbImFkbWluIl0sImlhdCI6MTcyNjU4MTk1OH0.dQiHFYaDDa1qp4OpEHaH5SCZ9dafJ8uO9fAAc8HZgAo"
+    }
+})
+
+const {
+    data: { items: devices }
+} = await axiosInstance.post("/device", {
+    page: { page: 1, limit: 1000 },
+    search: {
+        where: { online: true, storing: true },
+        order: { name: "ASC" }
+    }
+})
+
+for (let device of devices) {
+    console.log(chalk.green(`${device.name} cancelStoreNumber`))
+    axiosInstance
+        .post(
+            `/device/${device.id}/sendMessage`,
+            {
+                action: "cancelStoreNumber",
+                data: {}
+            },
+            {
+                timeout: 60000
+            }
+        )
+        .catch(e => {
+            console.log(chalk.red(e.message))
+        })
+}