Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6658 workflows add a first twenty piece email sender #6965

Merged
merged 24 commits into from
Sep 12, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix missing data in deleted event
  • Loading branch information
martmull committed Sep 10, 2024
commit 52ac80db8b7e44b70c32901b3a2b47bc8fafc6c2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable, Logger } from '@nestjs/common';

import isEmpty from 'lodash.isempty';
import { DataSource } from 'typeorm';
import { DataSource, In } from 'typeorm';

import {
Record as IRecord,
Expand Down Expand Up @@ -498,7 +498,7 @@ export class WorkspaceQueryRunnerService {
args.filter?.id?.in?.forEach((id) => assertIsValidUuid(id));

const existingRecords = await repository.find({
where: { id: { in: args.filter?.id?.in } },
where: { id: In(args.filter?.id?.in) },
});
const mappedRecords = new Map(
existingRecords.map((record) => [record.id, record]),
Expand Down Expand Up @@ -618,6 +618,19 @@ export class WorkspaceQueryRunnerService {
});
}

const repository =
await this.twentyORMGlobalManager.getRepositoryForWorkspace(
authContext.workspace.id,
objectMetadataItem.nameSingular,
);

const existingRecords = await repository.find({
where: { id: In(args.filter?.id?.in) },
});
const mappedRecords = new Map(
existingRecords.map((record) => [record.id, record]),
);

const result = await this.execute(query, authContext.workspace.id);

const parsedResults = (
Expand All @@ -637,17 +650,21 @@ export class WorkspaceQueryRunnerService {

this.workspaceEventEmitter.emit(
`${objectMetadataItem.nameSingular}.deleted`,
parsedResults.map(
(record) =>
({
userId: authContext.user?.id,
recordId: record.id,
objectMetadata: objectMetadataItem,
properties: {
before: this.removeNestedProperties(record),
},
}) satisfies ObjectRecordDeleteEvent<any>,
),
parsedResults.map((record) => {
martmull marked this conversation as resolved.
Show resolved Hide resolved
const existingRecord = mappedRecords.get(record.id);

return {
userId: authContext.user?.id,
recordId: record.id,
objectMetadata: objectMetadataItem,
properties: {
before: this.removeNestedProperties({
...existingRecord,
...record,
}),
},
} satisfies ObjectRecordDeleteEvent<any>;
}),
authContext.workspace.id,
);

Expand Down
Loading