From 4048c21c1fbaf74d69bcdf451133672a13007b6a Mon Sep 17 00:00:00 2001 From: Julian Krauser Date: Thu, 5 Sep 2024 16:17:22 +0200 Subject: [PATCH] self defined value tables - commands --- src/command/awardCommand.ts | 12 ++++ src/command/awardCommandHandler.ts | 66 +++++++++++++++++ src/command/communicationTypeCommand.ts | 14 ++++ .../communicationTypeCommandHandler.ts | 72 +++++++++++++++++++ src/command/executivePositionCommand.ts | 12 ++++ .../executivePositionCommandHandler.ts | 70 ++++++++++++++++++ src/command/membershipStatusCommand.ts | 12 ++++ src/command/membershipStatusCommandHandler.ts | 70 ++++++++++++++++++ src/command/qualificationCommand.ts | 14 ++++ src/command/qualificationCommandHandler.ts | 72 +++++++++++++++++++ src/command/roleCommandHandler.ts | 4 +- src/controller/admin/awardController.ts | 18 +++++ .../admin/communicationTypeController.ts | 26 +++++++ .../admin/executivePositionController.ts | 22 ++++++ .../admin/membershipStatusController.ts | 22 ++++++ .../admin/qualificationController.ts | 22 ++++++ 16 files changed, 526 insertions(+), 2 deletions(-) create mode 100644 src/command/awardCommand.ts create mode 100644 src/command/awardCommandHandler.ts create mode 100644 src/command/communicationTypeCommand.ts create mode 100644 src/command/communicationTypeCommandHandler.ts create mode 100644 src/command/executivePositionCommand.ts create mode 100644 src/command/executivePositionCommandHandler.ts create mode 100644 src/command/membershipStatusCommand.ts create mode 100644 src/command/membershipStatusCommandHandler.ts create mode 100644 src/command/qualificationCommand.ts create mode 100644 src/command/qualificationCommandHandler.ts diff --git a/src/command/awardCommand.ts b/src/command/awardCommand.ts new file mode 100644 index 0000000..8819170 --- /dev/null +++ b/src/command/awardCommand.ts @@ -0,0 +1,12 @@ +export interface CreateAwardCommand { + award: string; +} + +export interface UpdateAwardCommand { + id: number; + award: string; +} + +export interface DeleteAwardCommand { + id: number; +} diff --git a/src/command/awardCommandHandler.ts b/src/command/awardCommandHandler.ts new file mode 100644 index 0000000..251f70e --- /dev/null +++ b/src/command/awardCommandHandler.ts @@ -0,0 +1,66 @@ +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} + */ + static async create(createAward: CreateAwardCommand): Promise { + return await dataSource + .createQueryBuilder() + .insert() + .into(award) + .values({ + award: createAward.award, + }) + .execute() + .then((result) => { + return result.identifiers[0].id; + }) + .catch((err) => { + throw new InternalException("Failed creating award"); + }); + } + + /** + * @description update award + * @param UpdateAwardCommand + * @returns {Promise} + */ + static async update(updateAward: UpdateAwardCommand): Promise { + return await dataSource + .createQueryBuilder() + .update(award) + .set({ + award: updateAward.award, + }) + .where("id = :id", { id: updateAward.id }) + .execute() + .then(() => {}) + .catch((err) => { + throw new InternalException("Failed updating award"); + }); + } + + /** + * @description delete award + * @param DeleteAwardCommand + * @returns {Promise} + */ + static async delete(deletAward: DeleteAwardCommand): Promise { + return await dataSource + .createQueryBuilder() + .delete() + .from(award) + .where("id = :id", { id: deletAward.id }) + .execute() + .then(() => {}) + .catch((err) => { + throw new InternalException("Failed deleting award"); + }); + } +} diff --git a/src/command/communicationTypeCommand.ts b/src/command/communicationTypeCommand.ts new file mode 100644 index 0000000..992ef1c --- /dev/null +++ b/src/command/communicationTypeCommand.ts @@ -0,0 +1,14 @@ +export interface CreateCommunicationTypeCommand { + type: string; + useColumns: Array; +} + +export interface UpdateCommunicationTypeCommand { + id: number; + type: string; + useColumns: Array; +} + +export interface DeleteCommunicationTypeCommand { + id: number; +} diff --git a/src/command/communicationTypeCommandHandler.ts b/src/command/communicationTypeCommandHandler.ts new file mode 100644 index 0000000..51b9659 --- /dev/null +++ b/src/command/communicationTypeCommandHandler.ts @@ -0,0 +1,72 @@ +import { dataSource } from "../data-source"; +import { communicationType } from "../entity/communicationType"; +import InternalException from "../exceptions/internalException"; +import { + CreateCommunicationTypeCommand, + DeleteCommunicationTypeCommand, + UpdateCommunicationTypeCommand, +} from "./communicationTypeCommand"; + +export default abstract class CommunicationTypeCommandHandler { + /** + * @description create communicationType + * @param CreateCommunicationTypeCommand + * @returns {Promise} + */ + static async create(createCommunicationType: CreateCommunicationTypeCommand): Promise { + return await dataSource + .createQueryBuilder() + .insert() + .into(communicationType) + .values({ + type: createCommunicationType.type, + useColumns: createCommunicationType.useColumns, + }) + .execute() + .then((result) => { + return result.identifiers[0].id; + }) + .catch((err) => { + throw new InternalException("Failed creating communicationType"); + }); + } + + /** + * @description update communicationType + * @param UpdateCommunicationTypeCommand + * @returns {Promise} + */ + static async update(updateCommunicationType: UpdateCommunicationTypeCommand): Promise { + return await dataSource + .createQueryBuilder() + .update(communicationType) + .set({ + type: updateCommunicationType.type, + useColumns: updateCommunicationType.useColumns, + }) + .where("id = :id", { id: updateCommunicationType.id }) + .execute() + .then(() => {}) + .catch((err) => { + throw new InternalException("Failed updating communicationType"); + }); + } + + /** + * @description delete communicationType + * @param DeleteCommunicationTypeCommand + * @returns {Promise} + */ + static async delete(deletCommunicationType: DeleteCommunicationTypeCommand): Promise { + return await dataSource + .createQueryBuilder() + .delete() + .from(communicationType) + .where("id = :id", { id: deletCommunicationType.id }) + .execute() + .then(() => {}) + .catch((err) => { + throw new InternalException("Failed deleting communicationType"); + }); + } +} diff --git a/src/command/executivePositionCommand.ts b/src/command/executivePositionCommand.ts new file mode 100644 index 0000000..21d9214 --- /dev/null +++ b/src/command/executivePositionCommand.ts @@ -0,0 +1,12 @@ +export interface CreateExecutivePositionCommand { + position: string; +} + +export interface UpdateExecutivePositionCommand { + id: number; + position: string; +} + +export interface DeleteExecutivePositionCommand { + id: number; +} diff --git a/src/command/executivePositionCommandHandler.ts b/src/command/executivePositionCommandHandler.ts new file mode 100644 index 0000000..3f80098 --- /dev/null +++ b/src/command/executivePositionCommandHandler.ts @@ -0,0 +1,70 @@ +import { dataSource } from "../data-source"; +import { executivePosition } from "../entity/executivePosition"; +import InternalException from "../exceptions/internalException"; +import { + CreateExecutivePositionCommand, + DeleteExecutivePositionCommand, + UpdateExecutivePositionCommand, +} from "./executivePositionCommand"; + +export default abstract class ExecutivePositionCommandHandler { + /** + * @description create executivePosition + * @param CreateExecutivePositionCommand + * @returns {Promise} + */ + static async create(createExecutivePosition: CreateExecutivePositionCommand): Promise { + return await dataSource + .createQueryBuilder() + .insert() + .into(executivePosition) + .values({ + position: createExecutivePosition.position, + }) + .execute() + .then((result) => { + return result.identifiers[0].id; + }) + .catch((err) => { + throw new InternalException("Failed creating executivePosition"); + }); + } + + /** + * @description update executivePosition + * @param UpdateExecutivePositionCommand + * @returns {Promise} + */ + static async update(updateExecutivePosition: UpdateExecutivePositionCommand): Promise { + return await dataSource + .createQueryBuilder() + .update(executivePosition) + .set({ + positon: updateExecutivePosition.position, + }) + .where("id = :id", { id: updateExecutivePosition.id }) + .execute() + .then(() => {}) + .catch((err) => { + throw new InternalException("Failed updating executivePosition"); + }); + } + + /** + * @description delete executivePosition + * @param DeleteExecutivePositionCommand + * @returns {Promise} + */ + static async delete(deletExecutivePosition: DeleteExecutivePositionCommand): Promise { + return await dataSource + .createQueryBuilder() + .delete() + .from(executivePosition) + .where("id = :id", { id: deletExecutivePosition.id }) + .execute() + .then(() => {}) + .catch((err) => { + throw new InternalException("Failed deleting executivePosition"); + }); + } +} diff --git a/src/command/membershipStatusCommand.ts b/src/command/membershipStatusCommand.ts new file mode 100644 index 0000000..9a565c8 --- /dev/null +++ b/src/command/membershipStatusCommand.ts @@ -0,0 +1,12 @@ +export interface CreateMembershipStatusCommand { + status: string; +} + +export interface UpdateMembershipStatusCommand { + id: number; + status: string; +} + +export interface DeleteMembershipStatusCommand { + id: number; +} diff --git a/src/command/membershipStatusCommandHandler.ts b/src/command/membershipStatusCommandHandler.ts new file mode 100644 index 0000000..b6594db --- /dev/null +++ b/src/command/membershipStatusCommandHandler.ts @@ -0,0 +1,70 @@ +import { dataSource } from "../data-source"; +import { membershipStatus } from "../entity/membershipStatus"; +import InternalException from "../exceptions/internalException"; +import { + CreateMembershipStatusCommand, + DeleteMembershipStatusCommand, + UpdateMembershipStatusCommand, +} from "./membershipStatusCommand"; + +export default abstract class MembershipStatusCommandHandler { + /** + * @description create membershipStatus + * @param CreateMembershipStatusCommand + * @returns {Promise} + */ + static async create(createMembershipStatus: CreateMembershipStatusCommand): Promise { + return await dataSource + .createQueryBuilder() + .insert() + .into(membershipStatus) + .values({ + status: createMembershipStatus.status, + }) + .execute() + .then((result) => { + return result.identifiers[0].id; + }) + .catch((err) => { + throw new InternalException("Failed creating membershipStatus"); + }); + } + + /** + * @description update membershipStatus + * @param UpdateMembershipStatusCommand + * @returns {Promise} + */ + static async update(updateMembershipStatus: UpdateMembershipStatusCommand): Promise { + return await dataSource + .createQueryBuilder() + .update(membershipStatus) + .set({ + status: updateMembershipStatus.status, + }) + .where("id = :id", { id: updateMembershipStatus.id }) + .execute() + .then(() => {}) + .catch((err) => { + throw new InternalException("Failed updating membershipStatus"); + }); + } + + /** + * @description delete membershipStatus + * @param DeleteMembershipStatusCommand + * @returns {Promise} + */ + static async delete(deletMembershipStatus: DeleteMembershipStatusCommand): Promise { + return await dataSource + .createQueryBuilder() + .delete() + .from(membershipStatus) + .where("id = :id", { id: deletMembershipStatus.id }) + .execute() + .then(() => {}) + .catch((err) => { + throw new InternalException("Failed deleting membershipStatus"); + }); + } +} diff --git a/src/command/qualificationCommand.ts b/src/command/qualificationCommand.ts new file mode 100644 index 0000000..129f09e --- /dev/null +++ b/src/command/qualificationCommand.ts @@ -0,0 +1,14 @@ +export interface CreateQualificationCommand { + qualification: string; + description?: string; +} + +export interface UpdateQualificationCommand { + id: number; + qualification: string; + description?: string; +} + +export interface DeleteQualificationCommand { + id: number; +} diff --git a/src/command/qualificationCommandHandler.ts b/src/command/qualificationCommandHandler.ts new file mode 100644 index 0000000..a71187d --- /dev/null +++ b/src/command/qualificationCommandHandler.ts @@ -0,0 +1,72 @@ +import { dataSource } from "../data-source"; +import { qualification } from "../entity/qualification"; +import InternalException from "../exceptions/internalException"; +import { + CreateQualificationCommand, + DeleteQualificationCommand, + UpdateQualificationCommand, +} from "./qualificationCommand"; + +export default abstract class QualificationCommandHandler { + /** + * @description create qualification + * @param CreateQualificationCommand + * @returns {Promise} + */ + static async create(createQualification: CreateQualificationCommand): Promise { + return await dataSource + .createQueryBuilder() + .insert() + .into(qualification) + .values({ + qualification: createQualification.qualification, + description: createQualification.description, + }) + .execute() + .then((result) => { + return result.identifiers[0].id; + }) + .catch((err) => { + throw new InternalException("Failed creating qualification"); + }); + } + + /** + * @description update qualification + * @param UpdateQualificationCommand + * @returns {Promise} + */ + static async update(updateQualification: UpdateQualificationCommand): Promise { + return await dataSource + .createQueryBuilder() + .update(qualification) + .set({ + qualification: updateQualification.qualification, + description: updateQualification.description, + }) + .where("id = :id", { id: updateQualification.id }) + .execute() + .then(() => {}) + .catch((err) => { + throw new InternalException("Failed updating qualification"); + }); + } + + /** + * @description delete qualification + * @param DeleteQualificationCommand + * @returns {Promise} + */ + static async delete(deletQualification: DeleteQualificationCommand): Promise { + return await dataSource + .createQueryBuilder() + .delete() + .from(qualification) + .where("id = :id", { id: deletQualification.id }) + .execute() + .then(() => {}) + .catch((err) => { + throw new InternalException("Failed deleting qualification"); + }); + } +} diff --git a/src/command/roleCommandHandler.ts b/src/command/roleCommandHandler.ts index 3e9902b..badbcb8 100644 --- a/src/command/roleCommandHandler.ts +++ b/src/command/roleCommandHandler.ts @@ -38,7 +38,7 @@ export default abstract class RoleCommandHandler { .set({ role: updateRole.role, }) - .where("role.id = :id", { id: updateRole.id }) + .where("id = :id", { id: updateRole.id }) .execute() .then(() => {}) .catch((err) => { @@ -56,7 +56,7 @@ export default abstract class RoleCommandHandler { .createQueryBuilder() .delete() .from(role) - .where("role.id = :id", { id: deleteRole.id }) + .where("id = :id", { id: deleteRole.id }) .execute() .then(() => {}) .catch((err) => { diff --git a/src/controller/admin/awardController.ts b/src/controller/admin/awardController.ts index e9155da..0aa7fa2 100644 --- a/src/controller/admin/awardController.ts +++ b/src/controller/admin/awardController.ts @@ -1,6 +1,8 @@ import { Request, Response } from "express"; import AwardService from "../../service/awardService"; import AwardFactory from "../../factory/admin/award"; +import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "../../command/awardCommand"; +import AwardCommandHandler from "../../command/awardCommandHandler"; /** * @description get all awards @@ -48,6 +50,11 @@ export async function getAwardAssignedMembers(req: Request, res: Response): Prom export async function createAward(req: Request, res: Response): Promise { const award = req.body.award; + let createAward: CreateAwardCommand = { + award: award, + }; + await AwardCommandHandler.create(createAward); + res.sendStatus(204); } @@ -61,6 +68,12 @@ export async function updateAward(req: Request, res: Response): Promise { const id = parseInt(req.params.id); const award = req.body.award; + let updateAward: UpdateAwardCommand = { + id: id, + award: award, + }; + await AwardCommandHandler.update(updateAward); + res.sendStatus(204); } @@ -73,5 +86,10 @@ export async function updateAward(req: Request, res: Response): Promise { export async function deleteAward(req: Request, res: Response): Promise { const id = parseInt(req.params.id); + let deleteAward: DeleteAwardCommand = { + id: id, + }; + await AwardCommandHandler.delete(deleteAward); + res.sendStatus(204); } diff --git a/src/controller/admin/communicationTypeController.ts b/src/controller/admin/communicationTypeController.ts index 29264b8..2d0b4e0 100644 --- a/src/controller/admin/communicationTypeController.ts +++ b/src/controller/admin/communicationTypeController.ts @@ -2,6 +2,12 @@ import { Request, Response } from "express"; import CommunicationTypeService from "../../service/communicationTypeService"; import CommunicationTypeFactory from "../../factory/admin/communicationType"; import CommunicationService from "../../service/communicationService"; +import { + CreateCommunicationTypeCommand, + DeleteCommunicationTypeCommand, + UpdateCommunicationTypeCommand, +} from "../../command/communicationTypeCommand"; +import CommunicationTypeCommandHandler from "../../command/communicationTypeCommandHandler"; /** * @description get all communicationTypes @@ -47,6 +53,13 @@ export async function getCommunicationTypeAvailableColumns(req: Request, res: Re */ export async function createCommunicationType(req: Request, res: Response): Promise { const communicationType = req.body.communicationType; + const useColumns = req.body.fields; + + let createCommunicationType: CreateCommunicationTypeCommand = { + type: communicationType, + useColumns: useColumns, + }; + await CommunicationTypeCommandHandler.create(createCommunicationType); res.sendStatus(204); } @@ -60,6 +73,14 @@ export async function createCommunicationType(req: Request, res: Response): Prom export async function updateCommunicationType(req: Request, res: Response): Promise { const id = parseInt(req.params.id); const communicationType = req.body.communicationType; + const useColumns = req.body.fields; + + let updateCommunicationType: UpdateCommunicationTypeCommand = { + id: id, + type: communicationType, + useColumns: useColumns, + }; + await CommunicationTypeCommandHandler.update(updateCommunicationType); res.sendStatus(204); } @@ -73,5 +94,10 @@ export async function updateCommunicationType(req: Request, res: Response): Prom export async function deleteCommunicationType(req: Request, res: Response): Promise { const id = parseInt(req.params.id); + let deleteCommunicationType: DeleteCommunicationTypeCommand = { + id: id, + }; + await CommunicationTypeCommandHandler.delete(deleteCommunicationType); + res.sendStatus(204); } diff --git a/src/controller/admin/executivePositionController.ts b/src/controller/admin/executivePositionController.ts index d99ceba..6902d68 100644 --- a/src/controller/admin/executivePositionController.ts +++ b/src/controller/admin/executivePositionController.ts @@ -1,6 +1,12 @@ import { Request, Response } from "express"; import ExecutivePositionService from "../../service/executivePositionService"; import ExecutivePositionFactory from "../../factory/admin/executivePosition"; +import { + CreateExecutivePositionCommand, + DeleteExecutivePositionCommand, + UpdateExecutivePositionCommand, +} from "../../command/executivePositionCommand"; +import ExecutivePositionCommandHandler from "../../command/executivePositionCommandHandler"; /** * @description get all executivePositions @@ -48,6 +54,11 @@ export async function getExecutivePositionAssignedMembers(req: Request, res: Res export async function createExecutivePosition(req: Request, res: Response): Promise { const executivePosition = req.body.executivePosition; + let createExecutivePosition: CreateExecutivePositionCommand = { + position: executivePosition, + }; + await ExecutivePositionCommandHandler.create(createExecutivePosition); + res.sendStatus(204); } @@ -61,6 +72,12 @@ export async function updateExecutivePosition(req: Request, res: Response): Prom const id = parseInt(req.params.id); const executivePosition = req.body.executivePosition; + let updateExecutivePosition: UpdateExecutivePositionCommand = { + id: id, + position: executivePosition, + }; + await ExecutivePositionCommandHandler.update(updateExecutivePosition); + res.sendStatus(204); } @@ -73,5 +90,10 @@ export async function updateExecutivePosition(req: Request, res: Response): Prom export async function deleteExecutivePosition(req: Request, res: Response): Promise { const id = parseInt(req.params.id); + let deleteExecutivePosition: DeleteExecutivePositionCommand = { + id: id, + }; + await ExecutivePositionCommandHandler.delete(deleteExecutivePosition); + res.sendStatus(204); } diff --git a/src/controller/admin/membershipStatusController.ts b/src/controller/admin/membershipStatusController.ts index bdcb0a2..04c153b 100644 --- a/src/controller/admin/membershipStatusController.ts +++ b/src/controller/admin/membershipStatusController.ts @@ -1,6 +1,12 @@ import { Request, Response } from "express"; import MembershipStatusService from "../../service/membershipStatusService"; import MembershipStatusFactory from "../../factory/admin/membershipStatus"; +import { + CreateMembershipStatusCommand, + DeleteMembershipStatusCommand, + UpdateMembershipStatusCommand, +} from "../../command/membershipStatusCommand"; +import MembershipStatusCommandHandler from "../../command/membershipStatusCommandHandler"; /** * @description get all membershipStatus @@ -48,6 +54,11 @@ export async function getMembershipStatusAssignedMembers(req: Request, res: Resp export async function createMembershipStatus(req: Request, res: Response): Promise { const membershipStatus = req.body.membershipStatus; + let createMembershipStatus: CreateMembershipStatusCommand = { + status: membershipStatus, + }; + await MembershipStatusCommandHandler.create(createMembershipStatus); + res.sendStatus(204); } @@ -61,6 +72,12 @@ export async function updateMembershipStatus(req: Request, res: Response): Promi const id = parseInt(req.params.id); const membershipStatus = req.body.membershipStatus; + let updateMembershipStatus: UpdateMembershipStatusCommand = { + id: id, + status: membershipStatus, + }; + await MembershipStatusCommandHandler.update(updateMembershipStatus); + res.sendStatus(204); } @@ -73,5 +90,10 @@ export async function updateMembershipStatus(req: Request, res: Response): Promi export async function deleteMembershipStatus(req: Request, res: Response): Promise { const id = parseInt(req.params.id); + let deleteMembershipStatus: DeleteMembershipStatusCommand = { + id: id, + }; + await MembershipStatusCommandHandler.delete(deleteMembershipStatus); + res.sendStatus(204); } diff --git a/src/controller/admin/qualificationController.ts b/src/controller/admin/qualificationController.ts index 946b4c8..7027dd7 100644 --- a/src/controller/admin/qualificationController.ts +++ b/src/controller/admin/qualificationController.ts @@ -1,6 +1,12 @@ import { Request, Response } from "express"; import QualificationService from "../../service/qualification"; import QualificationFactory from "../../factory/admin/qualification"; +import { + CreateQualificationCommand, + DeleteQualificationCommand, + UpdateQualificationCommand, +} from "../../command/qualificationCommand"; +import QualificationCommandHandler from "../../command/qualificationCommandHandler"; /** * @description get all qualifications @@ -48,6 +54,11 @@ export async function getQualificationAssignedMembers(req: Request, res: Respons export async function createQualification(req: Request, res: Response): Promise { const qualification = req.body.qualification; + let createQualification: CreateQualificationCommand = { + qualification: qualification, + }; + await QualificationCommandHandler.create(createQualification); + res.sendStatus(204); } @@ -61,6 +72,12 @@ export async function updateQualification(req: Request, res: Response): Promise< const id = parseInt(req.params.id); const qualification = req.body.qualification; + let updateQualification: UpdateQualificationCommand = { + id: id, + qualification: qualification, + }; + await QualificationCommandHandler.update(updateQualification); + res.sendStatus(204); } @@ -73,5 +90,10 @@ export async function updateQualification(req: Request, res: Response): Promise< export async function deleteQualification(req: Request, res: Response): Promise { const id = parseInt(req.params.id); + let deleteQualification: DeleteQualificationCommand = { + id: id, + }; + await QualificationCommandHandler.delete(deleteQualification); + res.sendStatus(204); }