2025-01-05 14:14:00 +01:00
|
|
|
import { dataSource } from "../../../data-source";
|
|
|
|
import { executivePosition } from "../../../entity/settings/executivePosition";
|
|
|
|
import InternalException from "../../../exceptions/internalException";
|
2024-09-05 16:17:22 +02:00
|
|
|
import {
|
|
|
|
CreateExecutivePositionCommand,
|
|
|
|
DeleteExecutivePositionCommand,
|
|
|
|
UpdateExecutivePositionCommand,
|
|
|
|
} from "./executivePositionCommand";
|
|
|
|
|
|
|
|
export default abstract class ExecutivePositionCommandHandler {
|
|
|
|
/**
|
|
|
|
* @description create executivePosition
|
2025-01-05 14:29:31 +01:00
|
|
|
* @param {CreateExecutivePositionCommand} createExecutivePosition
|
2024-09-05 16:17:22 +02:00
|
|
|
* @returns {Promise<number>}
|
|
|
|
*/
|
|
|
|
static async create(createExecutivePosition: CreateExecutivePositionCommand): Promise<number> {
|
|
|
|
return await dataSource
|
|
|
|
.createQueryBuilder()
|
|
|
|
.insert()
|
|
|
|
.into(executivePosition)
|
|
|
|
.values({
|
|
|
|
position: createExecutivePosition.position,
|
|
|
|
})
|
|
|
|
.execute()
|
|
|
|
.then((result) => {
|
|
|
|
return result.identifiers[0].id;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2024-09-06 10:08:19 +02:00
|
|
|
throw new InternalException("Failed creating executivePosition", err);
|
2024-09-05 16:17:22 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description update executivePosition
|
2025-01-05 14:29:31 +01:00
|
|
|
* @param {UpdateExecutivePositionCommand} updateExecutivePosition
|
2024-09-05 16:17:22 +02:00
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
static async update(updateExecutivePosition: UpdateExecutivePositionCommand): Promise<void> {
|
|
|
|
return await dataSource
|
|
|
|
.createQueryBuilder()
|
|
|
|
.update(executivePosition)
|
|
|
|
.set({
|
|
|
|
positon: updateExecutivePosition.position,
|
|
|
|
})
|
|
|
|
.where("id = :id", { id: updateExecutivePosition.id })
|
|
|
|
.execute()
|
|
|
|
.then(() => {})
|
|
|
|
.catch((err) => {
|
2024-09-06 10:08:19 +02:00
|
|
|
throw new InternalException("Failed updating executivePosition", err);
|
2024-09-05 16:17:22 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description delete executivePosition
|
2025-01-05 14:29:31 +01:00
|
|
|
* @param {DeleteExecutivePositionCommand} deleteExecutivePosition
|
2024-09-05 16:17:22 +02:00
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
2025-01-05 14:29:31 +01:00
|
|
|
static async delete(deleteExecutivePosition: DeleteExecutivePositionCommand): Promise<void> {
|
2024-09-05 16:17:22 +02:00
|
|
|
return await dataSource
|
|
|
|
.createQueryBuilder()
|
|
|
|
.delete()
|
|
|
|
.from(executivePosition)
|
2025-01-05 14:29:31 +01:00
|
|
|
.where("id = :id", { id: deleteExecutivePosition.id })
|
2024-09-05 16:17:22 +02:00
|
|
|
.execute()
|
|
|
|
.then(() => {})
|
|
|
|
.catch((err) => {
|
2025-01-13 10:37:53 +01:00
|
|
|
throw new InternalException(
|
|
|
|
`Failed deleting executivePosition${
|
|
|
|
err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""
|
|
|
|
}`,
|
|
|
|
err
|
|
|
|
);
|
2024-09-05 16:17:22 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|