Common api - Destroy and delete queries (#15177)
Done ⬇️ Gql : move delete and destroy logic to common Rest : - rename 'delete' handler to 'destroy' - create soft delete handlers (named 'delete') : one and many - create destroy many handler - update doc --> Rest api gains NEW soft delete one/many + destroy many capabilities closes : https://github.com/twentyhq/core-team-issues/issues/1579
This commit is contained in:
@@ -13,6 +13,7 @@ import {
|
||||
computeIdPathParameter,
|
||||
computeLimitParameters,
|
||||
computeOrderByParameters,
|
||||
computeSoftDeleteParameters,
|
||||
computeStartingAfterParameters,
|
||||
computeUpsertParameters,
|
||||
} from 'src/engine/core-modules/open-api/utils/parameters.utils';
|
||||
@@ -210,6 +211,7 @@ export const computeParameterComponents = (
|
||||
filter: computeFilterParameters(),
|
||||
depth: computeDepthParameters(),
|
||||
upsert: computeUpsertParameters(),
|
||||
softDelete: computeSoftDeleteParameters(),
|
||||
orderBy: computeOrderByParameters(),
|
||||
limit: computeLimitParameters(fromMetadata),
|
||||
};
|
||||
|
||||
@@ -75,6 +75,20 @@ export const computeUpsertParameters = (): OpenAPIV3_1.ParameterObject => {
|
||||
};
|
||||
};
|
||||
|
||||
export const computeSoftDeleteParameters = (): OpenAPIV3_1.ParameterObject => {
|
||||
return {
|
||||
name: 'soft_delete',
|
||||
in: 'query',
|
||||
description:
|
||||
'If true, soft deletes the objects. If false, objects are permanently deleted.',
|
||||
required: false,
|
||||
schema: {
|
||||
type: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const computeFilterParameters = (): OpenAPIV3_1.ParameterObject => {
|
||||
return {
|
||||
name: 'filter',
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
import {
|
||||
getCreateManyResponse201,
|
||||
getCreateOneResponse201,
|
||||
getDeleteManyResponse200,
|
||||
getDeleteResponse200,
|
||||
getFindDuplicatesResponse200,
|
||||
getFindManyResponse200,
|
||||
@@ -79,6 +80,20 @@ export const computeManyResultPath = (
|
||||
'401': { $ref: '#/components/responses/401' },
|
||||
},
|
||||
},
|
||||
delete: {
|
||||
tags: [item.namePlural],
|
||||
summary: `Delete Many ${item.namePlural}`,
|
||||
operationId: `deleteMany${capitalize(item.namePlural)}`,
|
||||
parameters: [
|
||||
{ $ref: '#/components/parameters/filter' },
|
||||
{ $ref: '#/components/parameters/softDelete' },
|
||||
],
|
||||
responses: {
|
||||
'200': getDeleteManyResponse200(item),
|
||||
'400': { $ref: '#/components/responses/400' },
|
||||
'401': { $ref: '#/components/responses/401' },
|
||||
},
|
||||
},
|
||||
} as OpenAPIV3_1.PathItemObject;
|
||||
};
|
||||
|
||||
@@ -105,7 +120,10 @@ export const computeSingleResultPath = (
|
||||
tags: [item.namePlural],
|
||||
summary: `Delete One ${item.nameSingular}`,
|
||||
operationId: `deleteOne${capitalize(item.nameSingular)}`,
|
||||
parameters: [{ $ref: '#/components/parameters/idPath' }],
|
||||
parameters: [
|
||||
{ $ref: '#/components/parameters/idPath' },
|
||||
{ $ref: '#/components/parameters/softDelete' },
|
||||
],
|
||||
responses: {
|
||||
'200': getDeleteResponse200(item),
|
||||
'400': { $ref: '#/components/responses/400' },
|
||||
|
||||
@@ -174,6 +174,40 @@ export const getUpdateOneResponse200 = (
|
||||
};
|
||||
};
|
||||
|
||||
export const getDeleteManyResponse200 = (
|
||||
item: Pick<ObjectMetadataEntity, 'namePlural'>,
|
||||
) => {
|
||||
return {
|
||||
description: 'Successful operation',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
data: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
[`delete${capitalize(item.namePlural)}`]: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
format: 'uuid',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const getDeleteResponse200 = (
|
||||
item: Pick<ObjectMetadataEntity, 'nameSingular'>,
|
||||
fromMetadata = false,
|
||||
|
||||
Reference in New Issue
Block a user