From b31c7cc0f966c0e0d29edbbbb6745f7de9d54515 Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Mon, 19 Jun 2023 19:21:48 +0000 Subject: [PATCH] added nfc model --- packages/comty.js/src/models/nfc/index.js | 56 +++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 packages/comty.js/src/models/nfc/index.js 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