feat: add notification UI
showPopup was also refactored to be better
This commit is contained in:
@ -269,6 +269,7 @@ func (r *mutationResolver) AssignTask(ctx context.Context, input *AssignTaskInpu
|
||||
if err != nil {
|
||||
return &db.Task{}, err
|
||||
}
|
||||
// r.NotificationQueue.TaskMemberWasAdded(assignedTask.TaskID, userID, assignedTask.UserID)
|
||||
task, err := r.Repository.GetTaskByID(ctx, input.TaskID)
|
||||
return &task, err
|
||||
}
|
||||
@ -720,6 +721,61 @@ func (r *mutationResolver) UpdateUserRole(ctx context.Context, input UpdateUserR
|
||||
return &UpdateUserRolePayload{User: &user}, nil
|
||||
}
|
||||
|
||||
func (r *notificationResolver) ID(ctx context.Context, obj *db.Notification) (uuid.UUID, error) {
|
||||
return obj.NotificationID, nil
|
||||
}
|
||||
|
||||
func (r *notificationResolver) Entity(ctx context.Context, obj *db.Notification) (*NotificationEntity, error) {
|
||||
log.WithFields(log.Fields{"notificationID": obj.NotificationID}).Info("fetching entity for notification")
|
||||
entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID)
|
||||
log.WithFields(log.Fields{"entityID": entity.EntityID}).Info("fetched entity")
|
||||
if err != nil {
|
||||
return &NotificationEntity{}, err
|
||||
}
|
||||
entityType := GetEntityType(entity.EntityType)
|
||||
switch entityType {
|
||||
case EntityTypeTask:
|
||||
task, err := r.Repository.GetTaskByID(ctx, entity.EntityID)
|
||||
if err != nil {
|
||||
return &NotificationEntity{}, err
|
||||
}
|
||||
return &NotificationEntity{Type: entityType, ID: entity.EntityID, Name: task.Name}, err
|
||||
|
||||
default:
|
||||
panic(fmt.Errorf("not implemented"))
|
||||
}
|
||||
}
|
||||
|
||||
func (r *notificationResolver) ActionType(ctx context.Context, obj *db.Notification) (ActionType, error) {
|
||||
entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID)
|
||||
if err != nil {
|
||||
return ActionTypeTaskMemberAdded, err
|
||||
}
|
||||
actionType := GetActionType(entity.ActionType)
|
||||
return actionType, nil
|
||||
}
|
||||
|
||||
func (r *notificationResolver) Actor(ctx context.Context, obj *db.Notification) (*NotificationActor, error) {
|
||||
entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID)
|
||||
if err != nil {
|
||||
return &NotificationActor{}, err
|
||||
}
|
||||
log.WithFields(log.Fields{"entityID": entity.ActorID}).Info("fetching actor")
|
||||
user, err := r.Repository.GetUserAccountByID(ctx, entity.ActorID)
|
||||
if err != nil {
|
||||
return &NotificationActor{}, err
|
||||
}
|
||||
return &NotificationActor{ID: entity.ActorID, Name: user.FullName, Type: ActorTypeUser}, nil
|
||||
}
|
||||
|
||||
func (r *notificationResolver) CreatedAt(ctx context.Context, obj *db.Notification) (*time.Time, error) {
|
||||
entity, err := r.Repository.GetEntityForNotificationID(ctx, obj.NotificationID)
|
||||
if err != nil {
|
||||
return &time.Time{}, err
|
||||
}
|
||||
return &entity.CreatedOn, nil
|
||||
}
|
||||
|
||||
func (r *organizationResolver) ID(ctx context.Context, obj *db.Organization) (uuid.UUID, error) {
|
||||
return obj.OrganizationID, nil
|
||||
}
|
||||
@ -1011,6 +1067,21 @@ func (r *queryResolver) Me(ctx context.Context) (*MePayload, error) {
|
||||
return &MePayload{User: &user, TeamRoles: teamRoles, ProjectRoles: projectRoles}, err
|
||||
}
|
||||
|
||||
func (r *queryResolver) Notifications(ctx context.Context) ([]db.Notification, error) {
|
||||
userID, ok := GetUserID(ctx)
|
||||
log.WithFields(log.Fields{"userID": userID}).Info("fetching notifications")
|
||||
if !ok {
|
||||
return []db.Notification{}, errors.New("user id is missing")
|
||||
}
|
||||
notifications, err := r.Repository.GetAllNotificationsForUserID(ctx, userID)
|
||||
if err == sql.ErrNoRows {
|
||||
return []db.Notification{}, nil
|
||||
} else if err != nil {
|
||||
return []db.Notification{}, err
|
||||
}
|
||||
return notifications, nil
|
||||
}
|
||||
|
||||
func (r *refreshTokenResolver) ID(ctx context.Context, obj *db.RefreshToken) (uuid.UUID, error) {
|
||||
return obj.TokenID, nil
|
||||
}
|
||||
@ -1268,6 +1339,9 @@ func (r *Resolver) LabelColor() LabelColorResolver { return &labelColorResolver{
|
||||
// Mutation returns MutationResolver implementation.
|
||||
func (r *Resolver) Mutation() MutationResolver { return &mutationResolver{r} }
|
||||
|
||||
// Notification returns NotificationResolver implementation.
|
||||
func (r *Resolver) Notification() NotificationResolver { return ¬ificationResolver{r} }
|
||||
|
||||
// Organization returns OrganizationResolver implementation.
|
||||
func (r *Resolver) Organization() OrganizationResolver { return &organizationResolver{r} }
|
||||
|
||||
@ -1308,6 +1382,7 @@ func (r *Resolver) UserAccount() UserAccountResolver { return &userAccountResolv
|
||||
|
||||
type labelColorResolver struct{ *Resolver }
|
||||
type mutationResolver struct{ *Resolver }
|
||||
type notificationResolver struct{ *Resolver }
|
||||
type organizationResolver struct{ *Resolver }
|
||||
type projectResolver struct{ *Resolver }
|
||||
type projectLabelResolver struct{ *Resolver }
|
||||
|
Reference in New Issue
Block a user