diff --git a/packages/comty.js/src/models/nfc/index.js b/packages/comty.js/src/models/nfc/index.js new file mode 100644 index 00000000..2305c13a --- /dev/null +++ b/packages/comty.js/src/models/nfc/index.js @@ -0,0 +1,56 @@ +import request from "../../handlers/request" + +export default class NFCModel { + static async getOwnTags() { + const { data } = await request({ + method: "GET", + url: `/nfc/tags` + }) + + return data + } + + static async getTagById(id) { + if (!id) { + throw new Error("ID is required") + } + + const { data } = await request({ + method: "GET", + url: `/nfc/tags/${id}` + }) + + return data + } + + static async getTagBySerial(serial) { + if (!serial) { + throw new Error("Serial is required") + } + + const { data } = await request({ + method: "GET", + url: `/nfc/tag/serial/${serial}` + }) + + return data + } + + static async registerTag(serial, payload) { + if (!serial) { + throw new Error("Serial is required") + } + + if (!payload) { + throw new Error("Payload is required") + } + + const { data } = await request({ + method: "POST", + url: `/nfc/tag/${serial}`, + data: payload + }) + + return data + } +} \ No newline at end of file