Update call page for new API
This commit is contained in:
parent
8212339da4
commit
3c9d92a497
@ -3,7 +3,7 @@ import { navbar } from '../../utils/navbar.js';
|
|||||||
function generateCallHTML(phoneNumber, name, callcount, session) {
|
function generateCallHTML(phoneNumber, name, callcount, session) {
|
||||||
const head = `<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><link rel="stylesheet" type="text/css" href="/assets/css/form.css" /><title>AutoCallMenu</title></head>`;
|
const head = `<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><link rel="stylesheet" type="text/css" href="/assets/css/form.css" /><title>AutoCallMenu</title></head>`;
|
||||||
const form = `
|
const form = `
|
||||||
<form action="/api/contacts/call" method="post">
|
<form action="javascript:callFromForm()" id="callForm">
|
||||||
<input type="hidden" name="phone" value="${phoneNumber}">
|
<input type="hidden" name="phone" value="${phoneNumber}">
|
||||||
<label class="switch">
|
<label class="switch">
|
||||||
<input type="checkbox" name="vote">
|
<input type="checkbox" name="vote">
|
||||||
@ -14,8 +14,31 @@ function generateCallHTML(phoneNumber, name, callcount, session) {
|
|||||||
<button class="submit" type="submit">CONFIRMER</button>
|
<button class="submit" type="submit">CONFIRMER</button>
|
||||||
</form>
|
</form>
|
||||||
`;
|
`;
|
||||||
const body = `<body>${navbar(session)}<h1>Bienvenue :3</h1><h2>Appel: ${name} - ${phoneNumber}</h2><p>${callcount} appels restants</p>${form}</body>`;
|
const body = `<body>${js}${navbar(session)}<h1>Bienvenue :3</h1><h2>Appel: ${name} - ${phoneNumber}</h2><p>${callcount} appels restants</p>${form}</body>`;
|
||||||
return `<!DOCTYPE html><html>${head}${body}</html>`;
|
return `<!DOCTYPE html><html>${head}${body}</html>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const js = '\
|
||||||
|
<script>\
|
||||||
|
function callFromForm() {\
|
||||||
|
const form = document.getElementById("callForm");\
|
||||||
|
fetch(`/api/call/${form.phone.value}`, {\
|
||||||
|
method: "POST",\
|
||||||
|
body: JSON.stringify({\
|
||||||
|
vote: form.vote.value == "on" ? 1 : 0,\
|
||||||
|
}),\
|
||||||
|
headers: {\
|
||||||
|
"Content-type": "application/json; charset=UTF-8"\
|
||||||
|
}\
|
||||||
|
})\
|
||||||
|
.then(async (response) => {\
|
||||||
|
const res = await response.json();\
|
||||||
|
console.log(res);\
|
||||||
|
if(!response.ok) return alert(res.message);\
|
||||||
|
location.reload();\
|
||||||
|
});\
|
||||||
|
}\
|
||||||
|
</script>\
|
||||||
|
';
|
||||||
|
|
||||||
export { generateCallHTML };
|
export { generateCallHTML };
|
||||||
|
14
src/html/pages/api/contacts/call.js
Normal file
14
src/html/pages/api/contacts/call.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { permissionBits } from "../../../../../utils/permissions.js";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
path: "/api/call/:phone",
|
||||||
|
requiresLogin: true,
|
||||||
|
permissions: permissionBits.ADMIN,
|
||||||
|
type: "post",
|
||||||
|
async execute(request, response) {
|
||||||
|
const { phone } = request.params;
|
||||||
|
const { vote } = request.body;
|
||||||
|
await global.database.contacts.update({ called: 1, vote: vote }, { where: { phone: phone } });
|
||||||
|
response.status(201).send({ message: `Vote registered` });
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user