diff --git a/src/command/club/calendar/calendarCommandHandler.ts b/src/command/club/calendar/calendarCommandHandler.ts index 5cd89b6..97fbff4 100644 --- a/src/command/club/calendar/calendarCommandHandler.ts +++ b/src/command/club/calendar/calendarCommandHandler.ts @@ -1,6 +1,7 @@ import { dataSource } from "../../../data-source"; import { calendar } from "../../../entity/club/calendar"; import { calendarType } from "../../../entity/settings/calendarType"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateCalendarCommand, DeleteCalendarCommand, UpdateCalendarCommand } from "./calendarCommand"; @@ -33,7 +34,7 @@ export default abstract class CalendarCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating calendar", err); + throw new DatabaseActionException("CREATE", "calendar", err); }); } @@ -72,7 +73,7 @@ export default abstract class CalendarCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating award", err); + throw new DatabaseActionException("UPDATE", "calendar", err); }); } @@ -90,7 +91,7 @@ export default abstract class CalendarCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed deleting calendar", err); + throw new DatabaseActionException("DELETE", "calendar", err); }); } } diff --git a/src/command/club/member/communicationCommandHandler.ts b/src/command/club/member/communicationCommandHandler.ts index 24402fc..3899394 100644 --- a/src/command/club/member/communicationCommandHandler.ts +++ b/src/command/club/member/communicationCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { communication } from "../../../entity/club/member/communication"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateCommunicationCommand, @@ -54,7 +55,7 @@ export default abstract class CommunicationCommandHandler { return insertId; }) .catch((err) => { - throw new InternalException("Failed creating communication", err); + throw new DatabaseActionException("CREATE", "communication", err); }); } @@ -97,7 +98,7 @@ export default abstract class CommunicationCommandHandler { }) .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating communication", err); + throw new DatabaseActionException("UPDATE", "communication", err); }); } @@ -116,7 +117,7 @@ export default abstract class CommunicationCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed deleting communication", err); + throw new DatabaseActionException("DELETE", "communication", err); }); } } diff --git a/src/command/club/member/memberAwardCommandHandler.ts b/src/command/club/member/memberAwardCommandHandler.ts index 0a02e01..53deccf 100644 --- a/src/command/club/member/memberAwardCommandHandler.ts +++ b/src/command/club/member/memberAwardCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { memberAwards } from "../../../entity/club/member/memberAwards"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateMemberAwardCommand, DeleteMemberAwardCommand, UpdateMemberAwardCommand } from "./memberAwardCommand"; @@ -26,7 +27,7 @@ export default abstract class MemberAwardCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating memberAward", err); + throw new DatabaseActionException("CREATE", "memberAward", err); }); } @@ -50,7 +51,7 @@ export default abstract class MemberAwardCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating memberAward", err); + throw new DatabaseActionException("UPDATE", "memberAward", err); }); } @@ -69,7 +70,7 @@ export default abstract class MemberAwardCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed deleting memberAward", err); + throw new DatabaseActionException("DELETE", "memberAward", err); }); } } diff --git a/src/command/club/member/memberCommandHandler.ts b/src/command/club/member/memberCommandHandler.ts index 54862f7..78f1da0 100644 --- a/src/command/club/member/memberCommandHandler.ts +++ b/src/command/club/member/memberCommandHandler.ts @@ -1,6 +1,7 @@ import { dataSource } from "../../../data-source"; import { communication } from "../../../entity/club/member/communication"; import { member } from "../../../entity/club/member/member"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateMemberCommand, DeleteMemberCommand, UpdateMemberCommand } from "./memberCommand"; @@ -28,10 +29,7 @@ export default abstract class MemberCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException( - `Failed creating member${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`, - err - ); + throw new DatabaseActionException("CREATE", "member", err); }); } @@ -56,10 +54,7 @@ export default abstract class MemberCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException( - `Failed updating member${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`, - err - ); + throw new DatabaseActionException("UPDATE", "member", err); }); } @@ -77,7 +72,7 @@ export default abstract class MemberCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed deleting member", err); + throw new DatabaseActionException("DELETE", "member", err); }); } } diff --git a/src/command/club/member/memberExecutivePositionCommandHandler.ts b/src/command/club/member/memberExecutivePositionCommandHandler.ts index f683541..95d5ab2 100644 --- a/src/command/club/member/memberExecutivePositionCommandHandler.ts +++ b/src/command/club/member/memberExecutivePositionCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { memberExecutivePositions } from "../../../entity/club/member/memberExecutivePositions"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateMemberExecutivePositionCommand, @@ -30,7 +31,7 @@ export default abstract class MemberExecutivePositionCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating memberExecutivePosition", err); + throw new DatabaseActionException("CREATE", "memberExecutivePosition", err); }); } @@ -54,7 +55,7 @@ export default abstract class MemberExecutivePositionCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating memberExecutivePosition", err); + throw new DatabaseActionException("UPDATE", "memberExecutivePosition", err); }); } @@ -73,7 +74,7 @@ export default abstract class MemberExecutivePositionCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed deleting memberExecutivePosition", err); + throw new DatabaseActionException("DELETE", "memberExecutivePosition", err); }); } } diff --git a/src/command/club/member/memberQualificationCommandHandler.ts b/src/command/club/member/memberQualificationCommandHandler.ts index 351cfb6..7ec87e3 100644 --- a/src/command/club/member/memberQualificationCommandHandler.ts +++ b/src/command/club/member/memberQualificationCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { memberQualifications } from "../../../entity/club/member/memberQualifications"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateMemberQualificationCommand, @@ -29,7 +30,7 @@ export default abstract class MemberQualificationCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating memberQualification", err); + throw new DatabaseActionException("CREATE", "memberQualification", err); }); } @@ -54,7 +55,7 @@ export default abstract class MemberQualificationCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating memberQualification", err); + throw new DatabaseActionException("UPDATE", "memberQualification", err); }); } @@ -73,7 +74,7 @@ export default abstract class MemberQualificationCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed deleting memberQualification", err); + throw new DatabaseActionException("DELETE", "memberQualification", err); }); } } diff --git a/src/command/club/member/membershipCommandHandler.ts b/src/command/club/member/membershipCommandHandler.ts index 0cd0e5a..52f3029 100644 --- a/src/command/club/member/membershipCommandHandler.ts +++ b/src/command/club/member/membershipCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { membership } from "../../../entity/club/member/membership"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateMembershipCommand, DeleteMembershipCommand, UpdateMembershipCommand } from "./membershipCommand"; @@ -43,7 +44,7 @@ export default abstract class MembershipCommandHandler { return insertId; }) .catch((err) => { - throw new InternalException("Failed creating membership", err); + throw new DatabaseActionException("CREATE", "membership", err); }); } @@ -67,7 +68,7 @@ export default abstract class MembershipCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating membership", err); + throw new DatabaseActionException("UPDATE", "membership", err); }); } @@ -86,7 +87,7 @@ export default abstract class MembershipCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed deleting membership", err); + throw new DatabaseActionException("DELETE", "membership", err); }); } } diff --git a/src/command/club/newsletter/newsletterCommandHandler.ts b/src/command/club/newsletter/newsletterCommandHandler.ts index 38c156b..45eb281 100644 --- a/src/command/club/newsletter/newsletterCommandHandler.ts +++ b/src/command/club/newsletter/newsletterCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { newsletter } from "../../../entity/club/newsletter/newsletter"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateNewsletterCommand, SendNewsletterCommand, SynchronizeNewsletterCommand } from "./newsletterCommand"; @@ -22,7 +23,7 @@ export default abstract class NewsletterCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating newsletter", err); + throw new DatabaseActionException("CREATE", "newsletter", err); }); } @@ -47,7 +48,7 @@ export default abstract class NewsletterCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed synching newsletter", err); + throw new DatabaseActionException("SYNC", "newsletter", err); }); } @@ -67,7 +68,7 @@ export default abstract class NewsletterCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed setting newsletter send state", err); + throw new DatabaseActionException("SET SEND STATE", "newsletter", err); }); } } diff --git a/src/command/club/newsletter/newsletterDatesCommandHandler.ts b/src/command/club/newsletter/newsletterDatesCommandHandler.ts index efaea75..2a11d43 100644 --- a/src/command/club/newsletter/newsletterDatesCommandHandler.ts +++ b/src/command/club/newsletter/newsletterDatesCommandHandler.ts @@ -4,6 +4,7 @@ import InternalException from "../../../exceptions/internalException"; import NewsletterDatesService from "../../../service/club/newsletter/newsletterDatesService"; import { NewsletterDateCommand, SynchronizeNewsletterDatesCommand } from "./newsletterDatesCommand"; import { newsletterDates } from "../../../entity/club/newsletter/newsletterDates"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; export default abstract class NewsletterDatesCommandHandler { /** @@ -42,7 +43,7 @@ export default abstract class NewsletterDatesCommandHandler { }) .then(() => {}) .catch((err) => { - throw new InternalException("Failed syncing newsletter dates", err); + throw new DatabaseActionException("SYNC", "newsletterDates", err); }); } diff --git a/src/command/club/newsletter/newsletterRecipientsCommandHandler.ts b/src/command/club/newsletter/newsletterRecipientsCommandHandler.ts index 2be82e0..76fa67d 100644 --- a/src/command/club/newsletter/newsletterRecipientsCommandHandler.ts +++ b/src/command/club/newsletter/newsletterRecipientsCommandHandler.ts @@ -4,6 +4,7 @@ import InternalException from "../../../exceptions/internalException"; import NewsletterRecipientsService from "../../../service/club/newsletter/newsletterRecipientsService"; import { SynchronizeNewsletterRecipientsCommand } from "./newsletterRecipientsCommand"; import { newsletterRecipients } from "../../../entity/club/newsletter/newsletterRecipients"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; export default abstract class NewsletterRecipientsCommandHandler { /** @@ -35,7 +36,7 @@ export default abstract class NewsletterRecipientsCommandHandler { }) .then(() => {}) .catch((err) => { - throw new InternalException("Failed syncing newsletter recipients", err); + throw new DatabaseActionException("SYNC", "newsletterRecipients", err); }); } diff --git a/src/command/club/protocol/protocolAgendaCommandHandler.ts b/src/command/club/protocol/protocolAgendaCommandHandler.ts index 0c74179..02fe4f2 100644 --- a/src/command/club/protocol/protocolAgendaCommandHandler.ts +++ b/src/command/club/protocol/protocolAgendaCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { protocolAgenda } from "../../../entity/club/protocol/protocolAgenda"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { SynchronizeProtocolAgendaCommand } from "./protocolAgendaCommand"; @@ -24,7 +25,7 @@ export default abstract class ProtocolAgendaCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating protocol", err); + throw new DatabaseActionException("CREATE", "protocolAgenda", err); }); } @@ -43,7 +44,7 @@ export default abstract class ProtocolAgendaCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed creating protocol", err); + throw new DatabaseActionException("SYNC", "protocolAgenda", err); }); } } diff --git a/src/command/club/protocol/protocolCommandHandler.ts b/src/command/club/protocol/protocolCommandHandler.ts index 95e5017..7174594 100644 --- a/src/command/club/protocol/protocolCommandHandler.ts +++ b/src/command/club/protocol/protocolCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { protocol } from "../../../entity/club/protocol/protocol"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateProtocolCommand, SynchronizeProtocolCommand } from "./protocolCommand"; @@ -23,7 +24,7 @@ export default abstract class ProtocolCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating protocol", err); + throw new DatabaseActionException("CREATE", "protocol", err); }); } @@ -47,7 +48,7 @@ export default abstract class ProtocolCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed creating protocol", err); + throw new DatabaseActionException("SYNC", "protocol", err); }); } } diff --git a/src/command/club/protocol/protocolDecisionCommandHandler.ts b/src/command/club/protocol/protocolDecisionCommandHandler.ts index 19aba38..585abf1 100644 --- a/src/command/club/protocol/protocolDecisionCommandHandler.ts +++ b/src/command/club/protocol/protocolDecisionCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { protocolDecision } from "../../../entity/club/protocol/protocolDecision"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { SynchronizeProtocolDecisionCommand } from "./protocolDecisionCommand"; @@ -24,7 +25,7 @@ export default abstract class ProtocolDecisionCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating protocol", err); + throw new DatabaseActionException("CREATE", "protocolDecision", err); }); } /** @@ -42,7 +43,7 @@ export default abstract class ProtocolDecisionCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed creating protocol", err); + throw new DatabaseActionException("SYNC", "protocolDecision", err); }); } } diff --git a/src/command/club/protocol/protocolPresenceCommandHandler.ts b/src/command/club/protocol/protocolPresenceCommandHandler.ts index 8d48fe6..0bdc302 100644 --- a/src/command/club/protocol/protocolPresenceCommandHandler.ts +++ b/src/command/club/protocol/protocolPresenceCommandHandler.ts @@ -4,6 +4,7 @@ import { protocolPresence } from "../../../entity/club/protocol/protocolPresence import InternalException from "../../../exceptions/internalException"; import ProtocolPresenceService from "../../../service/club/protocol/protocolPrecenseService"; import { ProtocolPresenceCommand, SynchronizeProtocolPresenceCommand } from "./protocolPresenceCommand"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; export default abstract class ProtocolPresenceCommandHandler { /** @@ -42,7 +43,7 @@ export default abstract class ProtocolPresenceCommandHandler { }) .then(() => {}) .catch((err) => { - throw new InternalException("Failed saving protocol presence", err); + throw new DatabaseActionException("SYNC", "protocolSresence", err); }); } diff --git a/src/command/club/protocol/protocolPrintoutCommandHandler.ts b/src/command/club/protocol/protocolPrintoutCommandHandler.ts index 9ceabea..5ef3770 100644 --- a/src/command/club/protocol/protocolPrintoutCommandHandler.ts +++ b/src/command/club/protocol/protocolPrintoutCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { protocolPrintout } from "../../../entity/club/protocol/protocolPrintout"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateProtocolPrintoutCommand } from "./protocolPrintoutCommand"; @@ -25,7 +26,7 @@ export default abstract class ProtocolPrintoutCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating protocol", err); + throw new DatabaseActionException("CREATE", "protocolPrintout", err); }); } } diff --git a/src/command/club/protocol/protocolVotingCommandHandler.ts b/src/command/club/protocol/protocolVotingCommandHandler.ts index 6b8834d..45a4642 100644 --- a/src/command/club/protocol/protocolVotingCommandHandler.ts +++ b/src/command/club/protocol/protocolVotingCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { protocolVoting } from "../../../entity/club/protocol/protocolVoting"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { SynchronizeProtocolVotingCommand } from "./protocolVotingCommand"; @@ -24,7 +25,7 @@ export default abstract class ProtocolVotingCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating protocol", err); + throw new DatabaseActionException("CREATE", "protocolVoting", err); }); } /** @@ -42,7 +43,7 @@ export default abstract class ProtocolVotingCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed creating protocol", err); + throw new DatabaseActionException("SYNC", "protocolVoting", err); }); } } diff --git a/src/command/refreshCommandHandler.ts b/src/command/refreshCommandHandler.ts index 709f51b..5796851 100644 --- a/src/command/refreshCommandHandler.ts +++ b/src/command/refreshCommandHandler.ts @@ -1,6 +1,7 @@ import { dataSource } from "../data-source"; import { refresh } from "../entity/refresh"; import { PWA_REFRESH_EXPIRATION, REFRESH_EXPIRATION } from "../env.defaults"; +import DatabaseActionException from "../exceptions/databaseActionException"; import InternalException from "../exceptions/internalException"; import { StringHelper } from "../helpers/stringHelper"; import UserService from "../service/user/userService"; @@ -32,7 +33,7 @@ export default abstract class RefreshCommandHandler { return refreshToken; }) .catch((err) => { - throw new InternalException("Failed saving refresh token", err); + throw new DatabaseActionException("CREATE", "refresh", err); }); } @@ -51,7 +52,7 @@ export default abstract class RefreshCommandHandler { .execute() .then((res) => {}) .catch((err) => { - throw new InternalException("failed refresh removal", err); + throw new DatabaseActionException("DELETE", "refresh", err); }); } @@ -68,7 +69,7 @@ export default abstract class RefreshCommandHandler { .execute() .then((res) => {}) .catch((err) => { - throw new InternalException("failed expired refresh removal", err); + throw new DatabaseActionException("DELETE", "refresh", err); }); } } diff --git a/src/command/resetCommandHandler.ts b/src/command/resetCommandHandler.ts index 9c75aba..8c7d06e 100644 --- a/src/command/resetCommandHandler.ts +++ b/src/command/resetCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../data-source"; import { reset } from "../entity/reset"; +import DatabaseActionException from "../exceptions/databaseActionException"; import InternalException from "../exceptions/internalException"; import { StringHelper } from "../helpers/stringHelper"; import { CreateResetCommand, DeleteResetCommand } from "./resetCommand"; @@ -29,7 +30,7 @@ export default abstract class ResetCommandHandler { return token; }) .catch((err) => { - throw new InternalException("Failed saving reset", err); + throw new DatabaseActionException("CREATE", "reset", err); }); } @@ -48,7 +49,7 @@ export default abstract class ResetCommandHandler { .execute() .then((res) => {}) .catch((err) => { - throw new InternalException("failed reset removal", err); + throw new DatabaseActionException("DELETE", "reset", err); }); } } diff --git a/src/command/settings/award/awardCommandHandler.ts b/src/command/settings/award/awardCommandHandler.ts index 2a525a9..bad5746 100644 --- a/src/command/settings/award/awardCommandHandler.ts +++ b/src/command/settings/award/awardCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { award } from "../../../entity/settings/award"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateAwardCommand, DeleteAwardCommand, UpdateAwardCommand } from "./awardCommand"; @@ -22,7 +23,7 @@ export default abstract class AwardCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating award", err); + throw new DatabaseActionException("CREATE", "award", err); }); } @@ -42,7 +43,7 @@ export default abstract class AwardCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating award", err); + throw new DatabaseActionException("UPDATE", "award", err); }); } @@ -60,10 +61,7 @@ export default abstract class AwardCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException( - `Failed deleting award ${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`, - err - ); + throw new DatabaseActionException("DELETE", "award", err); }); } } diff --git a/src/command/settings/calendarType/calendarTypeCommandHandler.ts b/src/command/settings/calendarType/calendarTypeCommandHandler.ts index 702728d..7de554c 100644 --- a/src/command/settings/calendarType/calendarTypeCommandHandler.ts +++ b/src/command/settings/calendarType/calendarTypeCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { calendarType } from "../../../entity/settings/calendarType"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateCalendarTypeCommand, DeleteCalendarTypeCommand, UpdateCalendarTypeCommand } from "./calendarTypeCommand"; @@ -25,7 +26,7 @@ export default abstract class CalendarTypeCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating calendarType", err); + throw new DatabaseActionException("CREATE", "calendarType", err); }); } @@ -48,7 +49,7 @@ export default abstract class CalendarTypeCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating award", err); + throw new DatabaseActionException("UPDATE", "calenarType", err); }); } @@ -66,10 +67,7 @@ export default abstract class CalendarTypeCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException( - `Failed deleting calendarType${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`, - err - ); + throw new DatabaseActionException("DELETE", "calendarType", err); }); } } diff --git a/src/command/settings/communicationType/communicationTypeCommandHandler.ts b/src/command/settings/communicationType/communicationTypeCommandHandler.ts index df11e20..f05b0ff 100644 --- a/src/command/settings/communicationType/communicationTypeCommandHandler.ts +++ b/src/command/settings/communicationType/communicationTypeCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { communicationType } from "../../../entity/settings/communicationType"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateCommunicationTypeCommand, @@ -27,7 +28,7 @@ export default abstract class CommunicationTypeCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating communicationType", err); + throw new DatabaseActionException("CREATE", "communicationType", err); }); } @@ -48,7 +49,7 @@ export default abstract class CommunicationTypeCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating communicationType", err); + throw new DatabaseActionException("UPDATE", "communicationType", err); }); } @@ -66,12 +67,7 @@ export default abstract class CommunicationTypeCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException( - `Failed deleting communicationType${ - err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : "" - }`, - err - ); + throw new DatabaseActionException("DELETE", "communicationType", err); }); } } diff --git a/src/command/settings/executivePosition/executivePositionCommandHandler.ts b/src/command/settings/executivePosition/executivePositionCommandHandler.ts index 14a31a5..d2fb77e 100644 --- a/src/command/settings/executivePosition/executivePositionCommandHandler.ts +++ b/src/command/settings/executivePosition/executivePositionCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { executivePosition } from "../../../entity/settings/executivePosition"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateExecutivePositionCommand, @@ -26,7 +27,7 @@ export default abstract class ExecutivePositionCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating executivePosition", err); + throw new DatabaseActionException("DELETE", "executivePosition", err); }); } @@ -46,7 +47,7 @@ export default abstract class ExecutivePositionCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating executivePosition", err); + throw new DatabaseActionException("UPDATE", "executivePosition", err); }); } @@ -64,12 +65,7 @@ export default abstract class ExecutivePositionCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException( - `Failed deleting executivePosition${ - err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : "" - }`, - err - ); + throw new DatabaseActionException("DELETE", "executivePosition", err); }); } } diff --git a/src/command/settings/membershipStatus/membershipStatusCommandHandler.ts b/src/command/settings/membershipStatus/membershipStatusCommandHandler.ts index 7e5e953..e1cff7f 100644 --- a/src/command/settings/membershipStatus/membershipStatusCommandHandler.ts +++ b/src/command/settings/membershipStatus/membershipStatusCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { membershipStatus } from "../../../entity/settings/membershipStatus"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateMembershipStatusCommand, @@ -26,7 +27,7 @@ export default abstract class MembershipStatusCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating membershipStatus", err); + throw new DatabaseActionException("CREATING", "membershipStatus", err); }); } @@ -46,7 +47,7 @@ export default abstract class MembershipStatusCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating membershipStatus", err); + throw new DatabaseActionException("UPDATE", "membershipStatus", err); }); } @@ -64,12 +65,7 @@ export default abstract class MembershipStatusCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException( - `Failed deleting membershipStatus${ - err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : "" - }`, - err - ); + throw new DatabaseActionException("DELETE", "membershipStatus", err); }); } } diff --git a/src/command/settings/newsletterConfig/newsletterConfigCommandHandler.ts b/src/command/settings/newsletterConfig/newsletterConfigCommandHandler.ts index 4f26df4..98d8e02 100644 --- a/src/command/settings/newsletterConfig/newsletterConfigCommandHandler.ts +++ b/src/command/settings/newsletterConfig/newsletterConfigCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { newsletterConfig } from "../../../entity/settings/newsletterConfig"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { SetNewsletterConfigCommand } from "./newsletterConfigCommand"; @@ -24,7 +25,7 @@ export default abstract class NewsletterConfigCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed setting newsletterConfig", err); + throw new DatabaseActionException("SET", "newsletterConfig", err); }); } } diff --git a/src/command/settings/qualification/qualificationCommandHandler.ts b/src/command/settings/qualification/qualificationCommandHandler.ts index b0b9f22..31480f2 100644 --- a/src/command/settings/qualification/qualificationCommandHandler.ts +++ b/src/command/settings/qualification/qualificationCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { qualification } from "../../../entity/settings/qualification"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateQualificationCommand, @@ -27,7 +28,7 @@ export default abstract class QualificationCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating qualification", err); + throw new DatabaseActionException("CREATE", "qualification", err); }); } @@ -48,7 +49,7 @@ export default abstract class QualificationCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating qualification", err); + throw new DatabaseActionException("UPDATE", "qualification", err); }); } @@ -66,10 +67,7 @@ export default abstract class QualificationCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException( - `Failed deleting qualification${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`, - err - ); + throw new DatabaseActionException("DELETE", "qualification", err); }); } } diff --git a/src/command/settings/queryStore/queryStoreCommandHandler.ts b/src/command/settings/queryStore/queryStoreCommandHandler.ts index e8c6917..c33cadc 100644 --- a/src/command/settings/queryStore/queryStoreCommandHandler.ts +++ b/src/command/settings/queryStore/queryStoreCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { query } from "../../../entity/settings/query"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateQueryStoreCommand, DeleteQueryStoreCommand, UpdateQueryStoreCommand } from "./queryStoreCommand"; @@ -24,7 +25,7 @@ export default abstract class QueryStoreCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating queryStore", err); + throw new DatabaseActionException("CREATE", "queryStore", err); }); } @@ -45,7 +46,7 @@ export default abstract class QueryStoreCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating queryStore", err); + throw new DatabaseActionException("UPDATE", "queryStore", err); }); } @@ -63,10 +64,7 @@ export default abstract class QueryStoreCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException( - `Failed deleting queryStore${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`, - err - ); + throw new DatabaseActionException("DELETE", "queryStore", err); }); } } diff --git a/src/command/settings/salutation/salutationCommandHandler.ts b/src/command/settings/salutation/salutationCommandHandler.ts index 78f7c69..70b24c2 100644 --- a/src/command/settings/salutation/salutationCommandHandler.ts +++ b/src/command/settings/salutation/salutationCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { salutation } from "../../../entity/settings/salutation"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateSalutationCommand, DeleteSalutationCommand, UpdateSalutationCommand } from "./salutationCommand"; @@ -22,7 +23,7 @@ export default abstract class SalutationCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating salutation", err); + throw new DatabaseActionException("CREATE", "salutation", err); }); } @@ -42,7 +43,7 @@ export default abstract class SalutationCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating salutation", err); + throw new DatabaseActionException("UPDATE", "salutation", err); }); } @@ -60,10 +61,7 @@ export default abstract class SalutationCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException( - `Failed deleting salutation ${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`, - err - ); + throw new DatabaseActionException("DELETE", "salutation", err); }); } } diff --git a/src/command/settings/template/templateCommandHandler.ts b/src/command/settings/template/templateCommandHandler.ts index 6a88353..ebb2df7 100644 --- a/src/command/settings/template/templateCommandHandler.ts +++ b/src/command/settings/template/templateCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { template } from "../../../entity/settings/template"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateTemplateCommand, DeleteTemplateCommand, UpdateTemplateCommand } from "./templateCommand"; @@ -23,7 +24,7 @@ export default abstract class TemplateCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating template", err); + throw new DatabaseActionException("CREATE", "template", err); }); } @@ -46,7 +47,7 @@ export default abstract class TemplateCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating template", err); + throw new DatabaseActionException("UPDATE", "template", err); }); } @@ -64,10 +65,7 @@ export default abstract class TemplateCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException( - `Failed deleting template${err.code.includes("ER_ROW_IS_REFERENCED") ? " due to referenced data" : ""}`, - err - ); + throw new DatabaseActionException("DELETE", "template", err); }); } } diff --git a/src/command/settings/templateUsage/templateUsageCommandHandler.ts b/src/command/settings/templateUsage/templateUsageCommandHandler.ts index 06c46c9..dc75944 100644 --- a/src/command/settings/templateUsage/templateUsageCommandHandler.ts +++ b/src/command/settings/templateUsage/templateUsageCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { templateUsage } from "../../../entity/settings/templateUsage"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { UpdateTemplateUsageCommand } from "./templateUsageCommand"; @@ -24,7 +25,7 @@ export default abstract class TemplateUsageCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating templateUsage", err); + throw new DatabaseActionException("SET", "templateUsage", err); }); } } diff --git a/src/command/user/role/roleCommandHandler.ts b/src/command/user/role/roleCommandHandler.ts index 739d8b9..40f9a8f 100644 --- a/src/command/user/role/roleCommandHandler.ts +++ b/src/command/user/role/roleCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { role } from "../../../entity/user/role"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateRoleCommand, DeleteRoleCommand, UpdateRoleCommand } from "./roleCommand"; @@ -22,7 +23,7 @@ export default abstract class RoleCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed creating role", err); + throw new DatabaseActionException("CREATE", "role", err); }); } @@ -42,7 +43,7 @@ export default abstract class RoleCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating role", err); + throw new DatabaseActionException("UPDATE", "role", err); }); } @@ -60,7 +61,7 @@ export default abstract class RoleCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed deleting role", err); + throw new DatabaseActionException("DELETE", "role", err); }); } } diff --git a/src/command/user/role/rolePermissionCommandHandler.ts b/src/command/user/role/rolePermissionCommandHandler.ts index a9a0b1f..21a98d4 100644 --- a/src/command/user/role/rolePermissionCommandHandler.ts +++ b/src/command/user/role/rolePermissionCommandHandler.ts @@ -11,6 +11,7 @@ import { import PermissionHelper from "../../../helpers/permissionHelper"; import RolePermissionService from "../../../service/user/rolePermissionService"; import { PermissionString } from "../../../type/permissionTypes"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; export default abstract class RolePermissionCommandHandler { /** @@ -35,7 +36,7 @@ export default abstract class RolePermissionCommandHandler { }) .then(() => {}) .catch((err) => { - throw new InternalException("Failed saving role permissions", err); + throw new DatabaseActionException("UPDATE", "rolePermissions", err); }); } @@ -71,46 +72,4 @@ export default abstract class RolePermissionCommandHandler { .andWhere("permission IN (:...permission)", { permission: permissions }) .execute(); } - - /** - * @description grant permission to user - * @param {CreateRolePermissionCommand} createPermission - * @returns {Promise} - */ - static async create(createPermission: CreateRolePermissionCommand): Promise { - return await dataSource - .createQueryBuilder() - .insert() - .into(rolePermission) - .values({ - permission: createPermission.permission, - role: await RoleService.getById(createPermission.roleId), - }) - .execute() - .then((result) => { - return result.identifiers[0].id; - }) - .catch((err) => { - throw new InternalException("Failed saving role permission", err); - }); - } - - /** - * @description remove permission from role - * @param {DeleteRolePermissionCommand} deletePermission - * @returns {Promise} - */ - static async delete(deletePermission: DeleteRolePermissionCommand): Promise { - return await dataSource - .createQueryBuilder() - .delete() - .from(rolePermission) - .where("roleId = :id", { id: deletePermission.roleId }) - .andWhere("permission = :permission", { permission: deletePermission.permission }) - .execute() - .then(() => {}) - .catch((err) => { - throw new InternalException("failed role permission removal", err); - }); - } } diff --git a/src/command/user/user/inviteCommandHandler.ts b/src/command/user/user/inviteCommandHandler.ts index 61c6149..fd760d4 100644 --- a/src/command/user/user/inviteCommandHandler.ts +++ b/src/command/user/user/inviteCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { invite } from "../../../entity/user/invite"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { StringHelper } from "../../../helpers/stringHelper"; import { CreateInviteCommand, DeleteInviteCommand } from "./inviteCommand"; @@ -31,7 +32,7 @@ export default abstract class InviteCommandHandler { return token; }) .catch((err) => { - throw new InternalException("Failed saving invite", err); + throw new DatabaseActionException("CREATE", "invite", err); }); } @@ -50,7 +51,7 @@ export default abstract class InviteCommandHandler { .execute() .then((res) => {}) .catch((err) => { - throw new InternalException("failed invite removal", err); + throw new DatabaseActionException("DELETE", "invite", err); }); } @@ -68,7 +69,7 @@ export default abstract class InviteCommandHandler { .execute() .then((res) => {}) .catch((err) => { - throw new InternalException("failed invite removal", err); + throw new DatabaseActionException("DELETE", "invite", err); }); } } diff --git a/src/command/user/user/userCommandHandler.ts b/src/command/user/user/userCommandHandler.ts index 50afb2a..0f1102a 100644 --- a/src/command/user/user/userCommandHandler.ts +++ b/src/command/user/user/userCommandHandler.ts @@ -11,6 +11,7 @@ import { UpdateUserSecretCommand, } from "./userCommand"; import UserService from "../../../service/user/userService"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; export default abstract class UserCommandHandler { /** @@ -36,7 +37,7 @@ export default abstract class UserCommandHandler { return result.identifiers[0].id; }) .catch((err) => { - throw new InternalException("Failed saving user", err); + throw new DatabaseActionException("CREATE", "user", err); }); } @@ -59,7 +60,7 @@ export default abstract class UserCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating user", err); + throw new DatabaseActionException("UPDATE", "user", err); }); } @@ -79,7 +80,7 @@ export default abstract class UserCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed updating user secret", err); + throw new DatabaseActionException("UPDATE", "user", err); }); } @@ -105,7 +106,7 @@ export default abstract class UserCommandHandler { }) .then(() => {}) .catch((err) => { - throw new InternalException("Failed saving user roles", err); + throw new DatabaseActionException("UPDATE", "userRoles", err); }); } @@ -145,7 +146,7 @@ export default abstract class UserCommandHandler { }) .then(() => {}) .catch((err) => { - throw new InternalException("Failed transfering ownership", err); + throw new DatabaseActionException("ABORT", "transfer owner", err); }); } @@ -163,7 +164,7 @@ export default abstract class UserCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed deleting user", err); + throw new DatabaseActionException("DELETE", "user", err); }); } } diff --git a/src/command/user/user/userPermissionCommandHandler.ts b/src/command/user/user/userPermissionCommandHandler.ts index bd6ffc3..77694f3 100644 --- a/src/command/user/user/userPermissionCommandHandler.ts +++ b/src/command/user/user/userPermissionCommandHandler.ts @@ -11,6 +11,7 @@ import { import UserPermissionService from "../../../service/user/userPermissionService"; import PermissionHelper from "../../../helpers/permissionHelper"; import { PermissionString } from "../../../type/permissionTypes"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; export default abstract class UserPermissionCommandHandler { /** @@ -36,7 +37,7 @@ export default abstract class UserPermissionCommandHandler { }) .then(() => {}) .catch((err) => { - throw new InternalException("Failed saving user permissions", err); + throw new DatabaseActionException("UPDATE", "userPermissions", err); }); } @@ -72,46 +73,4 @@ export default abstract class UserPermissionCommandHandler { .andWhere("permission IN (:...permission)", { permission: permissions }) .execute(); } - - /** - * @description grant permission to user - * @param {CreateUserPermissionCommand} createPermission - * @returns {Promise} - */ - static async create(createPermission: CreateUserPermissionCommand): Promise { - return await dataSource - .createQueryBuilder() - .insert() - .into(userPermission) - .values({ - permission: createPermission.permission, - userId: createPermission.userId, - }) - .execute() - .then((result) => { - return result.identifiers[0].id; - }) - .catch((err) => { - throw new InternalException("Failed saving user permission", err); - }); - } - - /** - * @description remove permission to user - * @param {DeleteUserPermissionCommand} deletePermission - * @returns {Promise} - */ - static async delete(deletePermission: DeleteUserPermissionCommand): Promise { - return await dataSource - .createQueryBuilder() - .delete() - .from(userPermission) - .where("userId = :id", { id: deletePermission.userId }) - .andWhere("permission = :permission", { permission: deletePermission.permission }) - .execute() - .then((res) => {}) - .catch((err) => { - throw new InternalException("failed user permission removal", err); - }); - } } diff --git a/src/command/user/webapi/webapiCommandHandler.ts b/src/command/user/webapi/webapiCommandHandler.ts index b49f7a6..ea12d98 100644 --- a/src/command/user/webapi/webapiCommandHandler.ts +++ b/src/command/user/webapi/webapiCommandHandler.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { webapi } from "../../../entity/user/webapi"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { CreateWebapiCommand, @@ -29,10 +30,7 @@ export default abstract class WebapiCommandHandler { return result.identifiers[0].token; }) .catch((err) => { - throw new InternalException( - `Failed creating api${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`, - err - ); + throw new DatabaseActionException("CREATE", "webapi", err); }); } @@ -53,10 +51,7 @@ export default abstract class WebapiCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException( - `Failed updating api${err.code.includes("ER_DUP_ENTRY") ? " due to duplicate entry for column" : ""}`, - err - ); + throw new DatabaseActionException("UPDATE", "webapi", err); }); } @@ -76,7 +71,7 @@ export default abstract class WebapiCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException(`Failed updating api last usage`, err); + throw new DatabaseActionException("UPDATE", "webapi", err); }); } @@ -94,7 +89,7 @@ export default abstract class WebapiCommandHandler { .execute() .then(() => {}) .catch((err) => { - throw new InternalException("Failed deleting api", err); + throw new DatabaseActionException("DELETE", "webapi", err); }); } } diff --git a/src/command/user/webapi/webapiPermissionCommandHandler.ts b/src/command/user/webapi/webapiPermissionCommandHandler.ts index 74ea514..ec661f4 100644 --- a/src/command/user/webapi/webapiPermissionCommandHandler.ts +++ b/src/command/user/webapi/webapiPermissionCommandHandler.ts @@ -11,6 +11,7 @@ import { import PermissionHelper from "../../../helpers/permissionHelper"; import WebapiPermissionService from "../../../service/user/webapiPermissionService"; import { PermissionString } from "../../../type/permissionTypes"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; export default abstract class WebapiPermissionCommandHandler { /** @@ -38,7 +39,7 @@ export default abstract class WebapiPermissionCommandHandler { }) .then(() => {}) .catch((err) => { - throw new InternalException("Failed saving api permissions", err); + throw new DatabaseActionException("UPDATE", "webapiPermission", err); }); } @@ -74,46 +75,4 @@ export default abstract class WebapiPermissionCommandHandler { .andWhere("permission IN (:...permission)", { permission: permissions }) .execute(); } - - /** - * @description grant permission to user - * @param {CreateWebapiPermissionCommand} createPermission - * @returns {Promise} - */ - static async create(createPermission: CreateWebapiPermissionCommand): Promise { - return await dataSource - .createQueryBuilder() - .insert() - .into(webapiPermission) - .values({ - permission: createPermission.permission, - webapiId: createPermission.webapiId, - }) - .execute() - .then((result) => { - return result.identifiers[0].id; - }) - .catch((err) => { - throw new InternalException("Failed saving api permission", err); - }); - } - - /** - * @description remove permission from api - * @param {DeleteWebapiPermissionCommand} deletePermission - * @returns {Promise} - */ - static async delete(deletePermission: DeleteWebapiPermissionCommand): Promise { - return await dataSource - .createQueryBuilder() - .delete() - .from(webapiPermission) - .where("webapiId = :id", { id: deletePermission.webapiId }) - .andWhere("permission = :permission", { permission: deletePermission.permission }) - .execute() - .then(() => {}) - .catch((err) => { - throw new InternalException("failed api permission removal", err); - }); - } } diff --git a/src/exceptions/databaseActionException.ts b/src/exceptions/databaseActionException.ts new file mode 100644 index 0000000..b0b145c --- /dev/null +++ b/src/exceptions/databaseActionException.ts @@ -0,0 +1,8 @@ +import CustomRequestException from "./customRequestException"; + +export default class DatabaseActionException extends CustomRequestException { + constructor(action: string, table: string, err: any) { + let errstring = `${action} on ${table} with ${err?.code ?? "XX"} at ${err?.sqlMessage ?? "XX"}`; + super(500, errstring, err); + } +} diff --git a/src/service/club/calendarService.ts b/src/service/club/calendarService.ts index e1186a1..7e8f86b 100644 --- a/src/service/club/calendarService.ts +++ b/src/service/club/calendarService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../data-source"; import { calendar } from "../../entity/club/calendar"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class CalendarService { @@ -18,7 +19,7 @@ export default abstract class CalendarService { return res; }) .catch((err) => { - throw new InternalException("calendars not found", err); + throw new DatabaseActionException("SELECT", "calendar", err); }); } @@ -37,7 +38,7 @@ export default abstract class CalendarService { return res; }) .catch((err) => { - throw new InternalException("calendar not found by id", err); + throw new DatabaseActionException("SELECT", "calendar", err); }); } @@ -62,7 +63,7 @@ export default abstract class CalendarService { return res; }) .catch((err) => { - throw new InternalException("calendars not found by types", err); + throw new DatabaseActionException("SELECT", "calendar", err); }); } @@ -81,7 +82,7 @@ export default abstract class CalendarService { return res; }) .catch((err) => { - throw new InternalException("calendars not found by type nscdr", err); + throw new DatabaseActionException("SELECT", "calendar", err); }); } } diff --git a/src/service/club/member/communicationService.ts b/src/service/club/member/communicationService.ts index 2a016d7..8a33b41 100644 --- a/src/service/club/member/communicationService.ts +++ b/src/service/club/member/communicationService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { communication } from "../../../entity/club/member/communication"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; export default abstract class CommunicationService { @@ -21,7 +22,7 @@ export default abstract class CommunicationService { return res; }) .catch((err) => { - throw new InternalException("member communications not found", err); + throw new DatabaseActionException("SELECT", "memberCommunications", err); }); } @@ -44,7 +45,7 @@ export default abstract class CommunicationService { return res; }) .catch((err) => { - throw new InternalException("member communication not found by id", err); + throw new DatabaseActionException("SELECT", "memberCommunication", err); }); } diff --git a/src/service/club/member/memberAwardService.ts b/src/service/club/member/memberAwardService.ts index 8e3aa8e..45e71c0 100644 --- a/src/service/club/member/memberAwardService.ts +++ b/src/service/club/member/memberAwardService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { memberAwards } from "../../../entity/club/member/memberAwards"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; export default abstract class MemberAwardService { @@ -20,7 +21,7 @@ export default abstract class MemberAwardService { return res; }) .catch((err) => { - throw new InternalException("member awards not found", err); + throw new DatabaseActionException("SELECT", "memberAwards", err); }); } @@ -42,7 +43,7 @@ export default abstract class MemberAwardService { return res; }) .catch((err) => { - throw new InternalException("member award not found by id", err); + throw new DatabaseActionException("SELECT", "memberAwards", err); }); } } diff --git a/src/service/club/member/memberExecutivePositionService.ts b/src/service/club/member/memberExecutivePositionService.ts index 93d76eb..f853b50 100644 --- a/src/service/club/member/memberExecutivePositionService.ts +++ b/src/service/club/member/memberExecutivePositionService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { memberExecutivePositions } from "../../../entity/club/member/memberExecutivePositions"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; export default abstract class MemberExecutivePositionService { @@ -21,7 +22,7 @@ export default abstract class MemberExecutivePositionService { return res; }) .catch((err) => { - throw new InternalException("member executivePositions not found", err); + throw new DatabaseActionException("SELECT", "memberExecutivePositions", err); }); } @@ -45,7 +46,7 @@ export default abstract class MemberExecutivePositionService { return res; }) .catch((err) => { - throw new InternalException("member executivePosition not found by id", err); + throw new DatabaseActionException("SELECT", "memberExecutivePositions", err); }); } } diff --git a/src/service/club/member/memberQualificationService.ts b/src/service/club/member/memberQualificationService.ts index afd3ee5..5a2e11c 100644 --- a/src/service/club/member/memberQualificationService.ts +++ b/src/service/club/member/memberQualificationService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { memberQualifications } from "../../../entity/club/member/memberQualifications"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; export default abstract class MemberQualificationService { @@ -20,7 +21,7 @@ export default abstract class MemberQualificationService { return res; }) .catch((err) => { - throw new InternalException("member qualifications not found", err); + throw new DatabaseActionException("SELECT", "memberQualifications", err); }); } @@ -42,7 +43,7 @@ export default abstract class MemberQualificationService { return res; }) .catch((err) => { - throw new InternalException("member qualification not found by id", err); + throw new DatabaseActionException("SELECT", "memberQualifications", err); }); } } diff --git a/src/service/club/member/memberService.ts b/src/service/club/member/memberService.ts index 5ec6d09..f970a9f 100644 --- a/src/service/club/member/memberService.ts +++ b/src/service/club/member/memberService.ts @@ -1,6 +1,8 @@ +import { SelectQueryBuilder } from "typeorm"; import { dataSource } from "../../../data-source"; import { member } from "../../../entity/club/member/member"; import { membership } from "../../../entity/club/member/membership"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { memberView } from "../../../views/memberView"; @@ -22,40 +24,7 @@ export default abstract class MemberService { noLimit?: boolean; ids?: Array; }): Promise<[Array, number]> { - let query = dataSource - .getRepository(member) - .createQueryBuilder("member") - .leftJoinAndMapOne( - "member.firstMembershipEntry", - "member.memberships", - "membership_first", - "membership_first.memberId = member.id AND membership_first.start = (SELECT MIN(m.start) FROM membership m WHERE m.memberId = member.id)" - ) - .leftJoinAndMapOne( - "member.lastMembershipEntry", - "member.memberships", - "membership_last", - "membership_last.memberId = member.id AND membership_last.start = (SELECT MAX(m.start) FROM membership m WHERE m.memberId = member.id)" - ) - .leftJoinAndSelect("membership_first.status", "status_first") - .leftJoinAndSelect("membership_last.status", "status_last") - .leftJoinAndMapMany( - "member.preferredCommunication", - "member.communications", - "preferredCommunication", - "preferredCommunication.preferred = 1" - ) - .leftJoinAndSelect("preferredCommunication.type", "communicationtype_preferred") - .leftJoinAndMapOne( - "member.sendNewsletter", - "member.communications", - "sendNewsletter", - "sendNewsletter.isSendNewsletter = 1" - ) - .leftJoinAndSelect("sendNewsletter.type", "communicationtype") - .leftJoinAndMapMany("member.smsAlarming", "member.communications", "smsAlarming", "smsAlarming.isSMSAlarming = 1") - .leftJoinAndSelect("smsAlarming.type", "communicationtype_smsAlarming") - .leftJoinAndSelect("member.salutation", "salutation"); + let query = this.applyMemberBaseJoins(); if (search != "") { search.split(" ").forEach((term, index) => { @@ -90,7 +59,7 @@ export default abstract class MemberService { return res; }) .catch((err) => { - throw new InternalException("members not found", err); + throw new DatabaseActionException("SELECT", "member", err); }); } @@ -100,7 +69,89 @@ export default abstract class MemberService { * @returns {Promise} */ static async getById(id: string): Promise { + return this.applyMemberBaseJoins() + .where("member.id = :id", { id: id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "member", err); + }); + } + + /** + * @description get member statistics by id + * @param {string} id + * @returns {Promise} + */ + static async getStatisticsById(id: string): Promise { return await dataSource + .getRepository(memberView) + .createQueryBuilder("memberView") + .where("memberView.id = :id", { id: id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "memberView", err); + }); + } + + /** + * @description get members where membership is setz + * @returns {Promise} + */ + static async getByRunningMembership(): Promise> { + return await dataSource + .getRepository(member) + .createQueryBuilder("member") + .leftJoinAndSelect("member.memberships", "membership") + .where("membership.end IS NULL") + .orderBy("member.lastname") + .addOrderBy("member.firstname") + .addOrderBy("member.nameaffix") + .getMany() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "member", err); + }); + } + + /** + * @description get newsletter by member by id + * @param {string} id + * @returns {Promise} + */ + static async getNewsletterById(id: string): Promise { + return await dataSource + .getRepository(member) + .createQueryBuilder("member") + .leftJoinAndMapOne( + "member.sendNewsletter", + "member.communications", + "sendNewsletter", + "sendNewsletter.isSendNewsletter = 1" + ) + .where("member.id = :id", { id: id }) + .getOneOrFail() + .then((res) => { + return res; + }) + .catch((err) => { + throw new DatabaseActionException("SELECT", "member", err); + }); + } + + /** + * @description apply member joins to query + * @returns {SelectQueryBuilder} + */ + static applyMemberBaseJoins(): SelectQueryBuilder { + return dataSource .getRepository(member) .createQueryBuilder("member") .leftJoinAndMapOne( @@ -133,80 +184,6 @@ export default abstract class MemberService { .leftJoinAndSelect("sendNewsletter.type", "communicationtype") .leftJoinAndMapMany("member.smsAlarming", "member.communications", "smsAlarming", "smsAlarming.isSMSAlarming = 1") .leftJoinAndSelect("smsAlarming.type", "communicationtype_smsAlarming") - .leftJoinAndSelect("member.salutation", "salutation") - .where("member.id = :id", { id: id }) - .getOneOrFail() - .then((res) => { - return res; - }) - .catch((err) => { - throw new InternalException("member not found by id", err); - }); - } - - /** - * @description get member statistics by id - * @param {string} id - * @returns {Promise} - */ - static async getStatisticsById(id: string): Promise { - return await dataSource - .getRepository(memberView) - .createQueryBuilder("memberView") - .where("memberView.id = :id", { id: id }) - .getOneOrFail() - .then((res) => { - return res; - }) - .catch((err) => { - throw new InternalException("memberView not found by id", err); - }); - } - - /** - * @description get members where membership is setz - * @returns {Promise} - */ - static async getByRunningMembership(): Promise> { - return await dataSource - .getRepository(member) - .createQueryBuilder("member") - .leftJoinAndSelect("member.memberships", "membership") - .where("membership.end IS NULL") - .orderBy("member.lastname") - .addOrderBy("member.firstname") - .addOrderBy("member.nameaffix") - .getMany() - .then((res) => { - return res; - }) - .catch((err) => { - throw new InternalException("member not found by id", err); - }); - } - - /** - * @description get newsletter by member by id - * @param {string} id - * @returns {Promise} - */ - static async getNewsletterById(id: string): Promise { - return await dataSource - .getRepository(member) - .createQueryBuilder("member") - .leftJoinAndMapOne( - "member.sendNewsletter", - "member.communications", - "sendNewsletter", - "sendNewsletter.isSendNewsletter = 1" - ) - .where("member.id = :id", { id: id }) - .getOneOrFail() - .then((res) => { - return res; - }) - .catch((err) => { - throw new InternalException("member not found by id", err); - }); + .leftJoinAndSelect("member.salutation", "salutation"); } } diff --git a/src/service/club/member/membershipService.ts b/src/service/club/member/membershipService.ts index 5067e81..f5e7a07 100644 --- a/src/service/club/member/membershipService.ts +++ b/src/service/club/member/membershipService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { membership } from "../../../entity/club/member/membership"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; import { membershipView } from "../../../views/membershipsView"; @@ -21,7 +22,7 @@ export default abstract class MembershipService { return res; }) .catch((err) => { - throw new InternalException("member memberships not found", err); + throw new DatabaseActionException("SELECT", "membershis", err); }); } @@ -43,7 +44,7 @@ export default abstract class MembershipService { return res; }) .catch((err) => { - throw new InternalException("member membership not found by id", err); + throw new DatabaseActionException("SELECT", "membership", err); }); } @@ -62,7 +63,7 @@ export default abstract class MembershipService { return res; }) .catch((err) => { - throw new InternalException("membershipView not found by id", err); + throw new DatabaseActionException("SELECT", "membershipView", err); }); } } diff --git a/src/service/club/newsletter/newsletterDatesService.ts b/src/service/club/newsletter/newsletterDatesService.ts index 10c4e7a..55264c1 100644 --- a/src/service/club/newsletter/newsletterDatesService.ts +++ b/src/service/club/newsletter/newsletterDatesService.ts @@ -2,6 +2,7 @@ import { dataSource } from "../../../data-source"; import { newsletterDates } from "../../../entity/club/newsletter/newsletterDates"; import { member } from "../../../entity/club/member/member"; import InternalException from "../../../exceptions/internalException"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; export default abstract class NewsletterDatesService { /** @@ -21,7 +22,7 @@ export default abstract class NewsletterDatesService { return res; }) .catch((err) => { - throw new InternalException("newsletterDatess not found", err); + throw new DatabaseActionException("SELECT", "newsletterDates", err); }); } } diff --git a/src/service/club/newsletter/newsletterRecipientsService.ts b/src/service/club/newsletter/newsletterRecipientsService.ts index fe570de..28bed59 100644 --- a/src/service/club/newsletter/newsletterRecipientsService.ts +++ b/src/service/club/newsletter/newsletterRecipientsService.ts @@ -2,6 +2,7 @@ import { dataSource } from "../../../data-source"; import { newsletterRecipients } from "../../../entity/club/newsletter/newsletterRecipients"; import { member } from "../../../entity/club/member/member"; import InternalException from "../../../exceptions/internalException"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; export default abstract class NewsletterRecipientsService { /** @@ -22,7 +23,7 @@ export default abstract class NewsletterRecipientsService { return res; }) .catch((err) => { - throw new InternalException("newsletterRecipients not found", err); + throw new DatabaseActionException("SELECT", "newsletterRecipient", err); }); } } diff --git a/src/service/club/newsletter/newsletterService.ts b/src/service/club/newsletter/newsletterService.ts index 24c2a3f..27489d0 100644 --- a/src/service/club/newsletter/newsletterService.ts +++ b/src/service/club/newsletter/newsletterService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { newsletter } from "../../../entity/club/newsletter/newsletter"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; export default abstract class NewsletterService { @@ -18,7 +19,7 @@ export default abstract class NewsletterService { return res; }) .catch((err) => { - throw new InternalException("newsletters not found", err); + throw new DatabaseActionException("SELECT", "newsletter", err); }); } @@ -37,7 +38,7 @@ export default abstract class NewsletterService { return res; }) .catch((err) => { - throw new InternalException("newsletter not found by id", err); + throw new DatabaseActionException("SELECT", "newsletter", err); }); } } diff --git a/src/service/club/protocol/protocolAgendaService.ts b/src/service/club/protocol/protocolAgendaService.ts index c0899bd..fb8ead8 100644 --- a/src/service/club/protocol/protocolAgendaService.ts +++ b/src/service/club/protocol/protocolAgendaService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { protocolAgenda } from "../../../entity/club/protocol/protocolAgenda"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; export default abstract class ProtocolAgendaService { @@ -17,7 +18,7 @@ export default abstract class ProtocolAgendaService { return res; }) .catch((err) => { - throw new InternalException("protocolAgendas not found", err); + throw new DatabaseActionException("SELECT", "protocolAgenda", err); }); } @@ -35,7 +36,7 @@ export default abstract class ProtocolAgendaService { return res; }) .catch((err) => { - throw new InternalException("protocolAgenda not found by id", err); + throw new DatabaseActionException("SELECT", "protocolAgenda", err); }); } } diff --git a/src/service/club/protocol/protocolDecisionService.ts b/src/service/club/protocol/protocolDecisionService.ts index 62dd672..56ac4c6 100644 --- a/src/service/club/protocol/protocolDecisionService.ts +++ b/src/service/club/protocol/protocolDecisionService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { protocolDecision } from "../../../entity/club/protocol/protocolDecision"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; export default abstract class ProtocolDecisionService { @@ -17,7 +18,7 @@ export default abstract class ProtocolDecisionService { return res; }) .catch((err) => { - throw new InternalException("protocolDecisions not found", err); + throw new DatabaseActionException("SELECT", "protocolDecision", err); }); } @@ -35,7 +36,7 @@ export default abstract class ProtocolDecisionService { return res; }) .catch((err) => { - throw new InternalException("protocolDecision not found by id", err); + throw new DatabaseActionException("SELECT", "protocolDecision", err); }); } } diff --git a/src/service/club/protocol/protocolPrecenseService.ts b/src/service/club/protocol/protocolPrecenseService.ts index ac3a82f..306031c 100644 --- a/src/service/club/protocol/protocolPrecenseService.ts +++ b/src/service/club/protocol/protocolPrecenseService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { protocolPresence } from "../../../entity/club/protocol/protocolPresence"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; export default abstract class ProtocolPresenceService { @@ -18,7 +19,7 @@ export default abstract class ProtocolPresenceService { return res; }) .catch((err) => { - throw new InternalException("protocolPresence not found", err); + throw new DatabaseActionException("SELECT", "protocolPresence", err); }); } } diff --git a/src/service/club/protocol/protocolPrintoutService.ts b/src/service/club/protocol/protocolPrintoutService.ts index a1815fb..ec4600c 100644 --- a/src/service/club/protocol/protocolPrintoutService.ts +++ b/src/service/club/protocol/protocolPrintoutService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { protocolPrintout } from "../../../entity/club/protocol/protocolPrintout"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; export default abstract class ProtocolPrintoutService { @@ -17,7 +18,7 @@ export default abstract class ProtocolPrintoutService { return res; }) .catch((err) => { - throw new InternalException("protocolPrintouts not found", err); + throw new DatabaseActionException("SELECT", "protocolPrintout", err); }); } @@ -36,7 +37,7 @@ export default abstract class ProtocolPrintoutService { return res; }) .catch((err) => { - throw new InternalException("protocolPrintout not found by id", err); + throw new DatabaseActionException("SELECT", "protocolPrintout", err); }); } @@ -54,7 +55,7 @@ export default abstract class ProtocolPrintoutService { return res; }) .catch((err) => { - throw new InternalException("protocolPrintout not found by id", err); + throw new DatabaseActionException("SELECT", "protocolPrintout", err); }); } } diff --git a/src/service/club/protocol/protocolService.ts b/src/service/club/protocol/protocolService.ts index 12526fe..185d76a 100644 --- a/src/service/club/protocol/protocolService.ts +++ b/src/service/club/protocol/protocolService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { protocol } from "../../../entity/club/protocol/protocol"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; export default abstract class ProtocolService { @@ -19,7 +20,7 @@ export default abstract class ProtocolService { return res; }) .catch((err) => { - throw new InternalException("protocols not found", err); + throw new DatabaseActionException("SELECT", "protocol", err); }); } diff --git a/src/service/club/protocol/protocolVotingService.ts b/src/service/club/protocol/protocolVotingService.ts index cc7c5f6..2000cce 100644 --- a/src/service/club/protocol/protocolVotingService.ts +++ b/src/service/club/protocol/protocolVotingService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../../data-source"; import { protocolVoting } from "../../../entity/club/protocol/protocolVoting"; +import DatabaseActionException from "../../../exceptions/databaseActionException"; import InternalException from "../../../exceptions/internalException"; export default abstract class ProtocolVotingService { @@ -17,7 +18,7 @@ export default abstract class ProtocolVotingService { return res; }) .catch((err) => { - throw new InternalException("protocolVotings not found", err); + throw new DatabaseActionException("SELECT", "protocolVoting", err); }); } @@ -35,7 +36,7 @@ export default abstract class ProtocolVotingService { return res; }) .catch((err) => { - throw new InternalException("protocolVoting not found by id", err); + throw new DatabaseActionException("SELECT", "protocolVoting", err); }); } } diff --git a/src/service/resetService.ts b/src/service/resetService.ts index 802548e..71a3c99 100644 --- a/src/service/resetService.ts +++ b/src/service/resetService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../data-source"; import { reset } from "../entity/reset"; +import DatabaseActionException from "../exceptions/databaseActionException"; import InternalException from "../exceptions/internalException"; export default abstract class ResetService { @@ -20,7 +21,7 @@ export default abstract class ResetService { return res; }) .catch((err) => { - throw new InternalException("reset not found by mail and token", err); + throw new DatabaseActionException("SELECT", "reset", err); }); } } diff --git a/src/service/settings/awardService.ts b/src/service/settings/awardService.ts index 57872da..cdf95d8 100644 --- a/src/service/settings/awardService.ts +++ b/src/service/settings/awardService.ts @@ -2,6 +2,7 @@ import { dataSource } from "../../data-source"; import { award } from "../../entity/settings/award"; import { member } from "../../entity/club/member/member"; import InternalException from "../../exceptions/internalException"; +import DatabaseActionException from "../../exceptions/databaseActionException"; export default abstract class AwardService { /** @@ -18,7 +19,7 @@ export default abstract class AwardService { return res; }) .catch((err) => { - throw new InternalException("awards not found", err); + throw new DatabaseActionException("SELECT", "award", err); }); } @@ -36,7 +37,7 @@ export default abstract class AwardService { return res; }) .catch((err) => { - throw new InternalException("award not found by id", err); + throw new DatabaseActionException("SELECT", "award", err); }); } } diff --git a/src/service/settings/calendarTypeService.ts b/src/service/settings/calendarTypeService.ts index 1fb3f34..74be65f 100644 --- a/src/service/settings/calendarTypeService.ts +++ b/src/service/settings/calendarTypeService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../data-source"; import { calendarType } from "../../entity/settings/calendarType"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class CalendarTypeService { @@ -17,7 +18,7 @@ export default abstract class CalendarTypeService { return res; }) .catch((err) => { - throw new InternalException("calendarTypes not found", err); + throw new DatabaseActionException("SELECT", "calendarType", err); }); } @@ -35,7 +36,7 @@ export default abstract class CalendarTypeService { return res; }) .catch((err) => { - throw new InternalException("calendarType not found by id", err); + throw new DatabaseActionException("SELECT", "calendarType", err); }); } @@ -53,7 +54,7 @@ export default abstract class CalendarTypeService { return res; }) .catch((err) => { - throw new InternalException("calendarTypes not found by names", err); + throw new DatabaseActionException("SELECT", "calendarType", err); }); } } diff --git a/src/service/settings/communicationTypeService.ts b/src/service/settings/communicationTypeService.ts index 74494b1..fa71786 100644 --- a/src/service/settings/communicationTypeService.ts +++ b/src/service/settings/communicationTypeService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../data-source"; import { communicationType } from "../../entity/settings/communicationType"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class CommunicationTypeService { @@ -17,7 +18,7 @@ export default abstract class CommunicationTypeService { return res; }) .catch((err) => { - throw new InternalException("communicationTypes not found", err); + throw new DatabaseActionException("SELECT", "communicationType", err); }); } @@ -35,7 +36,7 @@ export default abstract class CommunicationTypeService { return res; }) .catch((err) => { - throw new InternalException("communicationType not found by id", err); + throw new DatabaseActionException("SELECT", "communicationType", err); }); } } diff --git a/src/service/settings/executivePositionService.ts b/src/service/settings/executivePositionService.ts index cf2b105..ef161d3 100644 --- a/src/service/settings/executivePositionService.ts +++ b/src/service/settings/executivePositionService.ts @@ -2,6 +2,7 @@ import { dataSource } from "../../data-source"; import { executivePosition } from "../../entity/settings/executivePosition"; import { memberExecutivePositions } from "../../entity/club/member/memberExecutivePositions"; import InternalException from "../../exceptions/internalException"; +import DatabaseActionException from "../../exceptions/databaseActionException"; export default abstract class ExecutivePositionService { /** @@ -18,7 +19,7 @@ export default abstract class ExecutivePositionService { return res; }) .catch((err) => { - throw new InternalException("executivePositions not found", err); + throw new DatabaseActionException("SELECT", "executivePosition", err); }); } @@ -36,7 +37,7 @@ export default abstract class ExecutivePositionService { return res; }) .catch((err) => { - throw new InternalException("executivePosition not found by id", err); + throw new DatabaseActionException("SELECT", "executivePosition", err); }); } } diff --git a/src/service/settings/membershipStatusService.ts b/src/service/settings/membershipStatusService.ts index b1e94f1..317f788 100644 --- a/src/service/settings/membershipStatusService.ts +++ b/src/service/settings/membershipStatusService.ts @@ -2,6 +2,7 @@ import { dataSource } from "../../data-source"; import { membershipStatus } from "../../entity/settings/membershipStatus"; import InternalException from "../../exceptions/internalException"; import { membership } from "../../entity/club/member/membership"; +import DatabaseActionException from "../../exceptions/databaseActionException"; export default abstract class MembershipStatusService { /** @@ -18,7 +19,7 @@ export default abstract class MembershipStatusService { return res; }) .catch((err) => { - throw new InternalException("membershipStatuss not found", err); + throw new DatabaseActionException("SELECT", "membershipStatus", err); }); } @@ -36,7 +37,7 @@ export default abstract class MembershipStatusService { return res; }) .catch((err) => { - throw new InternalException("membershipStatus not found by id", err); + throw new DatabaseActionException("SELECT", "membershipStatus", err); }); } } diff --git a/src/service/settings/newsletterConfigService.ts b/src/service/settings/newsletterConfigService.ts index 984fbb2..104968b 100644 --- a/src/service/settings/newsletterConfigService.ts +++ b/src/service/settings/newsletterConfigService.ts @@ -2,6 +2,7 @@ import { dataSource } from "../../data-source"; import { newsletterConfig } from "../../entity/settings/newsletterConfig"; import { member } from "../../entity/club/member/member"; import InternalException from "../../exceptions/internalException"; +import DatabaseActionException from "../../exceptions/databaseActionException"; export default abstract class NewsletterConfigService { /** @@ -19,7 +20,7 @@ export default abstract class NewsletterConfigService { return res; }) .catch((err) => { - throw new InternalException("newsletterConfigs not found", err); + throw new DatabaseActionException("SELECT", "newsletterConfig", err); }); } @@ -38,7 +39,7 @@ export default abstract class NewsletterConfigService { return res; }) .catch((err) => { - throw new InternalException("newsletterConfig not found by cmId", err); + throw new DatabaseActionException("SELECT", "newsletterConfig", err); }); } } diff --git a/src/service/settings/qualification.ts b/src/service/settings/qualification.ts index f400576..2d232d7 100644 --- a/src/service/settings/qualification.ts +++ b/src/service/settings/qualification.ts @@ -2,6 +2,7 @@ import { dataSource } from "../../data-source"; import { memberQualifications } from "../../entity/club/member/memberQualifications"; import { qualification } from "../../entity/settings/qualification"; import { user } from "../../entity/user/user"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class QualificationService { @@ -19,7 +20,7 @@ export default abstract class QualificationService { return res; }) .catch((err) => { - throw new InternalException("qualifications not found", err); + throw new DatabaseActionException("SELECT", "qualification", err); }); } @@ -37,7 +38,7 @@ export default abstract class QualificationService { return res; }) .catch((err) => { - throw new InternalException("qualification not found by id", err); + throw new DatabaseActionException("SELECT", "qualification", err); }); } } diff --git a/src/service/settings/queryStoreService.ts b/src/service/settings/queryStoreService.ts index 8ad5a52..5a4edcb 100644 --- a/src/service/settings/queryStoreService.ts +++ b/src/service/settings/queryStoreService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../data-source"; import { query } from "../../entity/settings/query"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class QueryStoreService { @@ -17,7 +18,7 @@ export default abstract class QueryStoreService { return res; }) .catch((err) => { - throw new InternalException("queryStores not found", err); + throw new DatabaseActionException("SELECT", "queryStore", err); }); } @@ -35,7 +36,7 @@ export default abstract class QueryStoreService { return res; }) .catch((err) => { - throw new InternalException("queryStore not found by id", err); + throw new DatabaseActionException("SELECT", "queryStore", err); }); } } diff --git a/src/service/settings/salutationService.ts b/src/service/settings/salutationService.ts index 70a6b4f..2337748 100644 --- a/src/service/settings/salutationService.ts +++ b/src/service/settings/salutationService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../data-source"; import { salutation } from "../../entity/settings/salutation"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class SalutationService { @@ -17,7 +18,7 @@ export default abstract class SalutationService { return res; }) .catch((err) => { - throw new InternalException("salutations not found", err); + throw new DatabaseActionException("SELECT", "salutation", err); }); } @@ -35,7 +36,7 @@ export default abstract class SalutationService { return res; }) .catch((err) => { - throw new InternalException("salutation not found by id", err); + throw new DatabaseActionException("SELECT", "salutation", err); }); } } diff --git a/src/service/settings/templateService.ts b/src/service/settings/templateService.ts index fb073f8..e605ab9 100644 --- a/src/service/settings/templateService.ts +++ b/src/service/settings/templateService.ts @@ -2,6 +2,7 @@ import { dataSource } from "../../data-source"; import { template } from "../../entity/settings/template"; import { member } from "../../entity/club/member/member"; import InternalException from "../../exceptions/internalException"; +import DatabaseActionException from "../../exceptions/databaseActionException"; export default abstract class TemplateService { /** @@ -18,7 +19,7 @@ export default abstract class TemplateService { return res; }) .catch((err) => { - throw new InternalException("templates not found", err); + throw new DatabaseActionException("SELECT", "template", err); }); } @@ -36,7 +37,7 @@ export default abstract class TemplateService { return res; }) .catch((err) => { - throw new InternalException("template not found by id", err); + throw new DatabaseActionException("SELECT", "template", err); }); } } diff --git a/src/service/settings/templateUsageService.ts b/src/service/settings/templateUsageService.ts index a782d7b..cfa1d25 100644 --- a/src/service/settings/templateUsageService.ts +++ b/src/service/settings/templateUsageService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../data-source"; import { templateUsage } from "../../entity/settings/templateUsage"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class TemplateUsageService { @@ -20,7 +21,7 @@ export default abstract class TemplateUsageService { return res; }) .catch((err) => { - throw new InternalException("templates not found", err); + throw new DatabaseActionException("SELECT", "templateUsage", err); }); } diff --git a/src/service/user/inviteService.ts b/src/service/user/inviteService.ts index 6b2a701..b2cd07a 100644 --- a/src/service/user/inviteService.ts +++ b/src/service/user/inviteService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../data-source"; import { invite } from "../../entity/user/invite"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class InviteService { @@ -16,7 +17,7 @@ export default abstract class InviteService { return res; }) .catch((err) => { - throw new InternalException("invites not found", err); + throw new DatabaseActionException("SELECT", "invite", err); }); } @@ -37,7 +38,7 @@ export default abstract class InviteService { return res; }) .catch((err) => { - throw new InternalException("invite not found by mail and token", err); + throw new DatabaseActionException("SELECT", "invite", err); }); } } diff --git a/src/service/user/rolePermissionService.ts b/src/service/user/rolePermissionService.ts index e40930f..1cfe6f2 100644 --- a/src/service/user/rolePermissionService.ts +++ b/src/service/user/rolePermissionService.ts @@ -1,6 +1,7 @@ import { dataSource } from "../../data-source"; import { rolePermission } from "../../entity/user/role_permission"; import { userPermission } from "../../entity/user/user_permission"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class RolePermissionService { @@ -19,7 +20,7 @@ export default abstract class RolePermissionService { return res; }) .catch((err) => { - throw new InternalException("permissions not found by role", err); + throw new DatabaseActionException("SELECT", "rolePermission", err); }); } @@ -38,7 +39,7 @@ export default abstract class RolePermissionService { return res; }) .catch((err) => { - throw new InternalException("permissions not found by roles", err); + throw new DatabaseActionException("SELECT", "rolePermission", err); }); } } diff --git a/src/service/user/roleService.ts b/src/service/user/roleService.ts index 042c001..7601063 100644 --- a/src/service/user/roleService.ts +++ b/src/service/user/roleService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../data-source"; import { role } from "../../entity/user/role"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class RoleService { @@ -18,7 +19,7 @@ export default abstract class RoleService { return res; }) .catch((err) => { - throw new InternalException("roles not found", err); + throw new DatabaseActionException("SELECT", "roles", err); }); } @@ -38,7 +39,7 @@ export default abstract class RoleService { return res; }) .catch((err) => { - throw new InternalException("role not found by id", err); + throw new DatabaseActionException("SELECT", "role", err); }); } } diff --git a/src/service/user/userPermissionService.ts b/src/service/user/userPermissionService.ts index 0078ee3..7cb3ee6 100644 --- a/src/service/user/userPermissionService.ts +++ b/src/service/user/userPermissionService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../data-source"; import { userPermission } from "../../entity/user/user_permission"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class UserPermissionService { @@ -18,7 +19,7 @@ export default abstract class UserPermissionService { return res; }) .catch((err) => { - throw new InternalException("permission not found by user", err); + throw new DatabaseActionException("SELECT", "userPermission", err); }); } } diff --git a/src/service/user/userService.ts b/src/service/user/userService.ts index b75d499..2abb7f7 100644 --- a/src/service/user/userService.ts +++ b/src/service/user/userService.ts @@ -1,6 +1,7 @@ import { dataSource } from "../../data-source"; import { role } from "../../entity/user/role"; import { user } from "../../entity/user/user"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class UserService { @@ -22,7 +23,7 @@ export default abstract class UserService { return res; }) .catch((err) => { - throw new InternalException("users not found", err); + throw new DatabaseActionException("SELECT", "user", err); }); } @@ -44,7 +45,7 @@ export default abstract class UserService { return res; }) .catch((err) => { - throw new InternalException("user not found by id", err); + throw new DatabaseActionException("SELECT", "user", err); }); } @@ -64,7 +65,7 @@ export default abstract class UserService { return res; }) .catch((err) => { - throw new InternalException("user not found by username", err); + throw new DatabaseActionException("SELECT", "user", err); }); } @@ -86,7 +87,7 @@ export default abstract class UserService { return res; }) .catch((err) => { - throw new InternalException("user not found by mail or username", err); + throw new DatabaseActionException("SELECT", "user", err); }); } @@ -104,7 +105,7 @@ export default abstract class UserService { return res; }) .catch((err) => { - throw new InternalException("could not count users", err); + throw new DatabaseActionException("COUNT", "users", err); }); } @@ -125,7 +126,7 @@ export default abstract class UserService { return res.roles; }) .catch((err) => { - throw new InternalException("could not get roles for user", err); + throw new DatabaseActionException("SELECT", "userRoles", err); }); } } diff --git a/src/service/user/webapiPermissionService.ts b/src/service/user/webapiPermissionService.ts index a210353..ab57582 100644 --- a/src/service/user/webapiPermissionService.ts +++ b/src/service/user/webapiPermissionService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../data-source"; import { webapiPermission } from "../../entity/user/webapi_permission"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class WebapiPermissionService { @@ -18,7 +19,7 @@ export default abstract class WebapiPermissionService { return res; }) .catch((err) => { - throw new InternalException("webapi permissions not found by api", err); + throw new DatabaseActionException("SELECT", "webapiPermission", err); }); } } diff --git a/src/service/user/webapiService.ts b/src/service/user/webapiService.ts index 0faa51a..571a013 100644 --- a/src/service/user/webapiService.ts +++ b/src/service/user/webapiService.ts @@ -1,5 +1,6 @@ import { dataSource } from "../../data-source"; import { webapi } from "../../entity/user/webapi"; +import DatabaseActionException from "../../exceptions/databaseActionException"; import InternalException from "../../exceptions/internalException"; export default abstract class WebapiService { @@ -17,7 +18,7 @@ export default abstract class WebapiService { return res; }) .catch((err) => { - throw new InternalException("webapis not found", err); + throw new DatabaseActionException("SELECT", "webapi", err); }); } @@ -37,7 +38,7 @@ export default abstract class WebapiService { return res; }) .catch((err) => { - throw new InternalException("webapi not found by id", err); + throw new DatabaseActionException("SELECT", "webapi", err); }); } @@ -57,7 +58,7 @@ export default abstract class WebapiService { return res; }) .catch((err) => { - throw new InternalException("webapi not found by token", err); + throw new DatabaseActionException("SELECT", "webapi", err); }); } @@ -77,7 +78,7 @@ export default abstract class WebapiService { return res; }) .catch((err) => { - throw new InternalException("webapi token not found by id", err); + throw new DatabaseActionException("SELECT", "webapi", err); }); } }