Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 authored and shreddedbacon committed Sep 9, 2024
1 parent e081316 commit b424758
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions services/api/src/resources/notification/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,10 @@ export const getAllNotifications: ResolverFn = async (
if (args.name && args.type) {
rows = await query(sqlClientPool, Sql.selectNotificationByNameAndType(args.name, args.type));

if (rows.length === 0) {
throw new Error(`No notification found for ${args.name} & ${args.type}`);
}

if (rows.length > 0) {
rows[0].type = args.type;
}
Expand All @@ -720,10 +724,10 @@ export const getAllNotifications: ResolverFn = async (
if (args.name) {
await hasPermission('notification', 'viewAll');

const rows = await Helpers(sqlClientPool).selectAllNotifications(args.name);
rows = await Helpers(sqlClientPool).selectAllNotifications(args.name);

if (rows.length === 0) {
throw new Error(`No notification found for ${args.name}`);
throw new Error(`No notifications found for ${args.name}`);
}

return rows;
Expand All @@ -732,12 +736,20 @@ export const getAllNotifications: ResolverFn = async (
if (args.type) {
await hasPermission('notification', 'viewAll');

const rows = await query(sqlClientPool, Sql.selectAllNotifications(args.type));
rows = await query(sqlClientPool, Sql.selectAllNotifications(args.type));

if (rows.length === 0) {
throw new Error(`No notifications found for type ${args.type}`);
}

return rows;
}

await hasPermission('notification', 'viewAll');
rows = await Helpers(sqlClientPool).selectAllNotifications();
if (rows.length === 0) {
throw new Error(`No notifications found`);
}

return rows;
};

0 comments on commit b424758

Please sign in to comment.