chore: migrates to PATCH for collection updates
This commit is contained in:
@@ -34,6 +34,20 @@ export const requests = {
|
||||
return fetch(url, formattedOptions);
|
||||
},
|
||||
|
||||
patch: (url: string, options: RequestInit = { headers: {} }): Promise<Response> => {
|
||||
const headers = options && options.headers ? { ...options.headers } : {};
|
||||
|
||||
const formattedOptions = {
|
||||
...options,
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
...headers,
|
||||
},
|
||||
};
|
||||
|
||||
return fetch(url, formattedOptions);
|
||||
},
|
||||
|
||||
delete: (url: string, options: RequestInit = { headers: {} }): Promise<Response> => {
|
||||
const headers = options && options.headers ? { ...options.headers } : {};
|
||||
return fetch(url, {
|
||||
|
||||
@@ -77,7 +77,7 @@ const Autosave: React.FC<Props> = ({ collection, global, id, publishedDocUpdated
|
||||
|
||||
if (collection && id) {
|
||||
url = `${serverURL}${api}/${collection.slug}/${id}?draft=true&autosave=true&locale=${locale}`;
|
||||
method = 'PUT';
|
||||
method = 'PATCH';
|
||||
}
|
||||
|
||||
if (global) {
|
||||
|
||||
@@ -25,7 +25,7 @@ const SaveDraft: React.FC = () => {
|
||||
|
||||
if (collection) {
|
||||
action = `${serverURL}${api}/${collection.slug}${id ? `/${id}` : ''}${search}`;
|
||||
if (id) method = 'PUT';
|
||||
if (id) method = 'PATCH';
|
||||
}
|
||||
|
||||
if (global) {
|
||||
|
||||
@@ -55,7 +55,7 @@ const Status: React.FC<Props> = () => {
|
||||
|
||||
if (collection) {
|
||||
url = `${serverURL}${api}/${collection.slug}/${id}?depth=0&locale=${locale}&fallback-locale=null`;
|
||||
method = 'put';
|
||||
method = 'PATCH';
|
||||
}
|
||||
if (global) {
|
||||
url = `${serverURL}${api}/globals/${global.slug}?depth=0&locale=${locale}&fallback-locale=null`;
|
||||
|
||||
@@ -27,7 +27,7 @@ export type Preferences = {
|
||||
export type Props = {
|
||||
disabled?: boolean
|
||||
onSubmit?: (fields: Fields, data: Data) => void
|
||||
method?: 'get' | 'put' | 'delete' | 'post'
|
||||
method?: 'get' | 'patch' | 'delete' | 'post'
|
||||
action?: string
|
||||
handleResponse?: (res: Response) => void
|
||||
onSuccess?: (json: unknown) => void
|
||||
|
||||
@@ -61,7 +61,7 @@ const DefaultAccount: React.FC<Props> = (props) => {
|
||||
<OperationContext.Provider value="update">
|
||||
<Form
|
||||
className={`${baseClass}__form`}
|
||||
method="put"
|
||||
method="patch"
|
||||
action={action}
|
||||
initialState={initialState}
|
||||
disabled={!hasSavePermission}
|
||||
|
||||
@@ -81,7 +81,7 @@ const DefaultEditView: React.FC<Props> = (props) => {
|
||||
<OperationContext.Provider value={operation}>
|
||||
<Form
|
||||
className={`${baseClass}__form`}
|
||||
method={id ? 'put' : 'post'}
|
||||
method={id ? 'patch' : 'post'}
|
||||
action={action}
|
||||
onSuccess={onSave}
|
||||
disabled={!hasSavePermission}
|
||||
|
||||
@@ -10,7 +10,7 @@ export type UpdateResult = {
|
||||
};
|
||||
|
||||
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.');
|
||||
req.payload.logger.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);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { SanitizedConfig } from '../../config/types';
|
||||
export default (config: SanitizedConfig) => (
|
||||
(req: Request, res: Response, next: NextFunction) => {
|
||||
if (config.cors) {
|
||||
res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
|
||||
res.header('Access-Control-Allow-Methods', 'PUT, PATCH, POST, GET, DELETE, OPTIONS');
|
||||
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization, Content-Encoding');
|
||||
|
||||
if (config.cors === '*') {
|
||||
|
||||
@@ -174,7 +174,7 @@ export class RESTClient {
|
||||
const response = await fetch(`${this.serverURL}/api/${slug || this.defaultSlug}/${id}${formattedQs}`, {
|
||||
body: JSON.stringify(data),
|
||||
headers,
|
||||
method: 'put',
|
||||
method: 'PATCH',
|
||||
});
|
||||
const { status } = response;
|
||||
const json = await response.json();
|
||||
|
||||
Reference in New Issue
Block a user