bigbuffet-rw/packages/pl-api/lib/entities/admin/report.ts

51 lines
1.8 KiB
TypeScript
Raw Normal View History

import pick from 'lodash.pick';
import * as v from 'valibot';
import { ruleSchema } from '../rule';
import { statusWithoutAccountSchema } from '../status';
import { dateSchema, filteredArray } from '../utils';
import { adminAccountSchema } from './account';
/** @see {@link https://docs.joinmastodon.org/entities/Admin_Report/} */
const adminReportSchema = v.pipe(
v.any(),
v.transform((report: any) => {
if (report.actor) {
/**
* Convert Pleroma report schema
* @see {@link https://docs.pleroma.social/backend/development/API/admin_api/#get-apiv1pleromaadminreports}
*/
return {
action_taken: report.state !== 'open',
comment: report.content,
updated_at: report.created_at,
account: report.actor,
target_account: report.account,
...(pick(report, ['id', 'assigned_account', 'created_at', 'rules', 'statuses'])),
};
}
return report;
}),
v.object({
id: v.string(),
action_taken: v.fallback(v.optional(v.boolean()), undefined),
action_taken_at: v.fallback(v.nullable(dateSchema), null),
category: v.fallback(v.optional(v.string()), undefined),
comment: v.fallback(v.optional(v.string()), undefined),
forwarded: v.fallback(v.optional(v.boolean()), undefined),
created_at: v.fallback(v.optional(dateSchema), undefined),
updated_at: v.fallback(v.optional(dateSchema), undefined),
account: adminAccountSchema,
target_account: adminAccountSchema,
assigned_account: v.fallback(v.nullable(adminAccountSchema), null),
action_taken_by_account: v.fallback(v.nullable(adminAccountSchema), null),
statuses: filteredArray(statusWithoutAccountSchema),
rules: filteredArray(ruleSchema),
}),
);
type AdminReport = v.InferOutput<typeof adminReportSchema>;
export { adminReportSchema, type AdminReport };