ff-admin-server/src/command/club/member/communicationCommandHandler.ts

91 lines
3.1 KiB
TypeScript
Raw Normal View History

2025-01-05 14:14:00 +01:00
import { dataSource } from "../../../data-source";
import { communication } from "../../../entity/club/member/communication";
import InternalException from "../../../exceptions/internalException";
2024-09-27 14:55:34 +02:00
import {
CreateCommunicationCommand,
DeleteCommunicationCommand,
UpdateCommunicationCommand,
} from "./communicationCommand";
export default abstract class CommunicationCommandHandler {
/**
* @description create communication
2025-01-05 14:29:31 +01:00
* @param {CreateCommunicationCommand} createCommunication
2024-09-27 14:55:34 +02:00
* @returns {Promise<number>}
*/
static async create(createCommunication: CreateCommunicationCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(communication)
.values({
preferred: createCommunication.preferred,
2024-11-27 10:07:59 +01:00
isSMSAlarming: createCommunication.isSMSAlarming,
2024-09-27 14:55:34 +02:00
mobile: createCommunication.mobile,
email: createCommunication.email,
2025-01-03 19:26:33 +01:00
postalCode: createCommunication.postalCode,
2024-09-27 14:55:34 +02:00
city: createCommunication.city,
street: createCommunication.street,
streetNumber: createCommunication.streetNumber,
streetNumberAddition: createCommunication.streetNumberAddition,
2025-01-03 19:26:33 +01:00
memberId: createCommunication.memberId,
typeId: createCommunication.typeId,
2024-09-27 14:55:34 +02:00
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating communication", err);
});
}
/**
* @description update communication
2025-01-05 14:29:31 +01:00
* @param {UpdateCommunicationCommand} updateCommunication
2024-09-27 14:55:34 +02:00
* @returns {Promise<void>}
*/
static async update(updateCommunication: UpdateCommunicationCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(communication)
.set({
preferred: updateCommunication.preferred,
2024-11-27 10:07:59 +01:00
isSMSAlarming: updateCommunication.isSMSAlarming,
2024-09-27 14:55:34 +02:00
mobile: updateCommunication.mobile,
email: updateCommunication.email,
2025-01-03 19:26:33 +01:00
postalCode: updateCommunication.postalCode,
2024-09-27 14:55:34 +02:00
city: updateCommunication.city,
street: updateCommunication.street,
streetNumber: updateCommunication.streetNumber,
streetNumberAddition: updateCommunication.streetNumberAddition,
})
.where("id = :id", { id: updateCommunication.id })
.andWhere("memberId = :memberId", { memberId: updateCommunication.memberId })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating communication", err);
});
}
/**
* @description delete communication
2025-01-05 14:29:31 +01:00
* @param {DeleteCommunicationCommand} deleteCommunication
2024-09-27 14:55:34 +02:00
* @returns {Promise<void>}
*/
2025-01-03 19:26:33 +01:00
static async delete(deleteCommunication: DeleteCommunicationCommand): Promise<void> {
2024-09-27 14:55:34 +02:00
return await dataSource
.createQueryBuilder()
.delete()
.from(communication)
2025-01-03 19:26:33 +01:00
.where("id = :id", { id: deleteCommunication.id })
.andWhere("memberId = :memberId", { memberId: deleteCommunication.memberId })
2024-09-27 14:55:34 +02:00
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed deleting communication", err);
});
}
}