diff options
author | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-03 05:03:46 +0200 |
---|---|---|
committer | Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> | 2021-09-03 05:03:46 +0200 |
commit | 97ec83ea1c191ebd53a29adbfc8851cc9a340d19 (patch) | |
tree | 30f8cb3ed20091cf79962d9d0a102221fdaf1858 /util/src/entities/Member.ts | |
parent | :sparkles: guild position update (diff) | |
download | server-97ec83ea1c191ebd53a29adbfc8851cc9a340d19.tar.xz |
:bug: fix#310
Diffstat (limited to 'util/src/entities/Member.ts')
-rw-r--r-- | util/src/entities/Member.ts | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/util/src/entities/Member.ts b/util/src/entities/Member.ts index 42215c45..9ad6c8db 100644 --- a/util/src/entities/Member.ts +++ b/util/src/entities/Member.ts @@ -1,6 +1,18 @@ import { PublicUser, User } from "./User"; import { BaseClass } from "./BaseClass"; -import { Column, Entity, Index, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, RelationId } from "typeorm"; +import { + Column, + Entity, + Index, + JoinColumn, + JoinTable, + ManyToMany, + ManyToOne, + OneToMany, + PrimaryColumn, + PrimaryGeneratedColumn, + RelationId, +} from "typeorm"; import { Guild } from "./Guild"; import { Config, emitEvent } from "../util"; import { @@ -12,12 +24,16 @@ import { } from "../interfaces"; import { HTTPError } from "lambert-server"; import { Role } from "./Role"; +import { Snowflake } from "../util/Snowflake"; import { BaseClassWithoutId } from "./BaseClass"; @Entity("members") @Index(["id", "guild_id"], { unique: true }) export class Member extends BaseClassWithoutId { - @Column({ primary: true, unique: false }) + @PrimaryGeneratedColumn() + index: string; + + @Column() @RelationId((member: Member) => member.user) id: string; @@ -38,7 +54,7 @@ export class Member extends BaseClassWithoutId { @JoinTable({ name: "member_roles", - joinColumn: { name: "id", referencedColumnName: "id" }, + joinColumn: { name: "index", referencedColumnName: "index" }, inverseJoinColumn: { name: "role_id", referencedColumnName: "id", @@ -213,7 +229,7 @@ export class Member extends BaseClassWithoutId { guild.joined_at = member.joined_at.toISOString(); await Promise.all([ - new Member({ + Member.insert({ ...member, roles: [new Role({ id: guild_id })], // read_state: {}, @@ -226,7 +242,7 @@ export class Member extends BaseClassWithoutId { suppress_roles: false, version: 0, }, - }).save(), + }), Guild.increment({ id: guild_id }, "member_count", 1), emitEvent({ event: "GUILD_MEMBER_ADD", |