feat: return sharees when returning a workflow (#4312) (no-changelog)

This commit is contained in:
Omar Ajoue
2022-10-11 16:40:39 +02:00
committed by GitHub
parent 7a2e5bde90
commit ab0f776df1
6 changed files with 227 additions and 62 deletions

View File

@@ -6,6 +6,7 @@ import { WorkflowEntity } from '../databases/entities/WorkflowEntity';
import { RoleService } from '../role/role.service';
import { UserService } from '../user/user.service';
import { WorkflowsService } from './workflows.services';
import { WorkflowWithSharings } from './workflows.types';
export class EEWorkflowsService extends WorkflowsService {
static async isOwned(
@@ -70,4 +71,27 @@ export class EEWorkflowsService extends WorkflowsService {
return transaction.save(newSharedWorkflows);
}
static addOwnerAndSharings(
workflow: WorkflowEntity & WorkflowWithSharings,
): WorkflowEntity & WorkflowWithSharings {
workflow.ownedBy = null;
workflow.sharedWith = [];
workflow.shared?.forEach(({ user, role }) => {
const { id, email, firstName, lastName } = user;
if (role.name === 'owner') {
workflow.ownedBy = { id, email, firstName, lastName };
return;
}
workflow.sharedWith?.push({ id, email, firstName, lastName });
});
// @ts-ignore
delete workflow.shared;
return workflow;
}
}