self defined value tables - commands
This commit is contained in:
parent
b19cd97a01
commit
4048c21c1f
16 changed files with 526 additions and 2 deletions
12
src/command/awardCommand.ts
Normal file
12
src/command/awardCommand.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
export interface CreateAwardCommand {
|
||||
award: string;
|
||||
}
|
||||
|
||||
export interface UpdateAwardCommand {
|
||||
id: number;
|
||||
award: string;
|
||||
}
|
||||
|
||||
export interface DeleteAwardCommand {
|
||||
id: number;
|
||||
}
|
66
src/command/awardCommandHandler.ts
Normal file
66
src/command/awardCommandHandler.ts
Normal file
|
@ -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<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) => {
|
||||
throw new InternalException("Failed creating award");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) => {
|
||||
throw new InternalException("Failed updating award");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @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) => {
|
||||
throw new InternalException("Failed deleting award");
|
||||
});
|
||||
}
|
||||
}
|
14
src/command/communicationTypeCommand.ts
Normal file
14
src/command/communicationTypeCommand.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
export interface CreateCommunicationTypeCommand {
|
||||
type: string;
|
||||
useColumns: Array<string>;
|
||||
}
|
||||
|
||||
export interface UpdateCommunicationTypeCommand {
|
||||
id: number;
|
||||
type: string;
|
||||
useColumns: Array<string>;
|
||||
}
|
||||
|
||||
export interface DeleteCommunicationTypeCommand {
|
||||
id: number;
|
||||
}
|
72
src/command/communicationTypeCommandHandler.ts
Normal file
72
src/command/communicationTypeCommandHandler.ts
Normal file
|
@ -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<number>}
|
||||
*/
|
||||
static async create(createCommunicationType: CreateCommunicationTypeCommand): Promise<number> {
|
||||
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<void>}
|
||||
*/
|
||||
static async update(updateCommunicationType: UpdateCommunicationTypeCommand): Promise<void> {
|
||||
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<void>}
|
||||
*/
|
||||
static async delete(deletCommunicationType: DeleteCommunicationTypeCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(communicationType)
|
||||
.where("id = :id", { id: deletCommunicationType.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting communicationType");
|
||||
});
|
||||
}
|
||||
}
|
12
src/command/executivePositionCommand.ts
Normal file
12
src/command/executivePositionCommand.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
export interface CreateExecutivePositionCommand {
|
||||
position: string;
|
||||
}
|
||||
|
||||
export interface UpdateExecutivePositionCommand {
|
||||
id: number;
|
||||
position: string;
|
||||
}
|
||||
|
||||
export interface DeleteExecutivePositionCommand {
|
||||
id: number;
|
||||
}
|
70
src/command/executivePositionCommandHandler.ts
Normal file
70
src/command/executivePositionCommandHandler.ts
Normal file
|
@ -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<number>}
|
||||
*/
|
||||
static async create(createExecutivePosition: CreateExecutivePositionCommand): Promise<number> {
|
||||
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<void>}
|
||||
*/
|
||||
static async update(updateExecutivePosition: UpdateExecutivePositionCommand): Promise<void> {
|
||||
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<void>}
|
||||
*/
|
||||
static async delete(deletExecutivePosition: DeleteExecutivePositionCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(executivePosition)
|
||||
.where("id = :id", { id: deletExecutivePosition.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting executivePosition");
|
||||
});
|
||||
}
|
||||
}
|
12
src/command/membershipStatusCommand.ts
Normal file
12
src/command/membershipStatusCommand.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
export interface CreateMembershipStatusCommand {
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface UpdateMembershipStatusCommand {
|
||||
id: number;
|
||||
status: string;
|
||||
}
|
||||
|
||||
export interface DeleteMembershipStatusCommand {
|
||||
id: number;
|
||||
}
|
70
src/command/membershipStatusCommandHandler.ts
Normal file
70
src/command/membershipStatusCommandHandler.ts
Normal file
|
@ -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<number>}
|
||||
*/
|
||||
static async create(createMembershipStatus: CreateMembershipStatusCommand): Promise<number> {
|
||||
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<void>}
|
||||
*/
|
||||
static async update(updateMembershipStatus: UpdateMembershipStatusCommand): Promise<void> {
|
||||
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<void>}
|
||||
*/
|
||||
static async delete(deletMembershipStatus: DeleteMembershipStatusCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(membershipStatus)
|
||||
.where("id = :id", { id: deletMembershipStatus.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting membershipStatus");
|
||||
});
|
||||
}
|
||||
}
|
14
src/command/qualificationCommand.ts
Normal file
14
src/command/qualificationCommand.ts
Normal file
|
@ -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;
|
||||
}
|
72
src/command/qualificationCommandHandler.ts
Normal file
72
src/command/qualificationCommandHandler.ts
Normal file
|
@ -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<number>}
|
||||
*/
|
||||
static async create(createQualification: CreateQualificationCommand): Promise<number> {
|
||||
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<void>}
|
||||
*/
|
||||
static async update(updateQualification: UpdateQualificationCommand): Promise<void> {
|
||||
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<void>}
|
||||
*/
|
||||
static async delete(deletQualification: DeleteQualificationCommand): Promise<void> {
|
||||
return await dataSource
|
||||
.createQueryBuilder()
|
||||
.delete()
|
||||
.from(qualification)
|
||||
.where("id = :id", { id: deletQualification.id })
|
||||
.execute()
|
||||
.then(() => {})
|
||||
.catch((err) => {
|
||||
throw new InternalException("Failed deleting qualification");
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue