chore: rename publishVersion to restoreVersion (#438)

This commit is contained in:
Dan Ribbens
2022-02-10 16:35:03 -05:00
committed by GitHub
parent 7cfb2f7f02
commit b159e148db
16 changed files with 45 additions and 50 deletions

View File

@@ -15,7 +15,7 @@ import buildVersionWhereInputType from '../../graphql/schema/buildVersionWhereIn
function registerCollections(): void {
const {
findVersions, findVersionByID, publishVersion,
findVersions, findVersionByID, restoreVersion,
create, find, findByID, deleteResolver, update,
} = this.graphQL.resolvers.collections;
@@ -206,7 +206,7 @@ function registerCollections(): void {
args: {
id: { type: GraphQLString },
},
resolve: publishVersion(collection),
resolve: restoreVersion(collection),
};
}

View File

@@ -15,7 +15,7 @@ export type Resolver = (
}
) => Promise<Document>
export default function publishVersion(collection: Collection): Resolver {
export default function restoreVersion(collection: Collection): Resolver {
async function resolver(_, args, context) {
if (args.locale) context.req.locale = args.locale;
if (args.fallbackLocale) context.req.fallbackLocale = args.fallbackLocale;
@@ -26,10 +26,10 @@ export default function publishVersion(collection: Collection): Resolver {
req: context.req,
};
await this.operations.collections.publishVersion(options);
await this.operations.collections.restoreVersion(options);
return true;
}
const findVersionByIDResolver = resolver.bind(this);
return findVersionByIDResolver;
const restoreVersionResolver = resolver.bind(this);
return restoreVersionResolver;
}

View File

@@ -106,7 +106,7 @@ export default function registerCollections(ctx: Payload): void {
findByID,
findVersions,
findVersionByID,
publishVersion,
restoreVersion,
delete: deleteHandler,
} = ctx.requestHandlers.collections;
@@ -182,7 +182,7 @@ export default function registerCollections(ctx: Payload): void {
router.route(`/${slug}/versions/:id`)
.get(findVersionByID)
.post(publishVersion);
.post(restoreVersion);
}
router.route(`/${slug}`)

View File

@@ -6,7 +6,7 @@ import localDelete from './delete';
import auth from '../../../auth/operations/local';
import findVersionByID from './findVersionByID';
import findVersions from './findVersions';
import publishVersion from './publishVersion';
import restoreVersion from './restoreVersion';
export default {
find,
@@ -17,5 +17,5 @@ export default {
auth,
findVersionByID,
findVersions,
publishVersion,
restoreVersion,
};

View File

@@ -13,7 +13,7 @@ export type Options = {
showHiddenFields?: boolean
}
export default async function publishVersion<T extends TypeWithVersion<T> = any>(options: Options): Promise<T> {
export default async function restoreVersion<T extends TypeWithVersion<T> = any>(options: Options): Promise<T> {
const {
collection: collectionSlug,
depth,
@@ -44,5 +44,5 @@ export default async function publishVersion<T extends TypeWithVersion<T> = any>
},
};
return this.operations.collections.publishVersion(args);
return this.operations.collections.restoreVersion(args);
}

View File

@@ -20,7 +20,7 @@ export type Arguments = {
depth?: number
}
async function publishVersion<T extends TypeWithID = any>(this: Payload, args: Arguments): Promise<T> {
async function restoreVersion<T extends TypeWithID = any>(this: Payload, args: Arguments): Promise<T> {
const {
collection: {
Model,
@@ -171,4 +171,4 @@ async function publishVersion<T extends TypeWithID = any>(this: Payload, args: A
return result;
}
export default publishVersion;
export default restoreVersion;

View File

@@ -9,7 +9,7 @@ export type RestoreResult = {
doc: Document
};
export default async function publishVersion(req: PayloadRequest, res: Response, next: NextFunction): Promise<Response<RestoreResult> | void> {
export default async function restoreVersion(req: PayloadRequest, res: Response, next: NextFunction): Promise<Response<RestoreResult> | void> {
const options = {
req,
collection: req.collection,
@@ -18,7 +18,7 @@ export default async function publishVersion(req: PayloadRequest, res: Response,
};
try {
const doc = await this.operations.collections.publishVersion(options);
const doc = await this.operations.collections.restoreVersion(options);
return res.status(httpStatus.OK).json({
...formatSuccessResponse('Restored successfully.', 'message'),
doc,

View File

@@ -54,7 +54,7 @@ export default function initGlobals(ctx: Payload): void {
router.route(`/globals/${global.slug}/versions/:id`)
.get(ctx.requestHandlers.globals.findVersionByID(global))
.post(ctx.requestHandlers.globals.publishVersion(global));
.post(ctx.requestHandlers.globals.restoreVersion(global));
}
});

View File

@@ -23,7 +23,7 @@ export type Arguments = {
// TODO: finish
async function publishVersion<T extends TypeWithVersion<T> = any>(this: Payload, args: Arguments): Promise<PaginatedDocs<T>> {
async function restoreVersion<T extends TypeWithVersion<T> = any>(this: Payload, args: Arguments): Promise<PaginatedDocs<T>> {
const { globals: { Model } } = this;
const {
@@ -143,4 +143,4 @@ async function publishVersion<T extends TypeWithVersion<T> = any>(this: Payload,
return result;
}
export default publishVersion;
export default restoreVersion;

View File

@@ -15,7 +15,7 @@ export default function (globalConfig: SanitizedGlobalConfig) {
};
try {
const doc = await this.operations.globals.publishVersion(options);
const doc = await this.operations.globals.restoreVersion(options);
return res.status(httpStatus.OK).json({
...formatSuccessResponse('Restored successfully.', 'message'),
doc,
@@ -25,6 +25,6 @@ export default function (globalConfig: SanitizedGlobalConfig) {
}
}
const publishVersionHandler = handler.bind(this);
return publishVersionHandler;
const restoreVersionHandler = handler.bind(this);
return restoreVersionHandler;
}

View File

@@ -16,7 +16,7 @@ import update from '../collections/graphql/resolvers/update';
import deleteResolver from '../collections/graphql/resolvers/delete';
import findVersions from '../collections/graphql/resolvers/findVersions';
import findVersionByID from '../collections/graphql/resolvers/findVersionByID';
import publishVersion from '../collections/graphql/resolvers/publishVersion';
import restoreVersion from '../collections/graphql/resolvers/restoreVersion';
import findOne from '../globals/graphql/resolvers/findOne';
import globalUpdate from '../globals/graphql/resolvers/update';
@@ -30,7 +30,7 @@ export type GraphQLResolvers = {
findVersions: typeof findVersions,
findByID: typeof findByID,
findVersionByID: typeof findVersionByID,
publishVersion: typeof publishVersion,
restoreVersion: typeof restoreVersion,
update: typeof update,
deleteResolver: typeof deleteResolver,
auth: {
@@ -61,7 +61,7 @@ function bindResolvers(ctx: Payload): void {
findVersions: findVersions.bind(ctx),
findByID: findByID.bind(ctx),
findVersionByID: findVersionByID.bind(ctx),
publishVersion: publishVersion.bind(ctx),
restoreVersion: restoreVersion.bind(ctx),
update: update.bind(ctx),
deleteResolver: deleteResolver.bind(ctx),
auth: {

View File

@@ -48,7 +48,7 @@ import { Options as UpdateOptions } from './collections/operations/local/update'
import { Options as DeleteOptions } from './collections/operations/local/delete';
import { Options as FindVersionsOptions } from './collections/operations/local/findVersions';
import { Options as FindVersionByIDOptions } from './collections/operations/local/findVersionByID';
import { Options as RestoreVersionOptions } from './collections/operations/local/publishVersion';
import { Options as RestoreVersionOptions } from './collections/operations/local/restoreVersion';
import { Result } from './auth/operations/login';
require('isomorphic-fetch');
@@ -301,19 +301,14 @@ export class Payload {
* @param options
* @returns version with specified ID
*/
publishVersion = async <T extends TypeWithVersion<T> = any>(options: RestoreVersionOptions): Promise<T> => {
let { publishVersion } = localOperations;
publishVersion = publishVersion.bind(this);
return publishVersion(options);
restoreVersion = async <T extends TypeWithVersion<T> = any>(options: RestoreVersionOptions): Promise<T> => {
let { restoreVersion } = localOperations;
restoreVersion = restoreVersion.bind(this);
return restoreVersion(options);
}
// TODO: globals
// findVersionGlobal
// findVersionByIDGlobal
// publishVersionGlobal
// TODO:
// graphql operations & request handlers, where
// tests
// graphql Global Versions
login = async <T extends TypeWithID = any>(options): Promise<Result & { user: T}> => {
let { login } = localOperations.auth;

View File

@@ -16,14 +16,14 @@ import find from '../collections/operations/find';
import findByID from '../collections/operations/findByID';
import findVersions from '../collections/operations/findVersions';
import findVersionByID from '../collections/operations/findVersionByID';
import publishVersion from '../collections/operations/publishVersion';
import restoreVersion from '../collections/operations/restoreVersion';
import update from '../collections/operations/update';
import deleteHandler from '../collections/operations/delete';
import findOne from '../globals/operations/findOne';
import findGlobalVersions from '../globals/operations/findVersions';
import findGlobalVersionByID from '../globals/operations/findVersionByID';
import publishGlobalVersion from '../globals/operations/publishVersion';
import restoreGlobalVersion from '../globals/operations/restoreVersion';
import globalUpdate from '../globals/operations/update';
import preferenceUpdate from '../preferences/operations/update';
@@ -37,7 +37,7 @@ export type Operations = {
findByID: typeof findByID
findVersions: typeof findVersions
findVersionByID: typeof findVersionByID
publishVersion: typeof publishVersion
restoreVersion: typeof restoreVersion
update: typeof update
delete: typeof deleteHandler
auth: {
@@ -58,7 +58,7 @@ export type Operations = {
findOne: typeof findOne
findVersions: typeof findGlobalVersions
findVersionByID: typeof findGlobalVersionByID
publishVersion: typeof publishGlobalVersion
restoreVersion: typeof restoreGlobalVersion
update: typeof globalUpdate
}
preferences: {
@@ -76,7 +76,7 @@ function bindOperations(ctx: Payload): void {
findByID: findByID.bind(ctx),
findVersions: findVersions.bind(ctx),
findVersionByID: findVersionByID.bind(ctx),
publishVersion: publishVersion.bind(ctx),
restoreVersion: restoreVersion.bind(ctx),
update: update.bind(ctx),
delete: deleteHandler.bind(ctx),
auth: {
@@ -97,7 +97,7 @@ function bindOperations(ctx: Payload): void {
findOne: findOne.bind(ctx),
findVersions: findGlobalVersions.bind(ctx),
findVersionByID: findGlobalVersionByID.bind(ctx),
publishVersion: publishGlobalVersion.bind(ctx),
restoreVersion: restoreGlobalVersion.bind(ctx),
update: globalUpdate.bind(ctx),
},
preferences: {

View File

@@ -15,14 +15,14 @@ import find from '../collections/requestHandlers/find';
import findByID from '../collections/requestHandlers/findByID';
import findVersions from '../collections/requestHandlers/findVersions';
import findVersionByID from '../collections/requestHandlers/findVersionByID';
import publishVersion from '../collections/requestHandlers/publishVersion';
import restoreVersion from '../collections/requestHandlers/restoreVersion';
import update from '../collections/requestHandlers/update';
import deleteHandler from '../collections/requestHandlers/delete';
import findOne from '../globals/requestHandlers/findOne';
import findGlobalVersions from '../globals/requestHandlers/findVersions';
import findGlobalVersionByID from '../globals/requestHandlers/findVersionByID';
import publishGlobalVersion from '../globals/requestHandlers/publishVersion';
import restoreGlobalVersion from '../globals/requestHandlers/restoreVersion';
import globalUpdate from '../globals/requestHandlers/update';
import { Payload } from '../index';
import preferenceUpdate from '../preferences/requestHandlers/update';
@@ -36,7 +36,7 @@ export type RequestHandlers = {
findByID: typeof findByID,
findVersions: typeof findVersions
findVersionByID: typeof findVersionByID,
publishVersion: typeof publishVersion,
restoreVersion: typeof restoreVersion,
update: typeof update,
delete: typeof deleteHandler,
auth: {
@@ -58,7 +58,7 @@ export type RequestHandlers = {
update: typeof globalUpdate,
findVersions: typeof findGlobalVersions
findVersionByID: typeof findGlobalVersionByID
publishVersion: typeof publishGlobalVersion
restoreVersion: typeof restoreGlobalVersion
},
preferences: {
update: typeof preferenceUpdate,
@@ -75,7 +75,7 @@ function bindRequestHandlers(ctx: Payload): void {
findByID: findByID.bind(ctx),
findVersions: findVersions.bind(ctx),
findVersionByID: findVersionByID.bind(ctx),
publishVersion: publishVersion.bind(ctx),
restoreVersion: restoreVersion.bind(ctx),
update: update.bind(ctx),
delete: deleteHandler.bind(ctx),
auth: {
@@ -97,7 +97,7 @@ function bindRequestHandlers(ctx: Payload): void {
update: globalUpdate.bind(ctx),
findVersions: findGlobalVersions.bind(ctx),
findVersionByID: findGlobalVersionByID.bind(ctx),
publishVersion: publishGlobalVersion.bind(ctx),
restoreVersion: restoreGlobalVersion.bind(ctx),
},
preferences: {
update: preferenceUpdate.bind(ctx),