summary refs log tree commit diff
diff options
context:
space:
mode:
authorwhinis <whinis@whinis.com>2026-02-17 22:26:08 -0500
committerRory& <root@rory.gay>2026-02-18 14:14:14 +0100
commit750acb353ef019c18e7cb3625a9c3adc2a78bfe2 (patch)
tree959f18007a8674e5900862b81abc51b4b2210690
parentGateway: log user ID/i (diff)
downloadserver-ts-750acb353ef019c18e7cb3625a9c3adc2a78bfe2.tar.xz
Add decorator to change Bigint back to string using Number
-rw-r--r--src/util/entities/BaseClass.ts14
-rw-r--r--src/util/entities/Member.ts2
-rw-r--r--src/util/entities/User.ts5
-rw-r--r--src/util/util/Decorators.ts5
4 files changed, 26 insertions, 0 deletions
diff --git a/src/util/entities/BaseClass.ts b/src/util/entities/BaseClass.ts

index a8844630..2b6c651b 100644 --- a/src/util/entities/BaseClass.ts +++ b/src/util/entities/BaseClass.ts
@@ -38,6 +38,9 @@ export class BaseClassWithoutId extends BaseEntity { // Loops through all the keys and compares it to annotations. If the RemoveEmpty is there it sets the value to undefined if null clean_data() { const annotations = this.get_annotations(); + if (annotations == undefined || annotations.length > 0) + //prevent errors if there are no annotations on an object + return; for (const key in this) { if ( key in this && // This object has this property, should never fail but better to be safe @@ -50,6 +53,16 @@ export class BaseClassWithoutId extends BaseEntity { // @ts-expect-error this[key] = undefined; // set to undefined to remove } + if ( + key in this && // This object has this property, should never fail but better to be safe + key in annotations && // If this property has an annotation + annotations[key].indexOf("BigintToLong") > -1 && // if one of the annotations is JsonRemoveEmpty + typeof this[key] == "string" // and its a String + ) { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error + this[key] = Number(this[key]); // convert string back to number + } } return this; } @@ -66,6 +79,7 @@ export class BaseClassWithoutId extends BaseEntity { // TODO: fix eslint // eslint-disable-next-line @typescript-eslint/no-explicit-any toJSON(): any { + this.clean_data(); return Object.fromEntries( // eslint-disable-next-line @typescript-eslint/ban-ts-comment this.metadata!.columns // @ts-ignore diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts
index b15a9276..5d2de478 100644 --- a/src/util/entities/Member.ts +++ b/src/util/entities/Member.ts
@@ -29,6 +29,7 @@ import { Message } from "./Message"; import { Role } from "./Role"; import { User } from "./User"; import { AvatarDecorationData, Collectibles, DisplayNameStyle, PrimaryGuild, PublicMember, PublicMemberProjection, UserGuildSettings } from "@spacebar/schemas"; +import { BigintToLong } from "../util/Decorators"; export const MemberPrivateProjection: (keyof Member)[] = [ "id", @@ -98,6 +99,7 @@ export class Member extends BaseClassWithoutId { joined_at: Date; @Column({ type: "bigint", nullable: true }) + @BigintToLong premium_since?: number; @Column() diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts
index d8f52988..57b90ee1 100644 --- a/src/util/entities/User.ts +++ b/src/util/entities/User.ts
@@ -38,6 +38,7 @@ import { PublicUserProjection, UserPrivate, } from "@spacebar/schemas"; +import { BigintToLong } from "../util/Decorators"; @Entity({ name: "users", @@ -124,18 +125,22 @@ export class User extends BaseClass { email?: string; // email of the user @Column({ type: "bigint" }) + @BigintToLong flags: number = 0; // UserFlags // TODO: generate @Column({ type: "bigint" }) + @BigintToLong public_flags: number = 0; @Column({ type: "bigint" }) + @BigintToLong purchased_flags: number = 0; @Column() premium_usage_flags: number = 0; @Column({ type: "bigint" }) + @BigintToLong rights: string; @OneToMany(() => Session, (session: Session) => session.user) diff --git a/src/util/util/Decorators.ts b/src/util/util/Decorators.ts
index 9de9c1c9..0b7a67b6 100644 --- a/src/util/util/Decorators.ts +++ b/src/util/util/Decorators.ts
@@ -19,3 +19,8 @@ export function JsonRemoveEmpty(target: BaseClassWithoutId, propertyKey: string) initAnnotationMetadata(target, propertyKey); addAnnotationMetadata(target, propertyKey, "JsonRemoveEmpty"); } + +export function BigintToLong(target: BaseClassWithoutId, propertyKey: string) { + initAnnotationMetadata(target, propertyKey); + addAnnotationMetadata(target, propertyKey, "BigintToLong"); +}