ff-admin-server/src/command/roleCommandHandler.ts

67 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-08-28 20:41:16 +02:00
import { dataSource } from "../data-source";
import { role } from "../entity/role";
import InternalException from "../exceptions/internalException";
import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "./roleCommand";
export default abstract class RoleCommandHandler {
/**
* @description create role
* @param CreateRoleCommand
* @returns {Promise<number>}
*/
static async create(createRole: CreateRoleCommand): Promise<number> {
return await dataSource
.createQueryBuilder()
.insert()
.into(role)
.values({
role: createRole.role,
})
.execute()
.then((result) => {
return result.identifiers[0].id;
})
.catch((err) => {
throw new InternalException("Failed creating role");
});
}
/**
* @description update role
* @param UpdateRoleCommand
* @returns {Promise<void>}
*/
static async update(updateRole: UpdateRoleCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.update(role)
.set({
role: updateRole.role,
})
2024-09-05 16:17:22 +02:00
.where("id = :id", { id: updateRole.id })
2024-08-28 20:41:16 +02:00
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed updating role");
});
}
/**
* @description delete role
* @param DeleteRoleCommand
* @returns {Promise<void>}
*/
static async delete(deleteRole: DeleteRoleCommand): Promise<void> {
return await dataSource
.createQueryBuilder()
.delete()
.from(role)
2024-09-05 16:17:22 +02:00
.where("id = :id", { id: deleteRole.id })
2024-08-28 20:41:16 +02:00
.execute()
.then(() => {})
.catch((err) => {
throw new InternalException("Failed deleting role");
});
}
}