Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 10x 1x 1x 1x 1x 1x 1x 60x 60x 60x 60x 1x 1x 1x 1x 1x 1x 1x 8x 8x 8x 8x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 25x 1x | import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { flatten } from 'lodash-es';
import { Repository } from 'typeorm';
import { Relationship, type Company } from '@amalia/core/models';
@Injectable()
export class RelationshipsService {
public constructor(
@InjectRepository(Relationship)
private readonly relationshipRepository: Repository<Relationship>,
) {}
/**
* Find all relationships for a given company.
* @param company
*/
public async findAll(company: Company): Promise<Relationship[]> {
return this.relationshipRepository.find({
where: { company: { id: company.id } },
});
}
/**
* Find a relationship for a given company
* @param company company of the new period
* @param id
*/
public async findById(company: Company, id: string): Promise<Relationship | null> {
return this.relationshipRepository.findOne({
where: { company: { id: company.id }, id },
});
}
/**
* Find all relations that are from a given definition
*
* @param company
* @param definitionMachineName
* @returns
*/
public async findByDefinitionFrom(company: Company, definitionMachineName: string): Promise<Relationship[]> {
return this.relationshipRepository.find({
where: {
company: { id: company.id },
fromDefinitionMachineName: definitionMachineName,
},
});
}
/**
* Find all relations that are to a given definition
*
* @param company
* @param definitionMachineName
* @returns
*/
public async findByDefinitionTo(company: Company, definitionMachineName: string): Promise<Relationship[]> {
return this.relationshipRepository.find({
where: {
company: { id: company.id },
toDefinitionMachineName: definitionMachineName,
},
});
}
public async findByDefinition(company: Company, definitionMachineName: string): Promise<Relationship[]> {
const relationships = await Promise.all([
this.findByDefinitionFrom(company, definitionMachineName),
this.findByDefinitionTo(company, definitionMachineName),
]);
return flatten(relationships);
}
public async findByDefinitionAndName(
company: Company,
definitionMachineName: string,
name: string,
): Promise<Relationship | null> {
return this.relationshipRepository.findOne({
where: {
company: { id: company.id },
fromDefinitionMachineName: definitionMachineName,
name,
},
});
}
}
|