feat: add local api for versions on globals
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
import { Document, Where } from 'payload/types';
|
||||
import { Response } from 'express';
|
||||
import { Document, Where } from '../../../types';
|
||||
import { SanitizedGlobalConfig } from '../../config/types';
|
||||
import { PayloadRequest } from '../../../express/types';
|
||||
|
||||
// export type Resolver = (
|
||||
// _: unknown,
|
||||
// args: {
|
||||
// locale?: string
|
||||
// fallbackLocale?: string
|
||||
// where: Where
|
||||
// limit?: number
|
||||
// page?: number
|
||||
// sort?: string
|
||||
// },
|
||||
// context: {
|
||||
// req: PayloadRequest,
|
||||
// res: Response
|
||||
// }
|
||||
// ) => Promise<Document>
|
||||
export type Resolver = (
|
||||
_: unknown,
|
||||
args: {
|
||||
locale?: string
|
||||
fallbackLocale?: string
|
||||
where: Where
|
||||
limit?: number
|
||||
page?: number
|
||||
sort?: string
|
||||
},
|
||||
context: {
|
||||
req: PayloadRequest,
|
||||
res: Response
|
||||
}
|
||||
) => Promise<Document>
|
||||
|
||||
function findVersions(globalConfig: SanitizedGlobalConfig) {
|
||||
async function resolver(_, args, context) {
|
||||
|
||||
49
src/globals/operations/local/findVersionByID.ts
Normal file
49
src/globals/operations/local/findVersionByID.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { Document } from '../../../types';
|
||||
import { TypeWithVersion } from '../../../versions/types';
|
||||
|
||||
export type Options = {
|
||||
slug: string
|
||||
id: string
|
||||
depth?: number
|
||||
locale?: string
|
||||
fallbackLocale?: string
|
||||
user?: Document
|
||||
overrideAccess?: boolean
|
||||
showHiddenFields?: boolean
|
||||
disableErrors?: boolean
|
||||
}
|
||||
|
||||
async function findVersionByID<T extends TypeWithVersion<T> = any>(options: Options): Promise<Document> {
|
||||
const {
|
||||
slug: globalSlug,
|
||||
depth,
|
||||
id,
|
||||
locale = this?.config?.localization?.defaultLocale,
|
||||
fallbackLocale = null,
|
||||
user,
|
||||
overrideAccess = true,
|
||||
disableErrors = false,
|
||||
showHiddenFields,
|
||||
} = options;
|
||||
|
||||
const globalConfig = this.globals.config.find((config) => config.slug === globalSlug);
|
||||
|
||||
return this.operations.globals.findVersionByID({
|
||||
slug: globalSlug,
|
||||
depth,
|
||||
id,
|
||||
globalConfig,
|
||||
overrideAccess,
|
||||
disableErrors,
|
||||
showHiddenFields,
|
||||
req: {
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
locale,
|
||||
fallbackLocale,
|
||||
payload: this,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export default findVersionByID;
|
||||
56
src/globals/operations/local/findVersions.ts
Normal file
56
src/globals/operations/local/findVersions.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { Document, Where } from '../../../types';
|
||||
import { PaginatedDocs } from '../../../mongoose/types';
|
||||
import { TypeWithVersion } from '../../../versions/types';
|
||||
|
||||
export type Options = {
|
||||
slug: string
|
||||
depth?: number
|
||||
page?: number
|
||||
limit?: number
|
||||
locale?: string
|
||||
fallbackLocale?: string
|
||||
user?: Document
|
||||
overrideAccess?: boolean
|
||||
showHiddenFields?: boolean
|
||||
disableErrors?: boolean
|
||||
sort?: string
|
||||
where?: Where
|
||||
}
|
||||
|
||||
export default async function findVersions<T extends TypeWithVersion<T> = any>(options: Options): Promise<PaginatedDocs<T>> {
|
||||
const {
|
||||
slug: globalSlug,
|
||||
depth,
|
||||
page,
|
||||
limit,
|
||||
where,
|
||||
locale = this?.config?.localization?.defaultLocale,
|
||||
fallbackLocale = null,
|
||||
user,
|
||||
overrideAccess = true,
|
||||
showHiddenFields,
|
||||
disableErrors = false,
|
||||
sort,
|
||||
} = options;
|
||||
|
||||
const globalConfig = this.globals.config.find((config) => config.slug === globalSlug);
|
||||
|
||||
return this.operations.globals.findVersions({
|
||||
where,
|
||||
page,
|
||||
limit,
|
||||
depth,
|
||||
globalConfig,
|
||||
sort,
|
||||
overrideAccess,
|
||||
showHiddenFields,
|
||||
disableErrors,
|
||||
req: {
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
locale,
|
||||
fallbackLocale,
|
||||
payload: this,
|
||||
},
|
||||
});
|
||||
}
|
||||
37
src/globals/operations/local/restoreVersion.ts
Normal file
37
src/globals/operations/local/restoreVersion.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { Document } from '../../../types';
|
||||
import { TypeWithVersion } from '../../../versions/types';
|
||||
|
||||
export type Options = {
|
||||
slug: string
|
||||
id: string
|
||||
depth?: number
|
||||
user?: Document
|
||||
overrideAccess?: boolean
|
||||
showHiddenFields?: boolean
|
||||
}
|
||||
|
||||
export default async function restoreVersion<T extends TypeWithVersion<T> = any>(options: Options): Promise<T> {
|
||||
const {
|
||||
slug: globalSlug,
|
||||
depth,
|
||||
id,
|
||||
user,
|
||||
overrideAccess = true,
|
||||
showHiddenFields,
|
||||
} = options;
|
||||
|
||||
const globalConfig = this.globals[globalSlug];
|
||||
|
||||
return this.operations.globals.restoreVersion({
|
||||
depth,
|
||||
globalConfig,
|
||||
overrideAccess,
|
||||
id,
|
||||
showHiddenFields,
|
||||
req: {
|
||||
user,
|
||||
payloadAPI: 'local',
|
||||
payload: this,
|
||||
},
|
||||
});
|
||||
}
|
||||
@@ -10,9 +10,6 @@ import { NotFound } from '../../errors';
|
||||
export type Arguments = {
|
||||
globalConfig: SanitizedGlobalConfig
|
||||
id: string
|
||||
page?: number
|
||||
limit?: number
|
||||
sort?: string
|
||||
depth?: number
|
||||
req?: PayloadRequest
|
||||
overrideAccess?: boolean
|
||||
|
||||
Reference in New Issue
Block a user