Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Implements getNotificationByNameAndType #3669

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion services/api/src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const {
deleteNotificationWebhook,
getNotificationsByProjectId,
getNotificationsByOrganizationId,
getNotificationByNameAndType,
removeNotificationFromProject,
updateNotificationMicrosoftTeams,
updateNotificationRocketChat,
Expand Down Expand Up @@ -595,7 +596,8 @@ const resolvers = {
getGroupProjectOrganizationAssociation,
getProjectGroupOrganizationAssociation,
getEnvVariablesByProjectEnvironmentName,
checkBulkImportProjectsAndGroupsToOrganization
checkBulkImportProjectsAndGroupsToOrganization,
notificationByNameAndType: getNotificationByNameAndType
},
Mutation: {
addProblem,
Expand Down
23 changes: 23 additions & 0 deletions services/api/src/resources/notification/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,3 +705,26 @@ export const removeAllNotificationsFromAllProjects: ResolverFn = async (
// TODO: Check rows for success
return 'success';
};

export const getNotificationByNameAndType: ResolverFn = async (
root,
args,
{ sqlClientPool, hasPermission }
) => {

const { name: notificationName, type: notificationType } = args;

const row = await query(sqlClientPool, Sql.selectNotificationByNameAndType(notificationName, notificationType));
let notification = row[0];

if (!notification) {
throw new Error(`No notification found for ${notificationName}`)
}

notification.type = notificationType;

await hasPermission('notification', 'view', {
notification: notification.id,
});
return notification;
};
11 changes: 10 additions & 1 deletion services/api/src/resources/notification/sql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,5 +227,14 @@ export const Sql = {
truncateProjectNotification: () =>
knex('project_notification')
.truncate()
.toString()
.toString(),
selectNotificationByNameAndType: (name: string, type: string) =>
knex(`notification_${type}`)
.where('name', '=', name)
.toString(),
selectProjectNotificationByNameAndType: (name: string, type: string) =>
knex(`notification_${type}`)
.join('project_notification', `notification_${type}.id`, '=', 'project_notification.nid' )
.where('name', '=', name)
.toString(),
};
4 changes: 4 additions & 0 deletions services/api/src/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,10 @@ const typeDefs = gql`
deployTargetConfigsByDeployTarget(deployTarget: Int!) : [DeployTargetConfig] @deprecated(reason: "Unstable API, subject to breaking changes in any release. Use at your own risk")
allDeployTargetConfigs: [DeployTargetConfig] @deprecated(reason: "Unstable API, subject to breaking changes in any release. Use at your own risk")
"""
Get a notification by its name and type
"""
notificationByNameAndType(name: String, type: NotificationType) : Notification
"""
List all organizations
"""
allOrganizations: [Organization] @deprecated(reason: "Unstable API, subject to breaking changes in any release. Use at your own risk")
Expand Down