app/api/relationships.v2/services/CreateRelationshipMigrationFieldService.ts
import { TransactionManager } from 'api/common.v2/contracts/TransactionManager';
import { RelationshipMigrationFieldsDataSource } from '../contracts/RelationshipMigrationFieldsDataSource';
import {
RelationshipMigrationFieldUniqueId,
RelationshipMigrationField,
} from '../model/RelationshipMigrationField';
class CreateRelationshipMigrationFieldService {
private transactionManager: TransactionManager;
private fieldDS: RelationshipMigrationFieldsDataSource;
constructor(
transactionManager: TransactionManager,
fieldDS: RelationshipMigrationFieldsDataSource
) {
this.transactionManager = transactionManager;
this.fieldDS = fieldDS;
}
async create(
sourceTemplate: string,
relationType: string,
targetTemplate?: string,
ignored: boolean = false
) {
const field = new RelationshipMigrationField(
new RelationshipMigrationFieldUniqueId(sourceTemplate, relationType, targetTemplate),
ignored
);
await this.transactionManager.run(async () => {
await this.fieldDS.create(field);
});
return field.flatten();
}
}
export { CreateRelationshipMigrationFieldService };