reports.ts•6 kB
/**
* Generated by orval v7.2.0 🍺
* Do not edit manually.
* storyden
* Storyden social API for building community driven platforms.
The Storyden API does not adhere to semantic versioning but instead applies a rolling strategy with deprecations and minimal breaking changes. This has been done mainly for a simpler development process and it may be changed to a more fixed versioning strategy in the future. Ultimately, the primary way Storyden tracks versions is dates, there are no set release tags currently.
* OpenAPI spec version: v1.25.8-canary
*/
import useSwr from "swr";
import type { Key, SWRConfiguration } from "swr";
import useSWRMutation from "swr/mutation";
import type { SWRMutationConfiguration } from "swr/mutation";
import { fetcher } from "../client";
import type {
BadRequestResponse,
ForbiddenResponse,
InternalServerErrorResponse,
NotFoundResponse,
ReportCreateBody,
ReportCreateOKResponse,
ReportListOKResponse,
ReportListParams,
ReportUpdateBody,
ReportUpdateOKResponse,
UnauthorisedResponse,
} from "../openapi-schema";
/**
* Create a new report for content or user violations.
Reports can be against any kind of user-generated content as well as
members themselves. The kind of report is specified in the request body
which dictates which resource the `id` field refers to.
*/
export const reportCreate = (reportCreateBody: ReportCreateBody) => {
return fetcher<ReportCreateOKResponse>({
url: `/reports`,
method: "POST",
headers: { "Content-Type": "application/json" },
data: reportCreateBody,
});
};
export const getReportCreateMutationFetcher = () => {
return (
_: Key,
{ arg }: { arg: ReportCreateBody },
): Promise<ReportCreateOKResponse> => {
return reportCreate(arg);
};
};
export const getReportCreateMutationKey = () => [`/reports`] as const;
export type ReportCreateMutationResult = NonNullable<
Awaited<ReturnType<typeof reportCreate>>
>;
export type ReportCreateMutationError =
| BadRequestResponse
| UnauthorisedResponse
| InternalServerErrorResponse;
export const useReportCreate = <
TError =
| BadRequestResponse
| UnauthorisedResponse
| InternalServerErrorResponse,
>(options?: {
swr?: SWRMutationConfiguration<
Awaited<ReturnType<typeof reportCreate>>,
TError,
Key,
ReportCreateBody,
Awaited<ReturnType<typeof reportCreate>>
> & { swrKey?: string };
}) => {
const { swr: swrOptions } = options ?? {};
const swrKey = swrOptions?.swrKey ?? getReportCreateMutationKey();
const swrFn = getReportCreateMutationFetcher();
const query = useSWRMutation(swrKey, swrFn, swrOptions);
return {
swrKey,
...query,
};
};
/**
* List reports. Regular members see only their own reports. Members with
`MANAGE_REPORTS` permission will see all submitted reports. Reports can
be filtered by status. By default filters open and acknowledged reports.
Returns a list ordered by most recently updated.
*/
export const reportList = (params?: ReportListParams) => {
return fetcher<ReportListOKResponse>({
url: `/reports`,
method: "GET",
params,
});
};
export const getReportListKey = (params?: ReportListParams) =>
[`/reports`, ...(params ? [params] : [])] as const;
export type ReportListQueryResult = NonNullable<
Awaited<ReturnType<typeof reportList>>
>;
export type ReportListQueryError =
| UnauthorisedResponse
| InternalServerErrorResponse;
export const useReportList = <
TError = UnauthorisedResponse | InternalServerErrorResponse,
>(
params?: ReportListParams,
options?: {
swr?: SWRConfiguration<Awaited<ReturnType<typeof reportList>>, TError> & {
swrKey?: Key;
enabled?: boolean;
};
},
) => {
const { swr: swrOptions } = options ?? {};
const isEnabled = swrOptions?.enabled !== false;
const swrKey =
swrOptions?.swrKey ?? (() => (isEnabled ? getReportListKey(params) : null));
const swrFn = () => reportList(params);
const query = useSwr<Awaited<ReturnType<typeof swrFn>>, TError>(
swrKey,
swrFn,
swrOptions,
);
return {
swrKey,
...query,
};
};
/**
* Update a report's status and optionally assign handler. Requires the
`MANAGE_REPORTS` permission to set the status to anything other than
closed. In other words, regular members can only close their own reports
while "moderators" can acknowledge, assign and resolve reports.
*/
export const reportUpdate = (
reportId: string,
reportUpdateBody: ReportUpdateBody,
) => {
return fetcher<ReportUpdateOKResponse>({
url: `/reports/${reportId}`,
method: "PATCH",
headers: { "Content-Type": "application/json" },
data: reportUpdateBody,
});
};
export const getReportUpdateMutationFetcher = (reportId: string) => {
return (
_: Key,
{ arg }: { arg: ReportUpdateBody },
): Promise<ReportUpdateOKResponse> => {
return reportUpdate(reportId, arg);
};
};
export const getReportUpdateMutationKey = (reportId: string) =>
[`/reports/${reportId}`] as const;
export type ReportUpdateMutationResult = NonNullable<
Awaited<ReturnType<typeof reportUpdate>>
>;
export type ReportUpdateMutationError =
| BadRequestResponse
| UnauthorisedResponse
| ForbiddenResponse
| NotFoundResponse
| InternalServerErrorResponse;
export const useReportUpdate = <
TError =
| BadRequestResponse
| UnauthorisedResponse
| ForbiddenResponse
| NotFoundResponse
| InternalServerErrorResponse,
>(
reportId: string,
options?: {
swr?: SWRMutationConfiguration<
Awaited<ReturnType<typeof reportUpdate>>,
TError,
Key,
ReportUpdateBody,
Awaited<ReturnType<typeof reportUpdate>>
> & { swrKey?: string };
},
) => {
const { swr: swrOptions } = options ?? {};
const swrKey = swrOptions?.swrKey ?? getReportUpdateMutationKey(reportId);
const swrFn = getReportUpdateMutationFetcher(reportId);
const query = useSWRMutation(swrKey, swrFn, swrOptions);
return {
swrKey,
...query,
};
};