mirror of
https://github.com/spacebarchat/server.git
synced 2026-10-23 21:44:47 +00:00
Fix audit log entry entity
This commit is contained in:
1 parent
b3b98bf72a
commit
c0a71086f1
2 files changed
+47
-2
No files matched your search
@@ -16,15 +16,29 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
|
||||
import { Column, Entity, Index, JoinColumn, ManyToOne, RelationId } from "typeorm";
|
||||
import { BaseClass } from "./BaseClass";
|
||||
import { Guild } from "./Guild";
|
||||
import { User } from "./User";
|
||||
import { AuditLogChange, AuditLogEvents } from "@spacebar/schemas";
|
||||
import { AuditLogChange, AuditLogEntry, AuditLogEvents } from "@spacebar/schemas";
|
||||
|
||||
@Entity({
|
||||
name: "audit_logs",
|
||||
})
|
||||
export class AuditLog extends BaseClass {
|
||||
@Column({ nullable: true })
|
||||
@RelationId((auditlog: AuditLog) => auditlog.guild)
|
||||
@Index("IDX_audit_log_guild_id")
|
||||
guild_id: string;
|
||||
|
||||
@JoinColumn({ name: "target_id", foreignKeyConstraintName: "FK_audit_log_guild_id" })
|
||||
@ManyToOne(() => Guild)
|
||||
guild?: Guild;
|
||||
|
||||
@Column({ nullable: true })
|
||||
@RelationId((auditlog: AuditLog) => auditlog.target)
|
||||
target_id: string;
|
||||
|
||||
@JoinColumn({ name: "target_id", foreignKeyConstraintName: "FK_audit_log_target_user_id" })
|
||||
@ManyToOne(() => User)
|
||||
target?: User;
|
||||
@@ -58,4 +72,16 @@ export class AuditLog extends BaseClass {
|
||||
|
||||
@Column({ nullable: true })
|
||||
reason?: string;
|
||||
|
||||
toAuditLogEntry(): AuditLogEntry {
|
||||
return {
|
||||
id: this.id,
|
||||
action_type: this.action_type,
|
||||
reason: this.reason,
|
||||
user_id: this.user_id,
|
||||
target_id: this.target_id,
|
||||
options: this.options,
|
||||
changes: this.changes,
|
||||
} satisfies AuditLogEntry;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AuditLogsByGuild1788342958702 implements MigrationInterface {
|
||||
name = "AuditLogsByGuild1788342958702";
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "audit_logs" ADD "guild_id" character varying`);
|
||||
await queryRunner.query(`CREATE INDEX "IDX_audit_log_guild_id" ON "audit_logs" ("guild_id") `);
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE "audit_logs" ADD CONSTRAINT "FK_audit_log_guild_id" FOREIGN KEY ("target_id") REFERENCES "guilds"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE "audit_logs" DROP CONSTRAINT "FK_audit_log_guild_id"`);
|
||||
await queryRunner.query(`DROP INDEX "public"."IDX_audit_log_guild_id"`);
|
||||
await queryRunner.query(`ALTER TABLE "audit_logs" DROP COLUMN "guild_id"`);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user