71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
|
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) => {
|
||
|
throw new InternalException("Failed creating executivePosition");
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @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) => {
|
||
|
throw new InternalException("Failed updating executivePosition");
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @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) => {
|
||
|
throw new InternalException("Failed deleting executivePosition");
|
||
|
});
|
||
|
}
|
||
|
}
|