Add meta to ApiPayload interfaces

This commit is contained in:
Alexander Skvortsov 2021-12-01 16:04:15 -05:00
parent b0504597da
commit 0bdb018ad4
No known key found for this signature in database
GPG Key ID: C4E3BBF9C3412B4C
2 changed files with 10 additions and 8 deletions

View File

@ -1,6 +1,6 @@
import app from '../common/app'; import app from '../common/app';
import { FlarumRequestOptions } from './Application'; import { FlarumRequestOptions } from './Application';
import Store, { ApiPayloadSingle, ApiResponseSingle } from './Store'; import Store, { ApiPayloadSingle, ApiResponseSingle, MetaInformation } from './Store';
export interface ModelIdentifier { export interface ModelIdentifier {
type: string; type: string;
@ -162,7 +162,7 @@ export default abstract class Model {
*/ */
save( save(
attributes: SaveAttributes, attributes: SaveAttributes,
options: Omit<FlarumRequestOptions<ApiPayloadSingle>, 'url'> & { meta?: any } = {} options: Omit<FlarumRequestOptions<ApiPayloadSingle>, 'url'> & { meta?: MetaInformation } = {}
): Promise<ApiResponseSingle<this>> { ): Promise<ApiResponseSingle<this>> {
const data: ModelData & { id?: string } = { const data: ModelData & { id?: string } = {
type: this.data.type, type: this.data.type,

View File

@ -2,13 +2,15 @@ import app from '../common/app';
import { FlarumRequestOptions } from './Application'; import { FlarumRequestOptions } from './Application';
import Model, { ModelData, SavedModelData } from './Model'; import Model, { ModelData, SavedModelData } from './Model';
export interface MetaInformation {
[key: string]: any;
}
export interface ApiQueryParamsSingle { export interface ApiQueryParamsSingle {
fields?: string[]; fields?: string[];
include?: string; include?: string;
bySlug?: boolean; bySlug?: boolean;
meta?: { meta?: MetaInformation;
[key: string]: any;
};
} }
export interface ApiQueryParamsPlural { export interface ApiQueryParamsPlural {
@ -25,9 +27,7 @@ export interface ApiQueryParamsPlural {
size?: number; size?: number;
}; };
sort?: string; sort?: string;
meta?: { meta?: MetaInformation;
[key: string]: any;
};
} }
export type ApiQueryParams = ApiQueryParamsPlural | ApiQueryParamsSingle; export type ApiQueryParams = ApiQueryParamsPlural | ApiQueryParamsSingle;
@ -35,6 +35,7 @@ export type ApiQueryParams = ApiQueryParamsPlural | ApiQueryParamsSingle;
export interface ApiPayloadSingle { export interface ApiPayloadSingle {
data: SavedModelData; data: SavedModelData;
included?: SavedModelData[]; included?: SavedModelData[];
meta?: MetaInformation;
} }
export interface ApiPayloadPlural { export interface ApiPayloadPlural {
@ -45,6 +46,7 @@ export interface ApiPayloadPlural {
next?: string; next?: string;
prev?: string; prev?: string;
}; };
meta?: MetaInformation;
} }
export type ApiPayload = ApiPayloadSingle | ApiPayloadPlural; export type ApiPayload = ApiPayloadSingle | ApiPayloadPlural;