68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
import { dataSource } from "../../../data-source";
|
|
import { education } from "../../../entity/configuration/education";
|
|
import DatabaseActionException from "../../../exceptions/databaseActionException";
|
|
import { CreateEducationCommand, DeleteEducationCommand, UpdateEducationCommand } from "./educationCommand";
|
|
|
|
export default abstract class EducationCommandHandler {
|
|
/**
|
|
* @description create education
|
|
* @param {CreateEducationCommand} createEducation
|
|
* @returns {Promise<number>}
|
|
*/
|
|
static async create(createEducation: CreateEducationCommand): Promise<number> {
|
|
return await dataSource
|
|
.createQueryBuilder()
|
|
.insert()
|
|
.into(education)
|
|
.values({
|
|
education: createEducation.education,
|
|
description: createEducation.description,
|
|
})
|
|
.execute()
|
|
.then((result) => {
|
|
return result.identifiers[0].id;
|
|
})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("CREATE", "education", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description update education
|
|
* @param {UpdateEducationCommand} updateEducation
|
|
* @returns {Promise<void>}
|
|
*/
|
|
static async update(updateEducation: UpdateEducationCommand): Promise<void> {
|
|
return await dataSource
|
|
.createQueryBuilder()
|
|
.update(education)
|
|
.set({
|
|
education: updateEducation.education,
|
|
description: updateEducation.description,
|
|
})
|
|
.where("id = :id", { id: updateEducation.id })
|
|
.execute()
|
|
.then(() => {})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("UPDATE", "education", err);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @description delete education
|
|
* @param {DeleteEducationCommand} deleteEducation
|
|
* @returns {Promise<void>}
|
|
*/
|
|
static async delete(deleteEducation: DeleteEducationCommand): Promise<void> {
|
|
return await dataSource
|
|
.createQueryBuilder()
|
|
.delete()
|
|
.from(education)
|
|
.where("id = :id", { id: deleteEducation.id })
|
|
.execute()
|
|
.then(() => {})
|
|
.catch((err) => {
|
|
throw new DatabaseActionException("DELETE", "education", err);
|
|
});
|
|
}
|
|
}
|