aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLarsVomMars2020-07-19 23:52:18 +0200
committerLarsVomMars2020-07-19 23:52:18 +0200
commita937e79d29685d76af6138191f553fc82cbd2b1a (patch)
treed352d5f2f01ac6eade223956935789136ead7623 /src
parentf47d1be953f175e45b6d4342f6c805aa473bdd87 (diff)
Added fancy database functions
Diffstat (limited to 'src')
-rw-r--r--src/db/user.ts56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/db/user.ts b/src/db/user.ts
index c7bed17..9152383 100644
--- a/src/db/user.ts
+++ b/src/db/user.ts
@@ -54,6 +54,51 @@ class User {
}
/**
+ * Returns the user with the uid and verification
+ * TODO: Tests
+ * @param uid
+ * @param userVerification
+ */
+ async getUserByVerificationId(uid: number, userVerification: string): Promise<userData | undefined> {
+ try {
+ const user = (
+ await this.controller.query(
+ "SELECT id, email, username, verification, dark_theme darkTheme, is_admin isAdmin FROM users WHERE id = ? AND verification = ?",
+ [uid, userVerification]
+ )
+ )[0];
+ if (user) return user as userData;
+ } catch (e) {
+ throw e;
+ }
+ }
+
+ /**
+ * Changes the user theme
+ * @param uid
+ */
+ async changeTheme(uid: number) {
+ try {
+ await this.controller.execute("UPDATE users SET dark_theme = NOT dark_theme WHERE id = ?", [uid]);
+ } catch (e) {
+ throw e;
+ }
+ }
+
+ /**
+ * Sets admin status of a user
+ * @param uid
+ * @param isAdmin
+ */
+ async setAdminState(uid: number, isAdmin: boolean) {
+ try {
+ await this.controller.execute("UPDATE users SET is_admin = ? WHERE id = ?", [isAdmin, uid]);
+ } catch (e) {
+ throw e;
+ }
+ }
+
+ /**
* Generate random id
* @param len
* @private
@@ -72,5 +117,14 @@ export interface loginData {
success: boolean;
uid?: number;
verification?: string;
- darkTheme?: string;
+ darkTheme?: boolean;
+}
+
+export interface userData {
+ id: number;
+ email: string;
+ username: string;
+ verification: string;
+ darkTheme: boolean;
+ isAdmin: boolean;
}