ff-admin-server/src/command/settings/award/awardCommandHandler.ts

67 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-01-05 14:14:00 +01:00
import { dataSource } from "../../../data-source";
import { award } from "../../../entity/settings/award";
import InternalException from "../../../exceptions/internalException";
2024-09-05 16:17:22 +02:00
import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "./awardCommand";
export default abstract class AwardCommandHandler {
/**
* @description create award
2025-01-05 14:29:31 +01:00
* @param {CreateAwardCommand} createAward
2024-09-05 16:17:22 +02:00
* @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 10:08:19 +02:00
throw new InternalException("Failed creating award", err);
2024-09-05 16:17:22 +02:00
});
}
/**
* @description update award
2025-01-05 14:29:31 +01:00
* @param {UpdateAwardCommand} updateAward
2024-09-05 16:17:22 +02:00
* @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 10:08:19 +02:00
throw new InternalException("Failed updating award", err);
2024-09-05 16:17:22 +02:00
});
}
/**
* @description delete award
2025-01-05 14:29:31 +01:00
* @param {DeleteAwardCommand} deleteAward
2024-09-05 16:17:22 +02:00
* @returns {Promise<void>}
*/
2025-01-05 14:29:31 +01:00
static async delete(deleteAward: DeleteAwardCommand): Promise<void> {
2024-09-05 16:17:22 +02:00
return await dataSource
.createQueryBuilder()
.delete()
.from(award)
2025-01-05 14:29:31 +01:00
.where("id = :id", { id: deleteAward.id })
2024-09-05 16:17:22 +02:00
.execute()
.then(() => {})
.catch((err) => {
2024-09-06 10:08:19 +02:00
throw new InternalException("Failed deleting award", err);
2024-09-05 16:17:22 +02:00
});
}
}