2024-09-04 14:01:22 +02:00
|
|
|
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")
|
2024-09-15 14:03:15 +02:00
|
|
|
.where("user.id = :id", { id: userId })
|
2024-09-04 14:01:22 +02:00
|
|
|
.getOneOrFail()
|
|
|
|
.then((res) => {
|
|
|
|
return res;
|
|
|
|
})
|
2024-09-06 10:08:19 +02:00
|
|
|
.catch((err) => {
|
|
|
|
throw new InternalException("communications not found by userid", err);
|
2024-09-04 14:01:22 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description get available columns for self made com type
|
|
|
|
* @returns {Array<string>}
|
|
|
|
*/
|
|
|
|
static getAvailableColumnsForCommunication(): Array<string> {
|
|
|
|
let metadata = dataSource.getMetadata(communication);
|
2024-09-04 14:24:30 +02:00
|
|
|
let columns = metadata.columns.map((c) => c.propertyName);
|
2024-09-15 13:53:10 +02:00
|
|
|
return columns.filter((c) => !["id", "preffered", "type", "member"].includes(c));
|
2024-09-04 14:01:22 +02:00
|
|
|
}
|
|
|
|
}
|