More refactoring, API route fixes

This commit is contained in:
Jesse Wierzbinski 2023-09-26 13:08:05 -10:00
parent 3b452d66aa
commit 95b46ba2e4
6 changed files with 72 additions and 16 deletions

View file

@ -7,7 +7,6 @@ import {
JoinTable,
ManyToMany,
ManyToOne,
OneToOne,
PrimaryGeneratedColumn,
RemoveOptions,
UpdateDateColumn,
@ -46,7 +45,10 @@ export class Status extends BaseEntity {
})
reblog?: Status;
@OneToOne(() => Status)
@ManyToOne(() => RawObject, {
nullable: true,
onDelete: "SET NULL",
})
object!: RawObject;
@Column("boolean")
@ -63,12 +65,12 @@ export class Status extends BaseEntity {
@ManyToOne(() => RawObject, {
nullable: true,
})
in_reply_to_post!: RawObject;
in_reply_to_post!: RawObject | null;
@ManyToOne(() => RawActor, {
nullable: true,
})
in_reply_to_account!: RawActor;
in_reply_to_account!: RawActor | null;
@Column("boolean")
sensitive!: boolean;
@ -99,9 +101,7 @@ export class Status extends BaseEntity {
// Delete object
await this.object.remove(options);
await super.remove(options);
return this;
return await super.remove(options);
}
static async createNew(data: {
@ -225,7 +225,7 @@ export class Status extends BaseEntity {
}
// TODO: Add default language
await newStatus.object.save();
await newStatus.save();
return newStatus;
}

View file

@ -9,6 +9,7 @@ import {
ManyToOne,
OneToMany,
PrimaryGeneratedColumn,
RemoveOptions,
UpdateDateColumn,
} from "typeorm";
import { APIAccount } from "~types/entities/account";
@ -174,7 +175,7 @@ export class User extends BaseEntity {
return relationship;
}
async selfDestruct() {
async remove(options?: RemoveOptions | undefined) {
// Clean up tokens
const tokens = await Token.findBy({
user: {
@ -182,9 +183,14 @@ export class User extends BaseEntity {
},
});
const statuses = await Status.findBy({
account: {
id: this.id,
const statuses = await Status.find({
where: {
account: {
id: this.id,
},
},
relations: {
object: true,
},
});
@ -199,6 +205,8 @@ export class User extends BaseEntity {
await Promise.all(
relationships.map(async relationship => await relationship.remove())
);
return await super.remove(options);
}
async getRelationships() {