71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
import { dataSource } from "../../../data-source";
|
|
import { executivePosition } from "../../../entity/settings/executivePosition";
|
|
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
|
import InternalException from "../../../exceptions/internalException";
|
|
import {
|
|
CreateExecutivePositionCommand,
|
|
DeleteExecutivePositionCommand,
|
|
UpdateExecutivePositionCommand,
|
|
} from "./executivePositionCommand";
|
|
|
|
export default abstract class ExecutivePositionCommandHandler {
|
|
/**
|
|
* @description create executivePosition
|
|
* @param {CreateExecutivePositionCommand} createExecutivePosition
|
|
* @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 DatabaseActionException("DELETE", "executivePosition", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description update executivePosition
|
|
* @param {UpdateExecutivePositionCommand} updateExecutivePosition
|
|
* @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 DatabaseActionException("UPDATE", "executivePosition", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description delete executivePosition
|
|
* @param {DeleteExecutivePositionCommand} deleteExecutivePosition
|
|
* @returns {Promise<void>}
|
|
*/
|
|
static async delete(deleteExecutivePosition: DeleteExecutivePositionCommand): Promise<void> {
|
|
return await dataSource
|
|
.createQueryBuilder()
|
|
.delete()
|
|
.from(executivePosition)
|
|
.where("id = :id", { id: deleteExecutivePosition.id })
|
|
.execute()
|
|
.then(() => {})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("DELETE", "executivePosition", err);
|
|
});
|
|
}
|
|
}
|