11312 rest api cant filter enum type columns by null value (#11343)
- Fixes https://github.com/twentyhq/twenty/issues/11312 - Fixes record undefined on webhook deleted events - Emit destroy event when deleting record via the rest api
This commit is contained in:
2
packages/twenty-server/@types/express.d.ts
vendored
2
packages/twenty-server/@types/express.d.ts
vendored
@ -7,7 +7,7 @@ declare module 'express-serve-static-core' {
|
|||||||
user?: User | null;
|
user?: User | null;
|
||||||
apiKey?: ApiKeyWorkspaceEntity | null;
|
apiKey?: ApiKeyWorkspaceEntity | null;
|
||||||
workspace: Workspace;
|
workspace: Workspace;
|
||||||
workspaceId?: string;
|
workspaceId: string;
|
||||||
workspaceMetadataVersion?: number;
|
workspaceMetadataVersion?: number;
|
||||||
workspaceMemberId?: string;
|
workspaceMemberId?: string;
|
||||||
userWorkspaceId?: string;
|
userWorkspaceId?: string;
|
||||||
|
|||||||
@ -56,4 +56,24 @@ describe('checkFilterEnumValues', () => {
|
|||||||
`'filter' enum value 'MISSING_OPTION' not available in '${fieldSelectMock.name}' enum. Available enum values are ['OPTION_1', 'OPTION_2']`,
|
`'filter' enum value 'MISSING_OPTION' not available in '${fieldSelectMock.name}' enum. Available enum values are ['OPTION_1', 'OPTION_2']`,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should allow filter by NULL or NOT_NULL values', () => {
|
||||||
|
expect(() =>
|
||||||
|
checkFilterEnumValues(
|
||||||
|
FieldMetadataType.SELECT,
|
||||||
|
fieldSelectMock.name,
|
||||||
|
'NULL',
|
||||||
|
mockObjectMetadataWithFieldMaps,
|
||||||
|
),
|
||||||
|
).not.toThrow();
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
checkFilterEnumValues(
|
||||||
|
FieldMetadataType.SELECT,
|
||||||
|
fieldSelectMock.name,
|
||||||
|
'NOT_NULL',
|
||||||
|
mockObjectMetadataWithFieldMaps,
|
||||||
|
),
|
||||||
|
).not.toThrow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -28,8 +28,10 @@ export const checkFilterEnumValues = (
|
|||||||
if (!enumValues) {
|
if (!enumValues) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const allowedEnumValues = ['NULL', 'NOT_NULL', ...enumValues];
|
||||||
|
|
||||||
values.forEach((val) => {
|
values.forEach((val) => {
|
||||||
if (!enumValues.includes(val)) {
|
if (!allowedEnumValues.includes(val)) {
|
||||||
throw new BadRequestException(
|
throw new BadRequestException(
|
||||||
`'filter' enum value '${val}' not available in '${fieldName}' enum. Available enum values are ['${enumValues.join(
|
`'filter' enum value '${val}' not available in '${fieldName}' enum. Available enum values are ['${enumValues.join(
|
||||||
"', '",
|
"', '",
|
||||||
|
|||||||
@ -35,7 +35,7 @@ export class RestApiCoreServiceV2 {
|
|||||||
|
|
||||||
await repository.delete(recordId);
|
await repository.delete(recordId);
|
||||||
|
|
||||||
this.apiEventEmitterService.emitDeletedEvents(
|
this.apiEventEmitterService.emitDestroyEvents(
|
||||||
[recordToDelete],
|
[recordToDelete],
|
||||||
this.getAuthContextFromRequest(request),
|
this.getAuthContextFromRequest(request),
|
||||||
objectMetadata.objectMetadataMapItem,
|
objectMetadata.objectMetadataMapItem,
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { Logger } from '@nestjs/common';
|
import { Logger } from '@nestjs/common';
|
||||||
|
|
||||||
import { ArrayContains } from 'typeorm';
|
import { ArrayContains } from 'typeorm';
|
||||||
|
import { isDefined } from 'twenty-shared/utils';
|
||||||
|
|
||||||
import { ObjectRecordEvent } from 'src/engine/core-modules/event-emitter/types/object-record-event.event';
|
import { ObjectRecordEvent } from 'src/engine/core-modules/event-emitter/types/object-record-event.event';
|
||||||
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
import { InjectMessageQueue } from 'src/engine/core-modules/message-queue/decorators/message-queue.decorator';
|
||||||
@ -61,9 +62,10 @@ export class CallWebhookJobsJob {
|
|||||||
};
|
};
|
||||||
const workspaceId = workspaceEventBatch.workspaceId;
|
const workspaceId = workspaceEventBatch.workspaceId;
|
||||||
const record =
|
const record =
|
||||||
'after' in eventData.properties
|
'after' in eventData.properties && isDefined(eventData.properties.after)
|
||||||
? eventData.properties.after
|
? eventData.properties.after
|
||||||
: 'before' in eventData.properties
|
: 'before' in eventData.properties &&
|
||||||
|
isDefined(eventData.properties.before)
|
||||||
? eventData.properties.before
|
? eventData.properties.before
|
||||||
: {};
|
: {};
|
||||||
const updatedFields =
|
const updatedFields =
|
||||||
|
|||||||
Reference in New Issue
Block a user