diff --git a/src/command/refreshCommandHandler.ts b/src/command/refreshCommandHandler.ts index 42a5d16..c2515f8 100644 --- a/src/command/refreshCommandHandler.ts +++ b/src/command/refreshCommandHandler.ts @@ -58,4 +58,21 @@ export default abstract class RefreshCommandHandler { throw new InternalException("failed refresh removal"); }); } + + /** + * @description delete expired + * @returns {Promise} + */ + static async deleteExpired(): Promise { + return await dataSource + .createQueryBuilder() + .delete() + .from(refresh) + .where("refresh.expiry < :expiry", { expiry: new Date() }) + .execute() + .then((res) => {}) + .catch((err) => { + throw new InternalException("failed expired refresh removal"); + }); + } } diff --git a/src/controller/admin/awardController.ts b/src/controller/admin/awardController.ts new file mode 100644 index 0000000..e9155da --- /dev/null +++ b/src/controller/admin/awardController.ts @@ -0,0 +1,77 @@ +import { Request, Response } from "express"; +import AwardService from "../../service/awardService"; +import AwardFactory from "../../factory/admin/award"; + +/** + * @description get all awards + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getAllAwards(req: Request, res: Response): Promise { + let awards = await AwardService.getAll(); + + res.json(AwardFactory.mapToBase(awards)); +} + +/** + * @description get award by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getAwardById(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + let award = await AwardService.getById(id); + + res.json(AwardFactory.mapToSingle(award)); +} + +/** + * @description get members assigned to award by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getAwardAssignedMembers(req: Request, res: Response): Promise { + const awardId = parseInt(req.params.id); + + res.json([]); +} + +/** + * @description create new award + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function createAward(req: Request, res: Response): Promise { + const award = req.body.award; + + res.sendStatus(204); +} + +/** + * @description update award + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function updateAward(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + const award = req.body.award; + + res.sendStatus(204); +} + +/** + * @description delete award + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteAward(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + + res.sendStatus(204); +} diff --git a/src/controller/admin/communicationTypeController.ts b/src/controller/admin/communicationTypeController.ts new file mode 100644 index 0000000..29264b8 --- /dev/null +++ b/src/controller/admin/communicationTypeController.ts @@ -0,0 +1,77 @@ +import { Request, Response } from "express"; +import CommunicationTypeService from "../../service/communicationTypeService"; +import CommunicationTypeFactory from "../../factory/admin/communicationType"; +import CommunicationService from "../../service/communicationService"; + +/** + * @description get all communicationTypes + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getAllCommunicationTypes(req: Request, res: Response): Promise { + let types = await CommunicationTypeService.getAll(); + + res.json(CommunicationTypeFactory.mapToBase(types)); +} + +/** + * @description get communicationType by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getCommunicationTypeById(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + let type = await CommunicationTypeService.getById(id); + + res.json(CommunicationTypeFactory.mapToSingle(type)); +} + +/** + * @description get columns available to communicationType + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getCommunicationTypeAvailableColumns(req: Request, res: Response): Promise { + let columns = CommunicationService.getAvailableColumnsForCommunication(); + res.json(columns); +} + +/** + * @description create new communicationType + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function createCommunicationType(req: Request, res: Response): Promise { + const communicationType = req.body.communicationType; + + res.sendStatus(204); +} + +/** + * @description update communicationType + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function updateCommunicationType(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + const communicationType = req.body.communicationType; + + res.sendStatus(204); +} + +/** + * @description delete communicationType + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteCommunicationType(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + + res.sendStatus(204); +} diff --git a/src/controller/admin/executivePositionController.ts b/src/controller/admin/executivePositionController.ts new file mode 100644 index 0000000..d99ceba --- /dev/null +++ b/src/controller/admin/executivePositionController.ts @@ -0,0 +1,77 @@ +import { Request, Response } from "express"; +import ExecutivePositionService from "../../service/executivePositionService"; +import ExecutivePositionFactory from "../../factory/admin/executivePosition"; + +/** + * @description get all executivePositions + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getAllExecutivePositions(req: Request, res: Response): Promise { + let positions = await ExecutivePositionService.getAll(); + + res.json(ExecutivePositionFactory.mapToBase(positions)); +} + +/** + * @description get executivePosition by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getExecutivePositionById(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + let position = await ExecutivePositionService.getById(id); + + res.json(ExecutivePositionFactory.mapToSingle(position)); +} + +/** + * @description get members assigned to executivePosition by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getExecutivePositionAssignedMembers(req: Request, res: Response): Promise { + const executivePositionId = parseInt(req.params.id); + + res.json([]); +} + +/** + * @description create new executivePosition + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function createExecutivePosition(req: Request, res: Response): Promise { + const executivePosition = req.body.executivePosition; + + res.sendStatus(204); +} + +/** + * @description update executivePosition + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function updateExecutivePosition(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + const executivePosition = req.body.executivePosition; + + res.sendStatus(204); +} + +/** + * @description delete executivePosition + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteExecutivePosition(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + + res.sendStatus(204); +} diff --git a/src/controller/admin/membershipStatusController.ts b/src/controller/admin/membershipStatusController.ts new file mode 100644 index 0000000..bdcb0a2 --- /dev/null +++ b/src/controller/admin/membershipStatusController.ts @@ -0,0 +1,77 @@ +import { Request, Response } from "express"; +import MembershipStatusService from "../../service/membershipStatusService"; +import MembershipStatusFactory from "../../factory/admin/membershipStatus"; + +/** + * @description get all membershipStatus + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getAllMembershipStatus(req: Request, res: Response): Promise { + let status = await MembershipStatusService.getAll(); + + res.json(MembershipStatusFactory.mapToBase(status)); +} + +/** + * @description get membershipStatus by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getMembershipStatusById(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + let status = await MembershipStatusService.getById(id); + + res.json(MembershipStatusFactory.mapToSingle(status)); +} + +/** + * @description get members assigned to membershipStatus by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getMembershipStatusAssignedMembers(req: Request, res: Response): Promise { + const membershipStatusId = parseInt(req.params.id); + + res.json({}); +} + +/** + * @description create new membershipStatus + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function createMembershipStatus(req: Request, res: Response): Promise { + const membershipStatus = req.body.membershipStatus; + + res.sendStatus(204); +} + +/** + * @description update membershipStatus + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function updateMembershipStatus(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + const membershipStatus = req.body.membershipStatus; + + res.sendStatus(204); +} + +/** + * @description delete membershipStatus + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteMembershipStatus(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + + res.sendStatus(204); +} diff --git a/src/controller/admin/qualificationController.ts b/src/controller/admin/qualificationController.ts new file mode 100644 index 0000000..946b4c8 --- /dev/null +++ b/src/controller/admin/qualificationController.ts @@ -0,0 +1,77 @@ +import { Request, Response } from "express"; +import QualificationService from "../../service/qualification"; +import QualificationFactory from "../../factory/admin/qualification"; + +/** + * @description get all qualifications + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getAllQualifications(req: Request, res: Response): Promise { + let qualifications = await QualificationService.getAll(); + + res.json(QualificationFactory.mapToBase(qualifications)); +} + +/** + * @description get qualification by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getQualificationById(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + let qualification = await QualificationService.getById(id); + + res.json(QualificationFactory.mapToSingle(qualification)); +} + +/** + * @description get members assigned to qualification by id + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function getQualificationAssignedMembers(req: Request, res: Response): Promise { + const qualificationId = parseInt(req.params.id); + + res.json({}); +} + +/** + * @description create new qualification + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function createQualification(req: Request, res: Response): Promise { + const qualification = req.body.qualification; + + res.sendStatus(204); +} + +/** + * @description update qualification + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function updateQualification(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + const qualification = req.body.qualification; + + res.sendStatus(204); +} + +/** + * @description delete qualification + * @param req {Request} Express req object + * @param res {Response} Express res object + * @returns {Promise<*>} + */ +export async function deleteQualification(req: Request, res: Response): Promise { + const id = parseInt(req.params.id); + + res.sendStatus(204); +} diff --git a/src/factory/admin/award.ts b/src/factory/admin/award.ts new file mode 100644 index 0000000..440e957 --- /dev/null +++ b/src/factory/admin/award.ts @@ -0,0 +1,25 @@ +import { award } from "../../entity/award"; +import { AwardViewModel } from "../../viewmodel/admin/award.models"; + +export default abstract class AwardFactory { + /** + * @description map record to award + * @param {award} record + * @returns {AwardViewModel} + */ + public static mapToSingle(record: award): AwardViewModel { + return { + id: record.id, + award: record.award, + }; + } + + /** + * @description map records to award + * @param {Array} records + * @returns {Array} + */ + public static mapToBase(records: Array): Array { + return records.map((r) => this.mapToSingle(r)); + } +} diff --git a/src/factory/admin/communicationType.ts b/src/factory/admin/communicationType.ts new file mode 100644 index 0000000..a16efa1 --- /dev/null +++ b/src/factory/admin/communicationType.ts @@ -0,0 +1,26 @@ +import { communicationType } from "../../entity/communicationType"; +import { CommunicationTypeViewModel } from "../../viewmodel/admin/communicationType.models"; + +export default abstract class CommunicationTypeFactory { + /** + * @description map record to communicationType + * @param {communicationType} record + * @returns {CommunicationTypeViewModel} + */ + public static mapToSingle(record: communicationType): CommunicationTypeViewModel { + return { + id: record.id, + type: record.type, + useColumns: record.useColumns, + }; + } + + /** + * @description map records to communicationType + * @param {Array} records + * @returns {Array} + */ + public static mapToBase(records: Array): Array { + return records.map((r) => this.mapToSingle(r)); + } +} diff --git a/src/factory/admin/executivePosition.ts b/src/factory/admin/executivePosition.ts new file mode 100644 index 0000000..9a1b3b6 --- /dev/null +++ b/src/factory/admin/executivePosition.ts @@ -0,0 +1,25 @@ +import { executivePosition } from "../../entity/executivePosition"; +import { ExecutivePositionViewModel } from "../../viewmodel/admin/executivePosition.models"; + +export default abstract class ExecutivePositionFactory { + /** + * @description map record to executivePosition + * @param {executivePosition} record + * @returns {ExecutivePositionViewModel} + */ + public static mapToSingle(record: executivePosition): ExecutivePositionViewModel { + return { + id: record.id, + position: record.position, + }; + } + + /** + * @description map records to executivePosition + * @param {Array} records + * @returns {Array} + */ + public static mapToBase(records: Array): Array { + return records.map((r) => this.mapToSingle(r)); + } +} diff --git a/src/factory/admin/membershipStatus.ts b/src/factory/admin/membershipStatus.ts new file mode 100644 index 0000000..43a11c2 --- /dev/null +++ b/src/factory/admin/membershipStatus.ts @@ -0,0 +1,25 @@ +import { membershipStatus } from "../../entity/membershipStatus"; +import { MembershipStatusViewModel } from "../../viewmodel/admin/membershipStatus.models"; + +export default abstract class MembershipStatusFactory { + /** + * @description map record to membershipStatus + * @param {membershipStatus} record + * @returns {MembershipStatusViewModel} + */ + public static mapToSingle(record: membershipStatus): MembershipStatusViewModel { + return { + id: record.id, + status: record.status, + }; + } + + /** + * @description map records to membershipStatus + * @param {Array} records + * @returns {Array} + */ + public static mapToBase(records: Array): Array { + return records.map((r) => this.mapToSingle(r)); + } +} diff --git a/src/factory/admin/qualification.ts b/src/factory/admin/qualification.ts new file mode 100644 index 0000000..f7edb62 --- /dev/null +++ b/src/factory/admin/qualification.ts @@ -0,0 +1,26 @@ +import { qualification } from "../../entity/qualification"; +import { QualificationViewModel } from "../../viewmodel/admin/qualification.models"; + +export default abstract class QualificationFactory { + /** + * @description map record to qualification + * @param {qualification} record + * @returns {AwardViewModel} + */ + public static mapToSingle(record: qualification): QualificationViewModel { + return { + id: record.id, + qualification: record.qualification, + description: record.description, + }; + } + + /** + * @description map records to qualification + * @param {Array} records + * @returns {Array} + */ + public static mapToBase(records: Array): Array { + return records.map((r) => this.mapToSingle(r)); + } +} diff --git a/src/index.ts b/src/index.ts index 833e7c1..d551a1e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,3 +25,10 @@ router(app); app.listen(SERVER_PORT, () => { console.log(`listening on *:${SERVER_PORT}`); }); + +import schedule from "node-schedule"; +import RefreshCommandHandler from "./command/refreshCommandHandler"; +const job = schedule.scheduleJob("0 0 * * *", async () => { + console.log(`running Cron at ${new Date()}`); + await RefreshCommandHandler.deleteExpired(); +}); diff --git a/src/routes/admin/award.ts b/src/routes/admin/award.ts new file mode 100644 index 0000000..84eebdf --- /dev/null +++ b/src/routes/admin/award.ts @@ -0,0 +1,35 @@ +import express, { Request, Response } from "express"; +import { + createAward, + deleteAward, + getAllAwards, + getAwardAssignedMembers, + getAwardById, + updateAward, +} from "../../controller/admin/awardController"; + +var router = express.Router({ mergeParams: true }); + +router.get("/", async (req: Request, res: Response) => { + await getAllAwards(req, res); +}); + +router.get("/:id", async (req: Request, res: Response) => { + await getAwardById(req, res); +}); + +router.get("/:id/assigned", async (req: Request, res: Response) => { + await getAwardAssignedMembers(req, res); +}); + +router.post("/", async (req: Request, res: Response) => { + await createAward(req, res); +}); + +router.patch("/:id", async (req: Request, res: Response) => { + await updateAward(req, res); +}); + +router.delete("/:id", async (req: Request, res: Response) => { + await deleteAward(req, res); +}); diff --git a/src/routes/admin/communicationType.ts b/src/routes/admin/communicationType.ts new file mode 100644 index 0000000..83fce1f --- /dev/null +++ b/src/routes/admin/communicationType.ts @@ -0,0 +1,35 @@ +import express, { Request, Response } from "express"; +import { + createCommunicationType, + deleteCommunicationType, + getAllCommunicationTypes, + getCommunicationTypeAvailableColumns, + getCommunicationTypeById, + updateCommunicationType, +} from "../../controller/admin/communicationTypeController"; + +var router = express.Router({ mergeParams: true }); + +router.get("/", async (req: Request, res: Response) => { + await getAllCommunicationTypes(req, res); +}); + +router.get("/:id", async (req: Request, res: Response) => { + await getCommunicationTypeById(req, res); +}); + +router.get("/fields", async (req: Request, res: Response) => { + await getCommunicationTypeAvailableColumns(req, res); +}); + +router.post("/", async (req: Request, res: Response) => { + await createCommunicationType(req, res); +}); + +router.patch("/:id", async (req: Request, res: Response) => { + await updateCommunicationType(req, res); +}); + +router.delete("/:id", async (req: Request, res: Response) => { + await deleteCommunicationType(req, res); +}); diff --git a/src/routes/admin/executivePosition.ts b/src/routes/admin/executivePosition.ts new file mode 100644 index 0000000..13c15ca --- /dev/null +++ b/src/routes/admin/executivePosition.ts @@ -0,0 +1,35 @@ +import express, { Request, Response } from "express"; +import { + createExecutivePosition, + deleteExecutivePosition, + getAllExecutivePositions, + getExecutivePositionAssignedMembers, + getExecutivePositionById, + updateExecutivePosition, +} from "../../controller/admin/executivePositionController"; + +var router = express.Router({ mergeParams: true }); + +router.get("/", async (req: Request, res: Response) => { + await getAllExecutivePositions(req, res); +}); + +router.get("/:id", async (req: Request, res: Response) => { + await getExecutivePositionById(req, res); +}); + +router.get("/:id/assigned", async (req: Request, res: Response) => { + await getExecutivePositionAssignedMembers(req, res); +}); + +router.post("/", async (req: Request, res: Response) => { + await createExecutivePosition(req, res); +}); + +router.patch("/:id", async (req: Request, res: Response) => { + await updateExecutivePosition(req, res); +}); + +router.delete("/:id", async (req: Request, res: Response) => { + await deleteExecutivePosition(req, res); +}); diff --git a/src/routes/admin/membershipStatus.ts b/src/routes/admin/membershipStatus.ts new file mode 100644 index 0000000..f62153c --- /dev/null +++ b/src/routes/admin/membershipStatus.ts @@ -0,0 +1,35 @@ +import express, { Request, Response } from "express"; +import { + createMembershipStatus, + deleteMembershipStatus, + getAllMembershipStatus, + getMembershipStatusAssignedMembers, + getMembershipStatusById, + updateMembershipStatus, +} from "../../controller/admin/membershipStatusController"; + +var router = express.Router({ mergeParams: true }); + +router.get("/", async (req: Request, res: Response) => { + await getAllMembershipStatus(req, res); +}); + +router.get("/:id", async (req: Request, res: Response) => { + await getMembershipStatusById(req, res); +}); + +router.get("/:id/assigned", async (req: Request, res: Response) => { + await getMembershipStatusAssignedMembers(req, res); +}); + +router.post("/", async (req: Request, res: Response) => { + await createMembershipStatus(req, res); +}); + +router.patch("/:id", async (req: Request, res: Response) => { + await updateMembershipStatus(req, res); +}); + +router.delete("/:id", async (req: Request, res: Response) => { + await deleteMembershipStatus(req, res); +}); diff --git a/src/routes/admin/qualification.ts b/src/routes/admin/qualification.ts new file mode 100644 index 0000000..cdbe709 --- /dev/null +++ b/src/routes/admin/qualification.ts @@ -0,0 +1,35 @@ +import express, { Request, Response } from "express"; +import { + createQualification, + deleteQualification, + getAllQualifications, + getQualificationAssignedMembers, + getQualificationById, + updateQualification, +} from "../../controller/admin/qualificationController"; + +var router = express.Router({ mergeParams: true }); + +router.get("/", async (req: Request, res: Response) => { + await getAllQualifications(req, res); +}); + +router.get("/:id", async (req: Request, res: Response) => { + await getQualificationById(req, res); +}); + +router.get("/:id/assigned", async (req: Request, res: Response) => { + await getQualificationAssignedMembers(req, res); +}); + +router.post("/", async (req: Request, res: Response) => { + await createQualification(req, res); +}); + +router.patch("/:id", async (req: Request, res: Response) => { + await updateQualification(req, res); +}); + +router.delete("/:id", async (req: Request, res: Response) => { + await deleteQualification(req, res); +}); diff --git a/src/service/awardService.ts b/src/service/awardService.ts new file mode 100644 index 0000000..e9b5ff3 --- /dev/null +++ b/src/service/awardService.ts @@ -0,0 +1,60 @@ +import { dataSource } from "../data-source"; +import { award } from "../entity/award"; +import { user } from "../entity/user"; +import InternalException from "../exceptions/internalException"; + +export default abstract class AwardService { + /** + * @description get all awards + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(award) + .createQueryBuilder("award") + .getMany() + .then((res) => { + return res; + }) + .catch(() => { + throw new InternalException("awards not found"); + }); + } + + /** + * @description get award by id + * @returns {Promise} + */ + static async getById(id: number): Promise { + return await dataSource + .getRepository(award) + .createQueryBuilder("award") + .andWhere("award.id = :id", { id: id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch(() => { + throw new InternalException("award not found by id"); + }); + } + + // /** + // * @description get members assigned to award + // * @returns {Promise>} + // */ + // static async getMembersByAwardId(id: number): Promise> { + // return await dataSource + // .getRepository(award) + // .createQueryBuilder("award") + // .leftJoinAndSelect("award.members", "members") + // .andWhere("award.id = :id", { id: id }) + // .getOneOrFail() + // .then((res) => { + // return []; + // }) + // .catch(() => { + // throw new InternalException("award assigned members not found by id"); + // }); + // } +} diff --git a/src/service/communicationService.ts b/src/service/communicationService.ts new file mode 100644 index 0000000..b30884e --- /dev/null +++ b/src/service/communicationService.ts @@ -0,0 +1,33 @@ +import { dataSource } from "../data-source"; +import { communication } from "../entity/communication"; +import InternalException from "../exceptions/internalException"; + +export default abstract class CommunicationService { + /** + * @description get communications by user + * @returns {Promise>} + */ + static async getById(userId: number): Promise { + return await dataSource + .getRepository(communication) + .createQueryBuilder("communication") + .leftJoin("communication.user", "user") + .andWhere("user.id = :id", { id: userId }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch(() => { + throw new InternalException("communications not found by userid"); + }); + } + + /** + * @description get available columns for self made com type + * @returns {Array} + */ + static getAvailableColumnsForCommunication(): Array { + let metadata = dataSource.getMetadata(communication); + return metadata.columns.map((c) => c.propertyName); + } +} diff --git a/src/service/communicationTypeService.ts b/src/service/communicationTypeService.ts new file mode 100644 index 0000000..609d610 --- /dev/null +++ b/src/service/communicationTypeService.ts @@ -0,0 +1,61 @@ +import { dataSource } from "../data-source"; +import { communication } from "../entity/communication"; +import { communicationType } from "../entity/communicationType"; +import { user } from "../entity/user"; +import InternalException from "../exceptions/internalException"; + +export default abstract class CommunicationTypeService { + /** + * @description get all communicationTypes + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(communicationType) + .createQueryBuilder("communicationType") + .getMany() + .then((res) => { + return res; + }) + .catch(() => { + throw new InternalException("communicationTypes not found"); + }); + } + + /** + * @description get communicationType by id + * @returns {Promise} + */ + static async getById(id: number): Promise { + return await dataSource + .getRepository(communicationType) + .createQueryBuilder("communicationType") + .andWhere("communicationType.id = :id", { id: id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch(() => { + throw new InternalException("communicationType not found by id"); + }); + } + + // /** + // * @description get members assigned to communicationType + // * @returns {Promise>} + // */ + // static async getMembersBycommunicationTypeId(id: number): Promise> { + // return await dataSource + // .getRepository(communicationType) + // .createQueryBuilder("communicationType") + // .leftJoinAndSelect("communicationType.members", "members") + // .andWhere("communicationType.id = :id", { id: id }) + // .getOneOrFail() + // .then((res) => { + // return []; + // }) + // .catch(() => { + // throw new InternalException("communicationType assigned members not found by id"); + // }); + // } +} diff --git a/src/service/executivePositionService.ts b/src/service/executivePositionService.ts new file mode 100644 index 0000000..3237dce --- /dev/null +++ b/src/service/executivePositionService.ts @@ -0,0 +1,60 @@ +import { dataSource } from "../data-source"; +import { executivePosition } from "../entity/executivePosition"; +import { user } from "../entity/user"; +import InternalException from "../exceptions/internalException"; + +export default abstract class ExecutivePositionService { + /** + * @description get all executivePositions + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(executivePosition) + .createQueryBuilder("executivePosition") + .getMany() + .then((res) => { + return res; + }) + .catch(() => { + throw new InternalException("executivePositions not found"); + }); + } + + /** + * @description get executivePosition by id + * @returns {Promise} + */ + static async getById(id: number): Promise { + return await dataSource + .getRepository(executivePosition) + .createQueryBuilder("executivePosition") + .andWhere("executivePosition.id = :id", { id: id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch(() => { + throw new InternalException("executivePosition not found by id"); + }); + } + + // /** + // * @description get members assigned to executivePosition + // * @returns {Promise>} + // */ + // static async getMembersByexecutivePositionId(id: number): Promise> { + // return await dataSource + // .getRepository(executivePosition) + // .createQueryBuilder("executivePosition") + // .leftJoinAndSelect("executivePosition.members", "members") + // .andWhere("executivePosition.id = :id", { id: id }) + // .getOneOrFail() + // .then((res) => { + // return []; + // }) + // .catch(() => { + // throw new InternalException("executivePosition assigned members not found by id"); + // }); + // } +} diff --git a/src/service/membershipStatusService.ts b/src/service/membershipStatusService.ts new file mode 100644 index 0000000..2ad5ec1 --- /dev/null +++ b/src/service/membershipStatusService.ts @@ -0,0 +1,60 @@ +import { dataSource } from "../data-source"; +import { membershipStatus } from "../entity/membershipStatus"; +import { user } from "../entity/user"; +import InternalException from "../exceptions/internalException"; + +export default abstract class MembershipStatusService { + /** + * @description get all membershipStatuss + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(membershipStatus) + .createQueryBuilder("membershipStatus") + .getMany() + .then((res) => { + return res; + }) + .catch(() => { + throw new InternalException("membershipStatuss not found"); + }); + } + + /** + * @description get membershipStatus by id + * @returns {Promise} + */ + static async getById(id: number): Promise { + return await dataSource + .getRepository(membershipStatus) + .createQueryBuilder("membershipStatus") + .andWhere("membershipStatus.id = :id", { id: id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch(() => { + throw new InternalException("membershipStatus not found by id"); + }); + } + + // /** + // * @description get members assigned to membershipStatus + // * @returns {Promise>} + // */ + // static async getMembersBymembershipStatusId(id: number): Promise> { + // return await dataSource + // .getRepository(membershipStatus) + // .createQueryBuilder("membershipStatus") + // .leftJoinAndSelect("membershipStatus.members", "members") + // .andWhere("membershipStatus.id = :id", { id: id }) + // .getOneOrFail() + // .then((res) => { + // return []; + // }) + // .catch(() => { + // throw new InternalException("membershipStatus assigned members not found by id"); + // }); + // } +} diff --git a/src/service/qualification.ts b/src/service/qualification.ts new file mode 100644 index 0000000..328e093 --- /dev/null +++ b/src/service/qualification.ts @@ -0,0 +1,60 @@ +import { dataSource } from "../data-source"; +import { qualification } from "../entity/qualification"; +import { user } from "../entity/user"; +import InternalException from "../exceptions/internalException"; + +export default abstract class QualificationService { + /** + * @description get all qualifications + * @returns {Promise>} + */ + static async getAll(): Promise> { + return await dataSource + .getRepository(qualification) + .createQueryBuilder("qualification") + .getMany() + .then((res) => { + return res; + }) + .catch(() => { + throw new InternalException("qualifications not found"); + }); + } + + /** + * @description get qualification by id + * @returns {Promise} + */ + static async getById(id: number): Promise { + return await dataSource + .getRepository(qualification) + .createQueryBuilder("qualification") + .andWhere("qualification.id = :id", { id: id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch(() => { + throw new InternalException("qualification not found by id"); + }); + } + + // /** + // * @description get members assigned to qualification + // * @returns {Promise>} + // */ + // static async getMembersByqualificationId(id: number): Promise> { + // return await dataSource + // .getRepository(qualification) + // .createQueryBuilder("qualification") + // .leftJoinAndSelect("qualification.members", "members") + // .andWhere("qualification.id = :id", { id: id }) + // .getOneOrFail() + // .then((res) => { + // return []; + // }) + // .catch(() => { + // throw new InternalException("qualification assigned members not found by id"); + // }); + // } +} diff --git a/src/viewmodel/admin/award.models.ts b/src/viewmodel/admin/award.models.ts new file mode 100644 index 0000000..64f2db4 --- /dev/null +++ b/src/viewmodel/admin/award.models.ts @@ -0,0 +1,4 @@ +export interface AwardViewModel { + id: number; + award: string; +} diff --git a/src/viewmodel/admin/communicationType.models.ts b/src/viewmodel/admin/communicationType.models.ts new file mode 100644 index 0000000..b2113a8 --- /dev/null +++ b/src/viewmodel/admin/communicationType.models.ts @@ -0,0 +1,5 @@ +export interface CommunicationTypeViewModel { + id: number; + type: string; + useColumns: Array; +} diff --git a/src/viewmodel/admin/executivePosition.models.ts b/src/viewmodel/admin/executivePosition.models.ts new file mode 100644 index 0000000..8c556cd --- /dev/null +++ b/src/viewmodel/admin/executivePosition.models.ts @@ -0,0 +1,4 @@ +export interface ExecutivePositionViewModel { + id: number; + position: string; +} diff --git a/src/viewmodel/admin/membershipStatus.models.ts b/src/viewmodel/admin/membershipStatus.models.ts new file mode 100644 index 0000000..12ae8c2 --- /dev/null +++ b/src/viewmodel/admin/membershipStatus.models.ts @@ -0,0 +1,4 @@ +export interface MembershipStatusViewModel { + id: number; + status: string; +} diff --git a/src/viewmodel/admin/qualification.models.ts b/src/viewmodel/admin/qualification.models.ts new file mode 100644 index 0000000..c52d639 --- /dev/null +++ b/src/viewmodel/admin/qualification.models.ts @@ -0,0 +1,5 @@ +export interface QualificationViewModel { + id: number; + qualification: string; + description: string | null; +}