2024-09-05 14:17:22 +00:00
|
|
|
import { dataSource } from "../data-source";
|
|
|
|
import { award } from "../entity/award";
|
|
|
|
import InternalException from "../exceptions/internalException";
|
|
|
|
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "./awardCommand";
|
|
|
|
|
|
|
|
export default abstract class AwardCommandHandler {
|
|
|
|
/**
|
|
|
|
* @description create award
|
|
|
|
* @param CreateAwardCommand
|
|
|
|
* @returns {Promise<number>}
|
|
|
|
*/
|
|
|
|
static async create(createAward: CreateAwardCommand): Promise<number> {
|
|
|
|
return await dataSource
|
|
|
|
.createQueryBuilder()
|
|
|
|
.insert()
|
|
|
|
.into(award)
|
|
|
|
.values({
|
|
|
|
award: createAward.award,
|
|
|
|
})
|
|
|
|
.execute()
|
|
|
|
.then((result) => {
|
|
|
|
return result.identifiers[0].id;
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
2024-09-06 08:08:19 +00:00
|
|
|
throw new InternalException("Failed creating award", err);
|
2024-09-05 14:17:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description update award
|
|
|
|
* @param UpdateAwardCommand
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
static async update(updateAward: UpdateAwardCommand): Promise<void> {
|
|
|
|
return await dataSource
|
|
|
|
.createQueryBuilder()
|
|
|
|
.update(award)
|
|
|
|
.set({
|
|
|
|
award: updateAward.award,
|
|
|
|
})
|
|
|
|
.where("id = :id", { id: updateAward.id })
|
|
|
|
.execute()
|
|
|
|
.then(() => {})
|
|
|
|
.catch((err) => {
|
2024-09-06 08:08:19 +00:00
|
|
|
throw new InternalException("Failed updating award", err);
|
2024-09-05 14:17:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @description delete award
|
|
|
|
* @param DeleteAwardCommand
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
|
|
|
static async delete(deletAward: DeleteAwardCommand): Promise<void> {
|
|
|
|
return await dataSource
|
|
|
|
.createQueryBuilder()
|
|
|
|
.delete()
|
|
|
|
.from(award)
|
|
|
|
.where("id = :id", { id: deletAward.id })
|
|
|
|
.execute()
|
|
|
|
.then(() => {})
|
|
|
|
.catch((err) => {
|
2024-09-06 08:08:19 +00:00
|
|
|
throw new InternalException("Failed deleting award", err);
|
2024-09-05 14:17:22 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|