34 lines
1 KiB
TypeScript
34 lines
1 KiB
TypeScript
|
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<Array<communication>>}
|
||
|
*/
|
||
|
static async getById(userId: number): Promise<communication> {
|
||
|
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<string>}
|
||
|
*/
|
||
|
static getAvailableColumnsForCommunication(): Array<string> {
|
||
|
let metadata = dataSource.getMetadata(communication);
|
||
|
return metadata.columns.map((c) => c.propertyName);
|
||
|
}
|
||
|
}
|