typescript migration

This commit is contained in:
realaravinth
2021-05-01 19:22:44 +05:30
parent 90424219f5
commit 9c6398a7c5
55 changed files with 857 additions and 921 deletions

View File

@@ -18,17 +18,32 @@
import ROUTES from '../../api/v1/routes';
import VIEWS from '../../views/v1/routes';
import isBlankString from '../../utils/genJsonPayload';
import isBlankString from '../../utils/isBlankString';
import genJsonPayload from '../../utils/genJsonPayload';
//import '../forms.scss';
const login = e => {
const login = (e: Event) => {
e.preventDefault();
let username = document.getElementById('username').value;
isBlankString(e, username, 'username');
InputEvent
const usernameElement: HTMLInputElement = <HTMLInputElement>document.getElementById('username');
if (usernameElement === null) {
console.debug("Username element is null");
return;
}
let username = usernameElement.value;
isBlankString(e, username, 'username');
// isBlankString(e);//, username, 'username');
const passwordElement: HTMLInputElement = <HTMLInputElement>document.getElementById('password');
if (passwordElement === null) {
console.debug("Password is null");
return;
}
let password = passwordElement.value;
let password = document.getElementById('password').value;
let payload = {
username,
password,
@@ -45,6 +60,6 @@ const login = e => {
};
export const index = () => {
let form = document.getElementById('form');
let form = <HTMLFontElement>document.getElementById('form');
form.addEventListener('submit', login, true);
};

View File

@@ -20,7 +20,7 @@ import ROUTES from '../../api/v1/routes';
import genJsonPayload from '../../utils/genJsonPayload';
const checkEmailExists = async () => {
let email = document.getElementById('email');
let email = <HTMLInputElement>document.getElementById('email');
let val = email.value;
let payload = {
val,

View File

@@ -1,78 +0,0 @@
/*
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import ROUTES from '../../api/v1/routes';
import VIEWS from '../../views/v1/routes';
import isBlankString from '../../utils/genJsonPayload';
import genJsonPayload from '../../utils/genJsonPayload';
import userExists from './userExists';
import {checkEmailExists} from './emailExists';
//import '../forms.scss';
const registerUser = async e => {
e.preventDefault();
let username = document.getElementById('username').value;
isBlankString(e, username, 'username');
let password = document.getElementById('password').value;
let passwordCheck = document.getElementById('password-check').value;
if (password != passwordCheck) {
return alert("passwords don't match, check again!");
}
let exists = await userExists();
if (exists) {
return;
}
let email = document.getElementById('email').value;
if (!email.replace(/\s/g, '').length) {
email = null;
} else {
exists = await checkEmailExists();
if (exists) {
return;
}
}
let payload = {
username,
password,
email,
};
let res = await fetch(ROUTES.registerUser, genJsonPayload(payload));
if (res.ok) {
alert('success');
window.location.assign(VIEWS.loginUser);
} else {
let err = await res.json();
alert(`error: ${err.error}`);
}
};
export const index = () => {
let form = document.getElementById('form');
form.addEventListener('submit', registerUser, true);
let username = document.getElementById('username');
username.addEventListener('input', userExists, false);
};

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import ROUTES from '../../api/v1/routes';
import VIEWS from '../../views/v1/routes';
import isBlankString from '../../utils/isBlankString';
import genJsonPayload from '../../utils/genJsonPayload';
import userExists from './userExists';
import {checkEmailExists} from './emailExists';
//import '../forms.scss';
const usernameElement = <HTMLInputElement>document.getElementById('username');
const emailElement = <HTMLInputElement>document.getElementById('email');
const passwordElement = <HTMLInputElement>document.getElementById('password');
const registerUser = async (e: Event) => {
e.preventDefault();
let username = usernameElement.value;
isBlankString(e, username, 'username');
//isBlankString(e);//, username, 'username');
let password = passwordElement.value;
const passwordCheckElement = <HTMLInputElement>(
document.getElementById('password-check')
);
let passwordCheck = passwordCheckElement.value;
if (password != passwordCheck) {
return alert("passwords don't match, check again!");
}
let exists = await userExists();
if (exists) {
return;
}
let email: string|null = emailElement.value;
if (!email.replace(/\s/g, '').length) {
email = null;
} else {
exists = await checkEmailExists();
if (exists) {
return;
}
}
let payload = {
username,
password,
email,
};
let res = await fetch(ROUTES.registerUser, genJsonPayload(payload));
if (res.ok) {
alert('success');
window.location.assign(VIEWS.loginUser);
} else {
let err = await res.json();
alert(`error: ${err.error}`);
}
};
export const index = () => {
let form = <HTMLFontElement>document.getElementById('form');
form.addEventListener('submit', registerUser, true);
usernameElement.addEventListener('input', userExists, false);
};

View File

@@ -21,7 +21,7 @@ import genJsonPayload from '../../utils/genJsonPayload';
//export const checkUsernameExists = async () => {
async function userExists() {
let username = document.getElementById('username');
let username = <HTMLInputElement>document.getElementById('username');
let val = username.value;
let payload = {
val,