summary refs log tree commit diff
path: root/util/src
diff options
context:
space:
mode:
authorFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-13 12:22:41 +0200
committerFlam3rboy <34555296+Flam3rboy@users.noreply.github.com>2021-09-13 12:22:41 +0200
commitdbbed7cbba8d5967d5b2bdc8a666fce22ac0e22c (patch)
treebcd33ccb16c3e1dbebc38544f0b4971a3b98cf2d /util/src
parent:bug: fix dm #321 (diff)
downloadserver-dbbed7cbba8d5967d5b2bdc8a666fce22ac0e22c.tar.xz
:bug: fix relationship
Diffstat (limited to 'util/src')
-rw-r--r--util/src/entities/Relationship.ts30
-rw-r--r--util/src/interfaces/Event.ts14
2 files changed, 34 insertions, 10 deletions
diff --git a/util/src/entities/Relationship.ts b/util/src/entities/Relationship.ts
index 5935f5b6..61b3ac82 100644
--- a/util/src/entities/Relationship.ts
+++ b/util/src/entities/Relationship.ts
@@ -1,4 +1,4 @@
-import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
+import { Column, Entity, Index, JoinColumn, ManyToOne, RelationId } from "typeorm";
 import { BaseClass } from "./BaseClass";
 import { User } from "./User";
 
@@ -10,18 +10,36 @@ export enum RelationshipType {
 }
 
 @Entity("relationships")
+@Index(["from_id", "to_id"], { unique: true })
 export class Relationship extends BaseClass {
-	@Column({ nullable: true })
-	@RelationId((relationship: Relationship) => relationship.user)
-	user_id: string;
+	@Column({})
+	@RelationId((relationship: Relationship) => relationship.from)
+	from_id: string;
 
-	@JoinColumn({ name: "user_id" })
+	@JoinColumn({ name: "from_id" })
 	@ManyToOne(() => User)
-	user: User;
+	from: User;
+
+	@Column({})
+	@RelationId((relationship: Relationship) => relationship.to)
+	to_id: string;
+
+	@JoinColumn({ name: "to_id" })
+	@ManyToOne(() => User)
+	to: User;
 
 	@Column({ nullable: true })
 	nickname?: string;
 
 	@Column({ type: "simple-enum", enum: RelationshipType })
 	type: RelationshipType;
+
+	toPublicRelationship() {
+		return {
+			id: this.to?.id || this.to_id,
+			type: this.type,
+			nickname: this.nickname,
+			user: this.to?.toPublicUser(),
+		};
+	}
 }
diff --git a/util/src/interfaces/Event.ts b/util/src/interfaces/Event.ts
index 5c2a01b0..aff50300 100644
--- a/util/src/interfaces/Event.ts
+++ b/util/src/interfaces/Event.ts
@@ -10,7 +10,7 @@ import { VoiceState } from "../entities/VoiceState";
 import { ApplicationCommand } from "../entities/Application";
 import { Interaction } from "./Interaction";
 import { ConnectedAccount } from "../entities/ConnectedAccount";
-import { Relationship } from "../entities/Relationship";
+import { Relationship, RelationshipType } from "../entities/Relationship";
 import { Presence } from "./Presence";
 
 export interface Event {
@@ -28,6 +28,12 @@ export interface InvalidatedEvent extends Event {
 	event: "INVALIDATED";
 }
 
+export interface PublicRelationship {
+	id: string;
+	user: PublicUser;
+	type: RelationshipType;
+}
+
 // ! END Custom Events that shouldn't get sent to the client but processed by the server
 
 export interface ReadyEventData {
@@ -72,7 +78,7 @@ export interface ReadyEventData {
 	guild_join_requests?: any[]; // ? what is this? this is new
 	shard?: [number, number];
 	user_settings?: UserSettings;
-	relationships?: Relationship[]; // TODO
+	relationships?: PublicRelationship[]; // TODO
 	read_state: {
 		entries: any[]; // TODO
 		partial: boolean;
@@ -412,7 +418,7 @@ export interface MessageAckEvent extends Event {
 
 export interface RelationshipAddEvent extends Event {
 	event: "RELATIONSHIP_ADD";
-	data: Relationship & {
+	data: PublicRelationship & {
 		should_notify?: boolean;
 		user: PublicUser;
 	};
@@ -420,7 +426,7 @@ export interface RelationshipAddEvent extends Event {
 
 export interface RelationshipRemoveEvent extends Event {
 	event: "RELATIONSHIP_REMOVE";
-	data: Omit<Relationship, "nickname">;
+	data: Omit<PublicRelationship, "nickname">;
 }
 
 export type EventData =