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 {
|
|
|
|
/**
|
2024-09-16 15:55:41 +02:00
|
|
|
* @description get all by member id
|
|
|
|
* @param {number} memberId
|
2024-09-04 14:01:22 +02:00
|
|
|
* @returns {Promise<Array<communication>>}
|
|
|
|
*/
|
2024-09-16 15:55:41 +02:00
|
|
|
static async getAll(memberId: number): Promise<Array<communication>> {
|
2024-09-04 14:01:22 +02:00
|
|
|
return await dataSource
|
|
|
|
.getRepository(communication)
|
|
|
|
.createQueryBuilder("communication")
|
2024-09-16 15:55:41 +02:00
|
|
|
.leftJoinAndSelect("communication.type", "communicationType")
|
|
|
|
.leftJoinAndSelect("communication.member", "member")
|
|
|
|
.leftJoinAndSelect("member.sendNewsletter", "sendNewsletter")
|
|
|
|
.where("communication.memberId = :memberId", { memberId: memberId })
|
|
|
|
.getMany()
|
|
|
|
.then((res) => {
|
|
|
|
return res;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
throw new InternalException("member communications not found", err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description get all by memberId and recordId
|
|
|
|
* @param {number} memberId
|
|
|
|
* @param {number} recordId
|
|
|
|
* @returns {Promise<communication>}
|
|
|
|
*/
|
|
|
|
static async getById(memberId: number, recordId: number): Promise<communication> {
|
|
|
|
return await dataSource
|
|
|
|
.getRepository(communication)
|
|
|
|
.createQueryBuilder("communication")
|
|
|
|
.leftJoinAndSelect("communication.type", "communicationType")
|
|
|
|
.leftJoinAndSelect("communication.member", "member")
|
|
|
|
.leftJoinAndSelect("member.sendNewsletter", "sendNewsletter")
|
|
|
|
.where("communication.memberId = :memberId", { memberId: memberId })
|
|
|
|
.andWhere("communication.id = :recordId", { recordId: recordId })
|
2024-09-04 14:01:22 +02:00
|
|
|
.getOneOrFail()
|
|
|
|
.then((res) => {
|
|
|
|
return res;
|
|
|
|
})
|
2024-09-06 10:08:19 +02:00
|
|
|
.catch((err) => {
|
2024-09-16 15:55:41 +02:00
|
|
|
throw new InternalException("member communication not found by id", 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-11-27 10:07:59 +01:00
|
|
|
return columns.filter((c) => !["id", "preferred", "isSMSAlarming", "type", "member"].includes(c));
|
2024-09-04 14:01:22 +02:00
|
|
|
}
|
|
|
|
}
|