2024-09-05 14:17:22 +00:00
|
|
|
import { dataSource } from "../data-source";
|
|
|
|
import { executivePosition } from "../entity/executivePosition";
|
|
|
|
import InternalException from "../exceptions/internalException";
|
|
|
|
import {
|
|
|
|
CreateExecutivePositionCommand,
|
|
|
|
DeleteExecutivePositionCommand,
|
|
|
|
UpdateExecutivePositionCommand,
|
|
|
|
} from "./executivePositionCommand";
|
|
|
|
|
|
|
|
export default abstract class ExecutivePositionCommandHandler {
|
|
|
|
/**
|
|
|
|
* @description create executivePosition
|
|
|
|
* @param CreateExecutivePositionCommand
|
|
|
|
* @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 08:08:19 +00:00
|
|
|
throw new InternalException("Failed creating executivePosition", err);
|
2024-09-05 14:17:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description update executivePosition
|
|
|
|
* @param UpdateExecutivePositionCommand
|
|
|
|
* @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 08:08:19 +00:00
|
|
|
throw new InternalException("Failed updating executivePosition", err);
|
2024-09-05 14:17:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description delete executivePosition
|
|
|
|
* @param DeleteExecutivePositionCommand
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
static async delete(deletExecutivePosition: DeleteExecutivePositionCommand): Promise<void> {
|
|
|
|
return await dataSource
|
|
|
|
.createQueryBuilder()
|
|
|
|
.delete()
|
|
|
|
.from(executivePosition)
|
|
|
|
.where("id = :id", { id: deletExecutivePosition.id })
|
|
|
|
.execute()
|
|
|
|
.then(() => {})
|
|
|
|
.catch((err) => {
|
2024-09-06 08:08:19 +00:00
|
|
|
throw new InternalException("Failed deleting executivePosition", err);
|
2024-09-05 14:17:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|