67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import { dataSource } from "../../../data-source";
|
|
import { salutation } from "../../../entity/settings/salutation";
|
|
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
|
import InternalException from "../../../exceptions/internalException";
|
|
import { CreateSalutationCommand, DeleteSalutationCommand, UpdateSalutationCommand } from "./salutationCommand";
|
|
|
|
export default abstract class SalutationCommandHandler {
|
|
/**
|
|
* @description create salutation
|
|
* @param {CreateSalutationCommand} createSalutation
|
|
* @returns {Promise<number>}
|
|
*/
|
|
static async create(createSalutation: CreateSalutationCommand): Promise<number> {
|
|
return await dataSource
|
|
.createQueryBuilder()
|
|
.insert()
|
|
.into(salutation)
|
|
.values({
|
|
salutation: createSalutation.salutation,
|
|
})
|
|
.execute()
|
|
.then((result) => {
|
|
return result.identifiers[0].id;
|
|
})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("CREATE", "salutation", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description update salutation
|
|
* @param {UpdateSalutationCommand} updateSalutation
|
|
* @returns {Promise<void>}
|
|
*/
|
|
static async update(updateSalutation: UpdateSalutationCommand): Promise<void> {
|
|
return await dataSource
|
|
.createQueryBuilder()
|
|
.update(salutation)
|
|
.set({
|
|
salutation: updateSalutation.salutation,
|
|
})
|
|
.where("id = :id", { id: updateSalutation.id })
|
|
.execute()
|
|
.then(() => {})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("UPDATE", "salutation", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description delete salutation
|
|
* @param {DeleteSalutationCommand} deleteSalutation
|
|
* @returns {Promise<void>}
|
|
*/
|
|
static async delete(deleteSalutation: DeleteSalutationCommand): Promise<void> {
|
|
return await dataSource
|
|
.createQueryBuilder()
|
|
.delete()
|
|
.from(salutation)
|
|
.where("id = :id", { id: deleteSalutation.id })
|
|
.execute()
|
|
.then(() => {})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("DELETE", "salutation", err);
|
|
});
|
|
}
|
|
}
|