Add application workflow and lead analytics
This commit is contained in:
@@ -12,8 +12,14 @@ import (
|
||||
|
||||
"adam-french.co.uk/job-tracker/internal/graph/model"
|
||||
"adam-french.co.uk/job-tracker/internal/models"
|
||||
"adam-french.co.uk/job-tracker/internal/services"
|
||||
)
|
||||
|
||||
// Events is the resolver for the events field.
|
||||
func (r *jobApplicationResolver) Events(ctx context.Context, obj *models.JobApplication) ([]*models.JobApplicationEvent, error) {
|
||||
return services.ListApplicationEvents(r.Store.DB, obj.ID)
|
||||
}
|
||||
|
||||
// CreateJobApplication is the resolver for the createJobApplication field.
|
||||
func (r *mutationResolver) CreateJobApplication(ctx context.Context, input model.CreateJobApplicationInput) (*models.JobApplication, error) {
|
||||
// String! is non-null but not non-empty, and the columns are only
|
||||
@@ -36,10 +42,19 @@ func (r *mutationResolver) CreateJobApplication(ctx context.Context, input model
|
||||
Notes: input.Notes,
|
||||
AppliedAt: input.AppliedAt,
|
||||
Description: input.Description,
|
||||
NextAction: input.NextAction, NextActionAt: input.NextActionAt,
|
||||
ContactName: input.ContactName, ContactEmail: input.ContactEmail,
|
||||
ContactRole: input.ContactRole, LastContactedAt: input.LastContactedAt,
|
||||
SalaryRange: input.SalaryRange, WorkArrangement: input.WorkArrangement,
|
||||
ApplicationSource: input.ApplicationSource, ResumeVersion: input.ResumeVersion,
|
||||
RequisitionID: input.RequisitionID,
|
||||
}
|
||||
if err := r.Store.DB.Create(&app).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := services.RecordApplicationEvent(r.Store.DB, app.ID, services.ApplicationEventInput{Kind: "created", Source: "graphql"}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &app, nil
|
||||
}
|
||||
|
||||
@@ -54,6 +69,7 @@ func (r *mutationResolver) UpdateJobApplication(ctx context.Context, id int, inp
|
||||
if err := r.Store.DB.First(&app, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
oldStatus := app.Status
|
||||
if input.JobTitle != nil {
|
||||
if strings.TrimSpace(*input.JobTitle) == "" {
|
||||
return nil, fmt.Errorf("jobTitle cannot be empty")
|
||||
@@ -84,9 +100,53 @@ func (r *mutationResolver) UpdateJobApplication(ctx context.Context, id int, inp
|
||||
if input.Description != nil {
|
||||
app.Description = input.Description
|
||||
}
|
||||
if input.NextAction != nil {
|
||||
app.NextAction = input.NextAction
|
||||
}
|
||||
if input.NextActionAt != nil {
|
||||
app.NextActionAt = input.NextActionAt
|
||||
}
|
||||
if input.ClearNextActionAt != nil && *input.ClearNextActionAt {
|
||||
app.NextActionAt = nil
|
||||
}
|
||||
if input.ContactName != nil {
|
||||
app.ContactName = input.ContactName
|
||||
}
|
||||
if input.ContactEmail != nil {
|
||||
app.ContactEmail = input.ContactEmail
|
||||
}
|
||||
if input.ContactRole != nil {
|
||||
app.ContactRole = input.ContactRole
|
||||
}
|
||||
if input.SalaryRange != nil {
|
||||
app.SalaryRange = input.SalaryRange
|
||||
}
|
||||
if input.WorkArrangement != nil {
|
||||
app.WorkArrangement = input.WorkArrangement
|
||||
}
|
||||
if input.ApplicationSource != nil {
|
||||
app.ApplicationSource = input.ApplicationSource
|
||||
}
|
||||
if input.ResumeVersion != nil {
|
||||
app.ResumeVersion = input.ResumeVersion
|
||||
}
|
||||
if input.RequisitionID != nil {
|
||||
app.RequisitionID = input.RequisitionID
|
||||
}
|
||||
if input.LastContactedAt != nil {
|
||||
app.LastContactedAt = input.LastContactedAt
|
||||
}
|
||||
if err := r.Store.DB.Save(&app).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := services.RecordApplicationEvent(r.Store.DB, app.ID, services.ApplicationEventInput{Kind: "updated", Source: "graphql"}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if oldStatus != app.Status {
|
||||
if _, err := services.RecordApplicationEvent(r.Store.DB, app.ID, services.ApplicationEventInput{Kind: "status_changed", Source: "graphql", Note: stringPtr(oldStatus + " -> " + app.Status)}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &app, nil
|
||||
}
|
||||
|
||||
@@ -109,6 +169,19 @@ func (r *mutationResolver) DeleteJobApplication(ctx context.Context, id int) (bo
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// AddJobApplicationEvent appends a user-entered follow-up or contact event.
|
||||
func (r *mutationResolver) AddJobApplicationEvent(ctx context.Context, applicationID int, input model.AddJobApplicationEventInput) (*models.JobApplicationEvent, error) {
|
||||
var app models.JobApplication
|
||||
if err := r.Store.DB.First(&app, applicationID).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return services.RecordApplicationEvent(r.Store.DB, uint(applicationID), services.ApplicationEventInput{
|
||||
Kind: input.Kind, OccurredAt: timeValue(input.OccurredAt), Note: input.Note,
|
||||
Source: stringValue(input.Source), ContactName: input.ContactName,
|
||||
ContactEmail: input.ContactEmail, ContactRole: input.ContactRole,
|
||||
})
|
||||
}
|
||||
|
||||
// JobApplications is the resolver for the jobApplications field.
|
||||
func (r *queryResolver) JobApplications(ctx context.Context) ([]*models.JobApplication, error) {
|
||||
// Admin-only even though it is a query (@admin in the schema): job
|
||||
@@ -137,3 +210,36 @@ func (r *queryResolver) JobApplication(ctx context.Context, id int) (*models.Job
|
||||
}
|
||||
return &app, nil
|
||||
}
|
||||
|
||||
// JobApplicationEvents is the explicit activity-history query for clients that
|
||||
// do not need the rest of the application object.
|
||||
func (r *queryResolver) JobApplicationEvents(ctx context.Context, applicationID int) ([]*models.JobApplicationEvent, error) {
|
||||
return services.ListApplicationEvents(r.Store.DB, uint(applicationID))
|
||||
}
|
||||
|
||||
// Analytics is calculated from the same application and activity history used
|
||||
// by the tracker, so the dashboard does not maintain a second data model.
|
||||
func (r *queryResolver) Analytics(ctx context.Context) (*model.Analytics, error) {
|
||||
stats, err := services.LoadAnalytics(r.Store.DB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := &model.Analytics{
|
||||
TotalApplications: stats.TotalApplications, ResponseCount: stats.ResponseCount,
|
||||
InterviewCount: stats.InterviewCount, OfferCount: stats.OfferCount,
|
||||
ResponseRate: stats.ResponseRate, InterviewRate: stats.InterviewRate, OfferRate: stats.OfferRate,
|
||||
AverageDaysToResponse: stats.AverageDaysToResponse, AverageDaysToInterview: stats.AverageDaysToInterview, AverageDaysToOffer: stats.AverageDaysToOffer,
|
||||
}
|
||||
for _, item := range stats.StatusCounts {
|
||||
result.StatusCounts = append(result.StatusCounts, &model.AnalyticsStatusCount{Status: item.Status, Count: item.Count})
|
||||
}
|
||||
for _, item := range stats.Transitions {
|
||||
result.Transitions = append(result.Transitions, &model.AnalyticsTransition{From: item.From, To: item.To, Count: item.Count})
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// JobApplication returns JobApplicationResolver implementation.
|
||||
func (r *Resolver) JobApplication() JobApplicationResolver { return &jobApplicationResolver{r} }
|
||||
|
||||
type jobApplicationResolver struct{ *Resolver }
|
||||
|
||||
Reference in New Issue
Block a user