import { dataSource } from "../data-source"; import { communication } from "../entity/communication"; import InternalException from "../exceptions/internalException"; export default abstract class CommunicationService { /** * @description get communications by user * @returns {Promise>} */ static async getById(userId: number): Promise { return await dataSource .getRepository(communication) .createQueryBuilder("communication") .leftJoin("communication.user", "user") .andWhere("user.id = :id", { id: userId }) .getOneOrFail() .then((res) => { return res; }) .catch(() => { throw new InternalException("communications not found by userid"); }); } /** * @description get available columns for self made com type * @returns {Array} */ static getAvailableColumnsForCommunication(): Array { let metadata = dataSource.getMetadata(communication); return metadata.columns.map((c) => c.propertyName); } }