rbs@u2
Home
Php_u2
Html #1
Html #2
Html #3
Html #4
JS #1
JS #2
JS #3
JS #4
JsApi #1
JsApi #2
JsApi #3
JsApi #4
JsApi_u4
all-files
ori-v2
master
user
Logout
dsg
tool css
bootstrtap 5.3
auth
profile
waste
waste_group
venue
vehicle
event
comment
notification
discover
post
scanner
to_delete
const fetch = require('node-fetch'); async function scanner(v) { let url=`${v.api}/scanner/get-linked-entity/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function scanner(v) { let url=`${v.api}/scanner/link-qr-code-entity/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function scanner(v) { let url=`${v.api}/scanner/unlink-qr-code-entity/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } async function scanner(v) { let url=`${v.api}/scanner/verify-qr-code/${v.param}`; console.log(url) const res = await fetch(url,{ method: 'POST', body: JSON.stringify(v.body), headers: { 'Content-Type': 'application/json', } }); return res } const scanner = { scanner, scanner, scanner, scanner, } module.exports = scanner
Save
Save
export const getIDFromQrCode = async (decodedText) => { const response = await fetch(`${API_URL}/wp-json/app/v1/get-linked-entity`, { cache: "no-cache", method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ qr_code: decodedText }), }) const data = await response.json() if ((data && data.error) || response.status === 404) { throw new Error(data.error) } return data } const linkProfile = async (decodedText) => { const user = await getSessionUser() const response = await fetch(`${API_URL}/wp-json/app/v1/link-qr-code-entity`, { cache: "no-cache", method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ entity_id: user?.id, qr_code: decodedText, entity_type: "profile" }), }) const data = await response.json() return data } const unlinkProfile = async (decodedText) => { const user = await getSessionUser() const response = await fetch(`${API_URL}/wp-json/app/v1/unlink-qr-code-entity`, { cache: "no-cache", method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ qr_code: decodedText, entity_id: user?.id, entity_type: "profile" }), }) const data = await response.json() return data } export const verifyScan = async (decodedText) => { const user = await getSessionUser() const response = await fetch(`${API_URL}/wp-json/app/v1/verify-qr-code`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user?.id, qr_code: decodedText }), }) const data = await response.json() return data }
import { getSessionUser } from "./auth.js" import { API_URL } from "./consts.js" export const verifyScan = async (decodedText) => { const user = await getSessionUser() const response = await fetch(`${API_URL}/scanner/verify-qr-code`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ user_id: user?.id, qr_code: decodedText }), }) const data = await response.json() return data } const linkProfile = async (decodedText) => { const user = await getSessionUser() const response = await fetch(`${API_URL}/scanner/link-qr-code-entity`, { cache: "no-cache", method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ entity_id: user?.id, qr_code: decodedText, entity_type: "profile" }), }) const data = await response.json() return data } const unlinkProfile = async (decodedText) => { const user = await getSessionUser() const response = await fetch(`${API_URL}/scanner/unlink-qr-code-entity`, { cache: "no-cache", method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ qr_code: decodedText, entity_id: user?.id, entity_type: "profile" }), }) const data = await response.json() return data } export const getIDFromQrCode = async (decodedText) => { const response = await fetch(`${API_URL}/scanner/get-linked-entity`, { cache: "no-cache", method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ qr_code: decodedText }), }) const data = await response.json() if ((data && data.error) || response.status === 404) { throw new Error(data.error) } return data } export const handleLink = async (result) => { if (!result) { return } try { const response = await linkProfile(result?.qr_code) return response } catch (e) { console.error("Error linking profile", e) return { status: 'error', text: 'Error linking profile' } } } export const handleUnlink = async (result) => { if (!result) { return } try { const response = await unlinkProfile(result?.qr_code) if (response.status === 'error') { return { type: 'error', text: response.message } } else { return { type: 'success', text: response.message } } } catch (e) { console.error("Error unlinking profile", e) return { type: 'error', text: 'Error unlinking profile' } } }
Save
scanner
-- get-linked-entity
-- link-qr-code-entity
-- unlink-qr-code-entity
-- verify-qr-code