700 fix rest api issues (#11326)
fixes issues listed here https://github.com/twentyhq/core-team-issues/issues/700
This commit is contained in:
@ -7,7 +7,7 @@ const formatMessage = (error: BaseGraphQLError) => {
|
|||||||
? error.extensions.response?.error ||
|
? error.extensions.response?.error ||
|
||||||
error.extensions.response ||
|
error.extensions.response ||
|
||||||
error.message
|
error.message
|
||||||
: error.error;
|
: error.error || error.message;
|
||||||
|
|
||||||
formattedMessage = formattedMessage
|
formattedMessage = formattedMessage
|
||||||
.replace(/"/g, "'")
|
.replace(/"/g, "'")
|
||||||
|
|||||||
@ -6,10 +6,14 @@ import { capitalize } from 'twenty-shared/utils';
|
|||||||
export class DeleteMetadataQueryFactory {
|
export class DeleteMetadataQueryFactory {
|
||||||
create(objectNameSingular: string): string {
|
create(objectNameSingular: string): string {
|
||||||
const objectNameCapitalized = capitalize(objectNameSingular);
|
const objectNameCapitalized = capitalize(objectNameSingular);
|
||||||
|
const formattedObjectName =
|
||||||
|
objectNameCapitalized === 'RelationMetadata'
|
||||||
|
? 'Relation'
|
||||||
|
: objectNameCapitalized;
|
||||||
|
|
||||||
return `
|
return `
|
||||||
mutation Delete${objectNameCapitalized}($input: DeleteOne${objectNameCapitalized}Input!) {
|
mutation Delete${objectNameCapitalized}($input: DeleteOne${formattedObjectName}Input!) {
|
||||||
deleteOne${objectNameCapitalized}(input: $input) {
|
deleteOne${formattedObjectName}(input: $input) {
|
||||||
id
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,7 +77,7 @@ export const fetchMetadataFields = (objectNamePlural: string) => {
|
|||||||
`;
|
`;
|
||||||
case 'fields':
|
case 'fields':
|
||||||
return fields;
|
return fields;
|
||||||
case 'relations':
|
case 'relationMetadata':
|
||||||
return `
|
return `
|
||||||
id
|
id
|
||||||
relationType
|
relationType
|
||||||
|
|||||||
@ -26,19 +26,19 @@ export const parseMetadataPath = (
|
|||||||
case 'fields':
|
case 'fields':
|
||||||
return {
|
return {
|
||||||
objectNameSingular: 'field',
|
objectNameSingular: 'field',
|
||||||
objectNamePlural: objectName,
|
objectNamePlural: 'fields',
|
||||||
id: queryAction[1],
|
id: queryAction[1],
|
||||||
};
|
};
|
||||||
case 'objects':
|
case 'objects':
|
||||||
return {
|
return {
|
||||||
objectNameSingular: 'object',
|
objectNameSingular: 'object',
|
||||||
objectNamePlural: objectName,
|
objectNamePlural: 'objects',
|
||||||
id: queryAction[1],
|
id: queryAction[1],
|
||||||
};
|
};
|
||||||
case 'relations':
|
case 'relations':
|
||||||
return {
|
return {
|
||||||
objectNameSingular: 'relation',
|
objectNameSingular: 'relationMetadata',
|
||||||
objectNamePlural: objectName,
|
objectNamePlural: 'relationMetadata',
|
||||||
id: queryAction[1],
|
id: queryAction[1],
|
||||||
};
|
};
|
||||||
default:
|
default:
|
||||||
@ -47,11 +47,14 @@ export const parseMetadataPath = (
|
|||||||
} else {
|
} else {
|
||||||
switch (objectName) {
|
switch (objectName) {
|
||||||
case 'fields':
|
case 'fields':
|
||||||
return { objectNameSingular: 'field', objectNamePlural: objectName };
|
return { objectNameSingular: 'field', objectNamePlural: 'fields' };
|
||||||
case 'objects':
|
case 'objects':
|
||||||
return { objectNameSingular: 'object', objectNamePlural: objectName };
|
return { objectNameSingular: 'object', objectNamePlural: 'objects' };
|
||||||
case 'relations':
|
case 'relations':
|
||||||
return { objectNameSingular: 'relation', objectNamePlural: objectName };
|
return {
|
||||||
|
objectNameSingular: 'relationMetadata',
|
||||||
|
objectNamePlural: 'relationMetadata',
|
||||||
|
};
|
||||||
default:
|
default:
|
||||||
return { objectNameSingular: '', objectNamePlural: '' };
|
return { objectNameSingular: '', objectNamePlural: '' };
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,14 +7,18 @@ import {
|
|||||||
Res,
|
Res,
|
||||||
Patch,
|
Patch,
|
||||||
Put,
|
Put,
|
||||||
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
|
|
||||||
import { Request, Response } from 'express';
|
import { Request, Response } from 'express';
|
||||||
|
|
||||||
import { RestApiMetadataService } from 'src/engine/api/rest/metadata/rest-api-metadata.service';
|
import { RestApiMetadataService } from 'src/engine/api/rest/metadata/rest-api-metadata.service';
|
||||||
import { cleanGraphQLResponse } from 'src/engine/api/rest/utils/clean-graphql-response.utils';
|
import { cleanGraphQLResponse } from 'src/engine/api/rest/utils/clean-graphql-response.utils';
|
||||||
|
import { JwtAuthGuard } from 'src/engine/guards/jwt-auth.guard';
|
||||||
|
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
|
||||||
|
|
||||||
@Controller('rest/metadata/*')
|
@Controller('rest/metadata/*')
|
||||||
|
@UseGuards(JwtAuthGuard, WorkspaceAuthGuard)
|
||||||
export class RestApiMetadataController {
|
export class RestApiMetadataController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly restApiMetadataService: RestApiMetadataService,
|
private readonly restApiMetadataService: RestApiMetadataService,
|
||||||
|
|||||||
@ -174,16 +174,6 @@ export class OpenApiService {
|
|||||||
},
|
},
|
||||||
} as OpenAPIV3_1.PathItemObject;
|
} as OpenAPIV3_1.PathItemObject;
|
||||||
path[`/${item.namePlural}/{id}`] = {
|
path[`/${item.namePlural}/{id}`] = {
|
||||||
get: {
|
|
||||||
tags: [item.namePlural],
|
|
||||||
summary: `Find One ${item.nameSingular}`,
|
|
||||||
parameters: [{ $ref: '#/components/parameters/idPath' }],
|
|
||||||
responses: {
|
|
||||||
'200': getFindOneResponse200(item),
|
|
||||||
'400': { $ref: '#/components/responses/400' },
|
|
||||||
'401': { $ref: '#/components/responses/401' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
delete: {
|
delete: {
|
||||||
tags: [item.namePlural],
|
tags: [item.namePlural],
|
||||||
summary: `Delete One ${item.nameSingular}`,
|
summary: `Delete One ${item.nameSingular}`,
|
||||||
@ -196,6 +186,16 @@ export class OpenApiService {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
...(item.nameSingular !== 'relation' && {
|
...(item.nameSingular !== 'relation' && {
|
||||||
|
get: {
|
||||||
|
tags: [item.namePlural],
|
||||||
|
summary: `Find One ${item.nameSingular}`,
|
||||||
|
parameters: [{ $ref: '#/components/parameters/idPath' }],
|
||||||
|
responses: {
|
||||||
|
'200': getFindOneResponse200(item),
|
||||||
|
'400': { $ref: '#/components/responses/400' },
|
||||||
|
'401': { $ref: '#/components/responses/401' },
|
||||||
|
},
|
||||||
|
},
|
||||||
patch: {
|
patch: {
|
||||||
tags: [item.namePlural],
|
tags: [item.namePlural],
|
||||||
summary: `Update One ${item.nameSingular}`,
|
summary: `Update One ${item.nameSingular}`,
|
||||||
|
|||||||
@ -10,6 +10,9 @@ export const getFindManyResponse200 = (
|
|||||||
item.nameSingular,
|
item.nameSingular,
|
||||||
)} for Response`;
|
)} for Response`;
|
||||||
|
|
||||||
|
const namePlural =
|
||||||
|
item.namePlural === 'relations' ? 'relationMetadata' : item.namePlural;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description: 'Successful operation',
|
description: 'Successful operation',
|
||||||
content: {
|
content: {
|
||||||
@ -20,7 +23,7 @@ export const getFindManyResponse200 = (
|
|||||||
data: {
|
data: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
[item.namePlural]: {
|
[namePlural]: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
items: {
|
items: {
|
||||||
$ref: schemaRef,
|
$ref: schemaRef,
|
||||||
@ -86,7 +89,11 @@ export const getCreateOneResponse201 = (
|
|||||||
fromMetadata = false,
|
fromMetadata = false,
|
||||||
) => {
|
) => {
|
||||||
const one = fromMetadata ? 'One' : '';
|
const one = fromMetadata ? 'One' : '';
|
||||||
const schemaRef = `#/components/schemas/${capitalize(item.nameSingular)} for Response`;
|
|
||||||
|
const nameSingular =
|
||||||
|
item.nameSingular === 'relation' ? 'relationMetadata' : item.nameSingular;
|
||||||
|
|
||||||
|
const schemaRef = `#/components/schemas/${capitalize(nameSingular)} for Response`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
description: 'Successful operation',
|
description: 'Successful operation',
|
||||||
@ -98,7 +105,7 @@ export const getCreateOneResponse201 = (
|
|||||||
data: {
|
data: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
[`create${one}${capitalize(item.nameSingular)}`]: {
|
[`create${one}${capitalize(nameSingular)}`]: {
|
||||||
$ref: schemaRef,
|
$ref: schemaRef,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user