summary refs log tree commit diff
path: root/util
diff options
context:
space:
mode:
Diffstat (limited to 'util')
-rw-r--r--util/package-lock.json14
-rw-r--r--util/package.json2
-rw-r--r--util/src/entities/AuditLog.ts6
-rw-r--r--util/src/entities/BaseClass.ts10
-rw-r--r--util/src/entities/Member.ts7
-rw-r--r--util/src/entities/Message.ts2
-rw-r--r--util/src/entities/User.ts66
-rw-r--r--util/src/tes.ts23
8 files changed, 65 insertions, 65 deletions
diff --git a/util/package-lock.json b/util/package-lock.json
index 47aca2d1..571fffbe 100644
--- a/util/package-lock.json
+++ b/util/package-lock.json
@@ -17,7 +17,7 @@
 				"env-paths": "^2.2.1",
 				"jsonwebtoken": "^8.5.1",
 				"lambert-server": "^1.2.10",
-				"missing-native-js-functions": "^1.2.11",
+				"missing-native-js-functions": "^1.2.13",
 				"node-fetch": "^2.6.1",
 				"patch-package": "^6.4.7",
 				"pg": "^8.7.1",
@@ -6338,9 +6338,9 @@
 			}
 		},
 		"node_modules/missing-native-js-functions": {
-			"version": "1.2.11",
-			"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.11.tgz",
-			"integrity": "sha512-U97IscNBL4Wg9adYjEBT46Hb0Ld5dPT8vbdwFX+TNzGrFQCc4WqoGAZouaLNFwUqxzzHZ9DVg59unwnQyeIIQg=="
+			"version": "1.2.13",
+			"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.13.tgz",
+			"integrity": "sha512-1RAArfUkrGkj5N3xJVW251F2PvfP2ozAcxsLLDR6uiiAixTP5Abh8zzGMadepbqgiHC0FGlTSAUNbh9abN4Osg=="
 		},
 		"node_modules/mkdirp": {
 			"version": "1.0.4",
@@ -13735,9 +13735,9 @@
 			}
 		},
 		"missing-native-js-functions": {
-			"version": "1.2.11",
-			"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.11.tgz",
-			"integrity": "sha512-U97IscNBL4Wg9adYjEBT46Hb0Ld5dPT8vbdwFX+TNzGrFQCc4WqoGAZouaLNFwUqxzzHZ9DVg59unwnQyeIIQg=="
+			"version": "1.2.13",
+			"resolved": "https://registry.npmjs.org/missing-native-js-functions/-/missing-native-js-functions-1.2.13.tgz",
+			"integrity": "sha512-1RAArfUkrGkj5N3xJVW251F2PvfP2ozAcxsLLDR6uiiAixTP5Abh8zzGMadepbqgiHC0FGlTSAUNbh9abN4Osg=="
 		},
 		"mkdirp": {
 			"version": "1.0.4",
diff --git a/util/package.json b/util/package.json
index 39af7526..38cd8d35 100644
--- a/util/package.json
+++ b/util/package.json
@@ -44,7 +44,7 @@
 		"env-paths": "^2.2.1",
 		"jsonwebtoken": "^8.5.1",
 		"lambert-server": "^1.2.10",
-		"missing-native-js-functions": "^1.2.11",
+		"missing-native-js-functions": "^1.2.13",
 		"node-fetch": "^2.6.1",
 		"patch-package": "^6.4.7",
 		"pg": "^8.7.1",
diff --git a/util/src/entities/AuditLog.ts b/util/src/entities/AuditLog.ts
index ceeb21fd..ae9feb76 100644
--- a/util/src/entities/AuditLog.ts
+++ b/util/src/entities/AuditLog.ts
@@ -42,17 +42,17 @@ export enum AuditLogEvents {
 }
 
 @Entity("audit_logs")
-export class AuditLogEntry extends BaseClass {
+export class AuditLog extends BaseClass {
 	@JoinColumn({ name: "target_id" })
 	@ManyToOne(() => User)
 	target?: User;
 
 	@Column({ nullable: true })
-	@RelationId((auditlog: AuditLogEntry) => auditlog.user)
+	@RelationId((auditlog: AuditLog) => auditlog.user)
 	user_id: string;
 
 	@JoinColumn({ name: "user_id" })
-	@ManyToOne(() => User)
+	@ManyToOne(() => User, (user: User) => user.id)
 	user: User;
 
 	@Column({
diff --git a/util/src/entities/BaseClass.ts b/util/src/entities/BaseClass.ts
index 0856ccd1..403a6fc6 100644
--- a/util/src/entities/BaseClass.ts
+++ b/util/src/entities/BaseClass.ts
@@ -8,19 +8,19 @@ import "missing-native-js-functions";
 
 export class BaseClass extends BaseEntity {
 	@PrimaryColumn()
-	id: string = Snowflake.generate();
+	id: string;
 
 	// @ts-ignore
-	constructor(public props?: any) {
+	constructor(private props?: any) {
 		super();
 		this.assign(props);
 	}
 
-	get construct(): any {
+	private get construct(): any {
 		return this.constructor;
 	}
 
-	get metadata() {
+	private get metadata() {
 		return this.construct.getRepository().metadata as EntityMetadata;
 	}
 
@@ -48,6 +48,8 @@ export class BaseClass extends BaseEntity {
 				this[key] = props[key];
 			}
 		}
+
+		if (!this.id) this.id = Snowflake.generate();
 	}
 
 	@BeforeUpdate()
diff --git a/util/src/entities/Member.ts b/util/src/entities/Member.ts
index d2d78bb9..e1773730 100644
--- a/util/src/entities/Member.ts
+++ b/util/src/entities/Member.ts
@@ -12,6 +12,7 @@ import {
 } from "../interfaces";
 import { HTTPError } from "lambert-server";
 import { Role } from "./Role";
+import { ReadState } from "./ReadState";
 
 @Entity("members")
 export class Member extends BaseClass {
@@ -53,8 +54,8 @@ export class Member extends BaseClass {
 	settings: UserGuildSettings;
 
 	// TODO: update
-	@Column({ type: "simple-json" })
-	read_state: Record<string, string | null>;
+	// @Column({ type: "simple-json" })
+	// read_state: ReadState;
 
 	static async IsInGuildOrFail(user_id: string, guild_id: string) {
 		if (await Member.count({ id: user_id, guild: { id: guild_id } })) return true;
@@ -206,7 +207,7 @@ export class Member extends BaseClass {
 			Member.insert({
 				...member,
 				roles: undefined,
-				read_state: {},
+				// read_state: {},
 				settings: {
 					channel_overrides: [],
 					message_notifications: 0,
diff --git a/util/src/entities/Message.ts b/util/src/entities/Message.ts
index 542b2b55..aacca526 100644
--- a/util/src/entities/Message.ts
+++ b/util/src/entities/Message.ts
@@ -139,7 +139,7 @@ export class Message extends BaseClass {
 	reactions: Reaction[];
 
 	@Column({ type: "text", nullable: true })
-	nonce?: string | number;
+	nonce?: string;
 
 	@Column({ nullable: true })
 	pinned?: boolean;
diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts
index 39f654be..1b4ce351 100644
--- a/util/src/entities/User.ts
+++ b/util/src/entities/User.ts
@@ -4,33 +4,53 @@ import { BitField } from "../util/BitField";
 import { Relationship } from "./Relationship";
 import { ConnectedAccount } from "./ConnectedAccount";
 import { HTTPError } from "lambert-server";
-import { Channel } from "./Channel";
-
-type PublicUserKeys =
-	| "username"
-	| "discriminator"
-	| "id"
-	| "public_flags"
-	| "avatar"
-	| "accent_color"
-	| "banner"
-	| "bio"
-	| "bot";
-export const PublicUserProjection: PublicUserKeys[] = [
-	"username",
-	"discriminator",
-	"id",
-	"public_flags",
-	"avatar",
-	"accent_color",
-	"banner",
-	"bio",
-	"bot",
-];
+
+export enum PublicUserEnum {
+	username,
+	discriminator,
+	id,
+	public_flags,
+	avatar,
+	accent_color,
+	banner,
+	bio,
+	bot,
+}
+export type PublicUserKeys = keyof typeof PublicUserEnum;
+
+export enum PrivateUserEnum {
+	flags,
+	mfa_enabled,
+	email,
+	phone,
+	verified,
+	nsfw_allowed,
+	premium,
+	premium_type,
+	disabled,
+	// locale
+}
+export type PrivateUserKeys = keyof typeof PrivateUserEnum | PublicUserKeys;
+
+export const PublicUserProjection = Object.values(PublicUserEnum).filter(
+	(x) => typeof x === "string"
+) as PublicUserKeys[];
+export const PrivateUserProjection = [
+	...PublicUserProjection,
+	Object.values(PrivateUserEnum).filter((x) => typeof x === "string"),
+] as PrivateUserKeys[];
 
 // Private user data that should never get sent to the client
 export type PublicUser = Pick<User, PublicUserKeys>;
 
+export interface UserPublic extends Pick<User, PublicUserKeys> {}
+
+export interface UserPrivate extends Pick<User, PrivateUserKeys> {
+	locale: string;
+}
+
+// TODO: add purchased_flags, premium_usage_flags
+
 @Entity("users")
 export class User extends BaseClass {
 	@Column()
diff --git a/util/src/tes.ts b/util/src/tes.ts
deleted file mode 100644
index e326dee1..00000000
--- a/util/src/tes.ts
+++ /dev/null
@@ -1,23 +0,0 @@
-import { performance } from "perf_hooks";
-import { Guild, Relationship, RelationshipType } from "./entities";
-import { User } from "./entities/User";
-import { initDatabase } from "./util";
-
-initDatabase().then(async (x) => {
-	try {
-		const user = await new User({
-			guilds: [],
-			discriminator: "1",
-			username: "test",
-			flags: "0",
-			public_flags: "0",
-			id: "0",
-		}).save();
-
-		user.relationships = [new Relationship({ type: RelationshipType.friends })];
-
-		user.save();
-	} catch (error) {
-		console.error(error);
-	}
-});