refactor: fix type of MkAbuseReport

This commit is contained in:
Lhcfl 2024-04-10 17:55:52 +08:00
parent 268b7aeb3f
commit 23145c61af
8 changed files with 114 additions and 81 deletions

View file

@ -33,8 +33,10 @@ import { packedGalleryPostSchema } from "@/models/schema/gallery-post.js";
import { packedEmojiSchema } from "@/models/schema/emoji.js"; import { packedEmojiSchema } from "@/models/schema/emoji.js";
import { packedNoteEdit } from "@/models/schema/note-edit.js"; import { packedNoteEdit } from "@/models/schema/note-edit.js";
import { packedNoteFileSchema } from "@/models/schema/note-file.js"; import { packedNoteFileSchema } from "@/models/schema/note-file.js";
import { packedAbuseUserReportSchema } from "@/models/schema/abuse-user-report.js";
export const refs = { export const refs = {
AbuseUserReport: packedAbuseUserReportSchema,
UserLite: packedUserLiteSchema, UserLite: packedUserLiteSchema,
UserDetailedNotMeOnly: packedUserDetailedNotMeOnlySchema, UserDetailedNotMeOnly: packedUserDetailedNotMeOnlySchema,
MeDetailedOnly: packedMeDetailedOnlySchema, MeDetailedOnly: packedMeDetailedOnlySchema,

View file

@ -2,6 +2,7 @@ import { db } from "@/db/postgre.js";
import { Users } from "../index.js"; import { Users } from "../index.js";
import { AbuseUserReport } from "@/models/entities/abuse-user-report.js"; import { AbuseUserReport } from "@/models/entities/abuse-user-report.js";
import { awaitAll } from "@/prelude/await-all.js"; import { awaitAll } from "@/prelude/await-all.js";
import type { Packed } from "@/misc/schema.js";
export const AbuseUserReportRepository = db export const AbuseUserReportRepository = db
.getRepository(AbuseUserReport) .getRepository(AbuseUserReport)
@ -10,7 +11,7 @@ export const AbuseUserReportRepository = db
const report = const report =
typeof src === "object" ? src : await this.findOneByOrFail({ id: src }); typeof src === "object" ? src : await this.findOneByOrFail({ id: src });
return await awaitAll({ const packed: Packed<"AbuseUserReport"> = await awaitAll({
id: report.id, id: report.id,
createdAt: report.createdAt.toISOString(), createdAt: report.createdAt.toISOString(),
comment: report.comment, comment: report.comment,
@ -31,9 +32,10 @@ export const AbuseUserReportRepository = db
: null, : null,
forwarded: report.forwarded, forwarded: report.forwarded,
}); });
return packed;
}, },
packMany(reports: any[]) { packMany(reports: (AbuseUserReport["id"] | AbuseUserReport)[]) {
return Promise.all(reports.map((x) => this.pack(x))); return Promise.all(reports.map((x) => this.pack(x)));
}, },
}); });

View file

@ -0,0 +1,69 @@
export const packedAbuseUserReportSchema = {
type: "object",
properties: {
id: {
type: "string",
optional: false,
nullable: false,
format: "id",
example: "xxxxxxxxxx",
},
createdAt: {
type: "string",
optional: false,
nullable: false,
format: "date-time",
},
comment: {
type: "string",
optional: false,
nullable: false,
},
resolved: {
type: "boolean",
optional: false,
nullable: false,
},
reporterId: {
type: "string",
optional: false,
nullable: false,
format: "id",
},
targetUserId: {
type: "string",
optional: false,
nullable: false,
format: "id",
},
assigneeId: {
type: "string",
optional: false,
nullable: true,
format: "id",
},
reporter: {
type: "object",
optional: false,
nullable: false,
ref: "UserDetailed",
},
targetUser: {
type: "object",
optional: false,
nullable: false,
ref: "UserDetailed",
},
assignee: {
type: "object",
optional: true,
nullable: true,
ref: "UserDetailed",
},
forwarded: {
type: "boolean",
optional: false,
nullable: false,
},
},
} as const;

View file

@ -16,68 +16,7 @@ export const meta = {
type: "object", type: "object",
optional: false, optional: false,
nullable: false, nullable: false,
properties: { ref: "AbuseUserReport",
id: {
type: "string",
nullable: false,
optional: false,
format: "id",
example: "xxxxxxxxxx",
},
createdAt: {
type: "string",
nullable: false,
optional: false,
format: "date-time",
},
comment: {
type: "string",
nullable: false,
optional: false,
},
resolved: {
type: "boolean",
nullable: false,
optional: false,
example: false,
},
reporterId: {
type: "string",
nullable: false,
optional: false,
format: "id",
},
targetUserId: {
type: "string",
nullable: false,
optional: false,
format: "id",
},
assigneeId: {
type: "string",
nullable: true,
optional: false,
format: "id",
},
reporter: {
type: "object",
nullable: false,
optional: false,
ref: "User",
},
targetUser: {
type: "object",
nullable: false,
optional: false,
ref: "User",
},
assignee: {
type: "object",
nullable: true,
optional: true,
ref: "User",
},
},
}, },
}, },
} as const; } as const;

View file

@ -72,13 +72,14 @@ import MkSwitch from "@/components/form/switch.vue";
import MkKeyValue from "@/components/MkKeyValue.vue"; import MkKeyValue from "@/components/MkKeyValue.vue";
import * as os from "@/os"; import * as os from "@/os";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import type { entities } from "firefish-js";
const props = defineProps<{ const props = defineProps<{
report: any; report: entities.AbuseUserReport;
}>(); }>();
const emit = defineEmits<{ const emit = defineEmits<{
(ev: "resolved", reportId: string): void; resolved: [reportId: string];
}>(); }>();
const forward = ref(props.report.forwarded); const forward = ref(props.report.forwarded);

View file

@ -99,12 +99,13 @@ import XAbuseReport from "@/components/MkAbuseReport.vue";
import { i18n } from "@/i18n"; import { i18n } from "@/i18n";
import { definePageMetadata } from "@/scripts/page-metadata"; import { definePageMetadata } from "@/scripts/page-metadata";
import icon from "@/scripts/icon"; import icon from "@/scripts/icon";
import type { entities } from "firefish-js";
const reports = ref<InstanceType<typeof MkPagination>>(); const reports = ref<InstanceType<typeof MkPagination>>();
const state = ref("unresolved"); const state = ref("unresolved");
const reporterOrigin = ref("combined"); const reporterOrigin = ref<entities.OriginType>("combined");
const targetUserOrigin = ref("combined"); const targetUserOrigin = ref<entities.OriginType>("combined");
// const searchUsername = ref(""); // const searchUsername = ref("");
// const searchHost = ref(""); // const searchHost = ref("");

View file

@ -1,4 +1,5 @@
import type { import type {
AbuseUserReport,
Ad, Ad,
Announcement, Announcement,
Antenna, Antenna,
@ -68,7 +69,18 @@ type NoteSubmitReq = {
export type Endpoints = { export type Endpoints = {
// admin // admin
"admin/abuse-user-reports": { req: TODO; res: TODO }; "admin/abuse-user-reports": {
req: {
limit?: number;
sinceId?: AbuseUserReport["id"];
untilId?: AbuseUserReport["id"];
state?: string;
reporterOrigin?: OriginType;
targetUserOrigin?: OriginType;
forwarded?: boolean;
};
res: AbuseUserReport[];
};
"admin/delete-all-files-of-a-user": { "admin/delete-all-files-of-a-user": {
req: { userId: User["id"] }; req: { userId: User["id"] };
res: null; res: null;

View file

@ -18,10 +18,7 @@ export type UserLite = {
avatarBlurhash: string; avatarBlurhash: string;
alsoKnownAs: string[]; alsoKnownAs: string[];
movedToUri: any; movedToUri: any;
emojis: { emojis: EmojiLite[];
name: string;
url: string;
}[];
instance?: { instance?: {
name: Instance["name"]; name: Instance["name"];
softwareName: Instance["softwareName"]; softwareName: Instance["softwareName"];
@ -171,10 +168,7 @@ export type Note = {
votes: number; votes: number;
}[]; }[];
}; };
emojis: { emojis: EmojiLite[];
name: string;
url: string;
}[];
uri?: string; uri?: string;
url?: string; url?: string;
updatedAt?: DateString; updatedAt?: DateString;
@ -191,10 +185,7 @@ export type NoteEdit = {
updatedAt: string; updatedAt: string;
fileIds: DriveFile["id"][]; fileIds: DriveFile["id"][];
files: DriveFile[]; files: DriveFile[];
emojis: { emojis: EmojiLite[];
name: string;
url: string;
}[];
}; };
export type NoteReaction = { export type NoteReaction = {
@ -325,6 +316,8 @@ export type EmojiLite = {
id: string; id: string;
name: string; name: string;
url: string; url: string;
width: number | null;
height: number | null;
}; };
export type LiteInstanceMetadata = { export type LiteInstanceMetadata = {
@ -547,3 +540,17 @@ export type UserSorting =
| "+updatedAt" | "+updatedAt"
| "-updatedAt"; | "-updatedAt";
export type OriginType = "combined" | "local" | "remote"; export type OriginType = "combined" | "local" | "remote";
export type AbuseUserReport = {
id: string;
createdAt: DateString;
comment: string;
resolved: boolean;
reporterId: User["id"];
targetUserId: User["id"];
assigneeId: User["id"] | null;
reporter: UserDetailed;
targetUser: UserDetailed;
assignee?: UserDetailed | null;
forwarded: boolean;
};