diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-01 23:34:55 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-01 23:34:55 +0200 |
commit | 295159fc4a7d32ffa7686ff7df510d098a1794f9 (patch) | |
tree | 51dd0493766f0eda1551dd44f546e8189aafa182 /util/src/entities | |
parent | :sparkles: generate open api schema based on body and db entities (diff) | |
download | server-295159fc4a7d32ffa7686ff7df510d098a1794f9.tar.xz |
:bug: fix entity types and projection
Diffstat (limited to '')
-rw-r--r-- | util/src/entities/AuditLog.ts | 6 | ||||
-rw-r--r-- | util/src/entities/BaseClass.ts | 10 | ||||
-rw-r--r-- | util/src/entities/Member.ts | 7 | ||||
-rw-r--r-- | util/src/entities/Message.ts | 2 | ||||
-rw-r--r-- | util/src/entities/User.ts | 66 |
5 files changed, 57 insertions, 34 deletions
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() |