|
| 1 | +/** |
| 2 | + * Copyright (C) 2021 PythonCoderAS |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | +import axios from "axios"; |
| 18 | +import objectToWrapper from "@healthscreening/object-to-wrapper" |
| 19 | +import { screeningTypeType } from "@healthscreening/screening-types"; |
| 20 | + |
| 21 | +export interface SendRequestParams { |
| 22 | + firstName: string; |
| 23 | + lastName: string; |
| 24 | + email: string; |
| 25 | + isVaxxed: boolean; |
| 26 | + type: screeningTypeType; |
| 27 | +} |
| 28 | + |
| 29 | +export interface SubmitParams { |
| 30 | + Type: screeningTypeType; |
| 31 | + IsOther: boolean; |
| 32 | + IsStudent: 0 | 1; |
| 33 | + FirstName: string; |
| 34 | + LastName: string; |
| 35 | + Email: string; |
| 36 | + State: string; |
| 37 | + Location: string; |
| 38 | + Floor: string | null; |
| 39 | + Answer1: 0 | 1; |
| 40 | + Answer2: 0 | 1; |
| 41 | + Answer3?: 0 | 1; |
| 42 | + Answer4?: 0 | 1; |
| 43 | +} |
| 44 | +export default async function completeScreening( |
| 45 | + options: SendRequestParams |
| 46 | +): Promise<boolean> { |
| 47 | + // We assume the browser has been started already. |
| 48 | + |
| 49 | + const obj: SubmitParams = { |
| 50 | + Type: options.type || "G", |
| 51 | + IsOther: false, |
| 52 | + IsStudent: 1, |
| 53 | + FirstName: options.firstName, |
| 54 | + LastName: options.lastName, |
| 55 | + Email: options.email, |
| 56 | + State: "NY", |
| 57 | + Location: "X445", |
| 58 | + Floor: null, |
| 59 | + Answer1: 0, |
| 60 | + Answer2: 0, |
| 61 | + }; |
| 62 | + if (options.isVaxxed) { |
| 63 | + obj.Answer3 = 0; |
| 64 | + obj.Answer4 = 0; |
| 65 | + } else { |
| 66 | + obj.Answer3 = 1; |
| 67 | + } |
| 68 | + const response = await axios.post( |
| 69 | + "https://healthscreening.schools.nyc/home/submit", |
| 70 | + new URLSearchParams(objectToWrapper(obj)).toString(), |
| 71 | + { |
| 72 | + headers: { |
| 73 | + accept: "*/*", |
| 74 | + "accept-language": "en-US,en;q=0.9,bn;q=0.8", |
| 75 | + "content-type": "application/x-www-form-urlencoded; charset=UTF-8", |
| 76 | + }, |
| 77 | + } |
| 78 | + ); |
| 79 | + return response.status / 100 < 4; |
| 80 | +} |
0 commit comments