ff-admin-server/src/command/communicationTypeCommandHandler.ts

72 lines
2.2 KiB
TypeScript

import { dataSource } from "../data-source";
import { communicationType } from "../entity/communicationType";
import InternalException from "../exceptions/internalException";
import {
CreateCommunicationTypeCommand,
DeleteCommunicationTypeCommand,
UpdateCommunicationTypeCommand,
} from "./communicationTypeCommand";
export default abstract class CommunicationTypeCommandHandler {
/**
* @description create communicationType
* @param CreateCommunicationTypeCommand
* @returns {Promise<number>}
*/
static async create(createCommunicationType: CreateCommunicationTypeCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(communicationType)
.values({
type: createCommunicationType.type,
useColumns: createCommunicationType.useColumns,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating communicationType", err);
});
}
/**
* @description update communicationType
* @param UpdateCommunicationTypeCommand
* @returns {Promise<void>}
*/
static async update(updateCommunicationType: UpdateCommunicationTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(communicationType)
.set({
type: updateCommunicationType.type,
useColumns: updateCommunicationType.useColumns,
})
.where("id = :id", { id: updateCommunicationType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating communicationType", err);
});
}
/**
* @description delete communicationType
* @param DeleteCommunicationTypeCommand
* @returns {Promise<void>}
*/
static async delete(deletCommunicationType: DeleteCommunicationTypeCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(communicationType)
.where("id = :id", { id: deletCommunicationType.id })
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed deleting communicationType", err);
});
}
}