Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 committed Jun 14, 2024
1 parent 2cc3b66 commit 3dc5bcc
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 @@ -716,6 +716,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 @@ -730,10 +734,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 @@ -742,12 +746,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 3dc5bcc

Please sign in to comment.