self defined value tables - getters

This commit is contained in:
Julian Krauser 2024-09-04 14:01:22 +02:00
parent c85f23ed73
commit ddb355836a
28 changed files with 1067 additions and 0 deletions

View file

@ -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<Array<award>>}
*/
static async getAll(): Promise<Array<award>> {
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<award>}
*/
static async getById(id: number): Promise<award> {
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<Array<member>>}
// */
// static async getMembersByAwardId(id: number): Promise<Array<member>> {
// 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");
// });
// }
}

View file

@ -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<Array<communication>>}
*/
static async getById(userId: number): Promise<communication> {
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<string>}
*/
static getAvailableColumnsForCommunication(): Array<string> {
let metadata = dataSource.getMetadata(communication);
return metadata.columns.map((c) => c.propertyName);
}
}

View file

@ -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<Array<communicationType>>}
*/
static async getAll(): Promise<Array<communicationType>> {
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<communicationType>}
*/
static async getById(id: number): Promise<communicationType> {
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<Array<member>>}
// */
// static async getMembersBycommunicationTypeId(id: number): Promise<Array<member>> {
// 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");
// });
// }
}

View file

@ -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<Array<executivePosition>>}
*/
static async getAll(): Promise<Array<executivePosition>> {
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<executivePosition>}
*/
static async getById(id: number): Promise<executivePosition> {
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<Array<user>>}
// */
// static async getMembersByexecutivePositionId(id: number): Promise<Array<member>> {
// 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");
// });
// }
}

View file

@ -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<Array<membershipStatus>>}
*/
static async getAll(): Promise<Array<membershipStatus>> {
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<membershipStatus>}
*/
static async getById(id: number): Promise<membershipStatus> {
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<Array<members>>}
// */
// static async getMembersBymembershipStatusId(id: number): Promise<Array<members>> {
// 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");
// });
// }
}

View file

@ -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<Array<qualification>>}
*/
static async getAll(): Promise<Array<qualification>> {
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<qualification>}
*/
static async getById(id: number): Promise<qualification> {
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<Array<member>>}
// */
// static async getMembersByqualificationId(id: number): Promise<Array<member>> {
// 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");
// });
// }
}