Merge commit 'refs/pull/863/head' of github.com:payloadcms/payload

This commit is contained in:
James
2022-08-15 18:55:07 -07:00
3 changed files with 13 additions and 2 deletions

View File

@@ -29,7 +29,7 @@ Each collection is mounted using its `slug` value. For example, if a collection'
| `GET` | `/api/{collectionSlug}` | Find paginated documents |
| `GET` | `/api/{collectionSlug}/:id` | Find a specific document by ID |
| `POST` | `/api/{collectionSlug}` | Create a new document |
| `PUT` | `/api/{collectionSlug}/:id` | Update a document by ID |
| `PATCH` | `/api/{collectionSlug}/:id` | Update a document by ID |
| `DELETE` | `/api/{collectionSlug}/:id` | Delete an existing document by ID |
##### Additional `find` query parameters

View File

@@ -16,7 +16,7 @@ import findVersionByID from './requestHandlers/findVersionByID';
import restoreVersion from './requestHandlers/restoreVersion';
import deleteHandler from './requestHandlers/delete';
import findByID from './requestHandlers/findByID';
import update from './requestHandlers/update';
import update, { deprecatedUpdate } from './requestHandlers/update';
import logoutHandler from '../auth/requestHandlers/logout';
const buildEndpoints = (collection: SanitizedCollectionConfig): Endpoint[] => {
@@ -122,6 +122,11 @@ const buildEndpoints = (collection: SanitizedCollectionConfig): Endpoint[] => {
{
path: '/:id',
method: 'put',
handler: deprecatedUpdate,
},
{
path: '/:id',
method: 'patch',
handler: update,
},
{

View File

@@ -9,6 +9,12 @@ export type UpdateResult = {
doc: Document
};
export async function deprecatedUpdate(req: PayloadRequest, res: Response, next: NextFunction): Promise<Response<UpdateResult> | void> {
console.warn('The PUT method is deprecated and will no longer be supported in a future release. Please use the PATCH method for update requests.');
return updateHandler(req, res, next);
}
export default async function updateHandler(req: PayloadRequest, res: Response, next: NextFunction): Promise<Response<UpdateResult> | void> {
try {
const draft = req.query.draft === 'true';