diff --git a/backend/graph/generated/generated.go b/backend/graph/generated/generated.go index d5483b2..3bea1c4 100644 --- a/backend/graph/generated/generated.go +++ b/backend/graph/generated/generated.go @@ -52,7 +52,7 @@ type ComplexityRoot struct { } Query struct { - QueryCheckDistance func(childComplexity int, mStaffID string, mCompanyID string, mCompanyLatitude string, mCompanyLongitude string, currentLatitude string, currentLongitude string) int + QueryCheckDistance func(childComplexity int, mStaffID string, mCompanyID string, currentLatitude string, currentLongitude string) int SearchStaffByEmail func(childComplexity int, email string) int StaffGetByStaffID func(childComplexity int, staffID string) int StaffListBySearch func(childComplexity int, search *string, page *int, maxPerPage *int) int @@ -60,8 +60,6 @@ type ComplexityRoot struct { Staff struct { CompanyID func(childComplexity int) int - CompanyLatitude func(childComplexity int) int - CompanyLongitude func(childComplexity int) int CompanyName func(childComplexity int) int CreatedAt func(childComplexity int) int DisplayNameGoogleSignIn func(childComplexity int) int @@ -83,6 +81,15 @@ type ComplexityRoot struct { Token func(childComplexity int) int } + TransAbsensiCheckDistanceResponse struct { + CurrentDistance func(childComplexity int) int + MaxDistance func(childComplexity int) int + Message func(childComplexity int) int + Selfie func(childComplexity int) int + Status func(childComplexity int) int + Unit func(childComplexity int) int + } + TransAbsensiResponse struct { Message func(childComplexity int) int Status func(childComplexity int) int @@ -97,7 +104,7 @@ type QueryResolver interface { SearchStaffByEmail(ctx context.Context, email string) (*model.Staff, error) StaffGetByStaffID(ctx context.Context, staffID string) (*model.Staff, error) StaffListBySearch(ctx context.Context, search *string, page *int, maxPerPage *int) ([]*model.Staff, error) - QueryCheckDistance(ctx context.Context, mStaffID string, mCompanyID string, mCompanyLatitude string, mCompanyLongitude string, currentLatitude string, currentLongitude string) (*model.TransAbsensiResponse, error) + QueryCheckDistance(ctx context.Context, mStaffID string, mCompanyID string, currentLatitude string, currentLongitude string) (*model.TransAbsensiCheckDistanceResponse, error) } type executableSchema struct { @@ -153,7 +160,7 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return 0, false } - return e.complexity.Query.QueryCheckDistance(childComplexity, args["M_StaffID"].(string), args["M_CompanyID"].(string), args["M_CompanyLatitude"].(string), args["M_CompanyLongitude"].(string), args["CurrentLatitude"].(string), args["CurrentLongitude"].(string)), true + return e.complexity.Query.QueryCheckDistance(childComplexity, args["M_StaffID"].(string), args["M_CompanyID"].(string), args["CurrentLatitude"].(string), args["CurrentLongitude"].(string)), true case "Query.searchStaffByEmail": if e.complexity.Query.SearchStaffByEmail == nil { @@ -198,20 +205,6 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Staff.CompanyID(childComplexity), true - case "Staff.company_latitude": - if e.complexity.Staff.CompanyLatitude == nil { - break - } - - return e.complexity.Staff.CompanyLatitude(childComplexity), true - - case "Staff.company_longitude": - if e.complexity.Staff.CompanyLongitude == nil { - break - } - - return e.complexity.Staff.CompanyLongitude(childComplexity), true - case "Staff.company_name": if e.complexity.Staff.CompanyName == nil { break @@ -324,6 +317,48 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.TokenResponse.Token(childComplexity), true + case "TransAbsensiCheckDistanceResponse.current_distance": + if e.complexity.TransAbsensiCheckDistanceResponse.CurrentDistance == nil { + break + } + + return e.complexity.TransAbsensiCheckDistanceResponse.CurrentDistance(childComplexity), true + + case "TransAbsensiCheckDistanceResponse.max_distance": + if e.complexity.TransAbsensiCheckDistanceResponse.MaxDistance == nil { + break + } + + return e.complexity.TransAbsensiCheckDistanceResponse.MaxDistance(childComplexity), true + + case "TransAbsensiCheckDistanceResponse.message": + if e.complexity.TransAbsensiCheckDistanceResponse.Message == nil { + break + } + + return e.complexity.TransAbsensiCheckDistanceResponse.Message(childComplexity), true + + case "TransAbsensiCheckDistanceResponse.selfie": + if e.complexity.TransAbsensiCheckDistanceResponse.Selfie == nil { + break + } + + return e.complexity.TransAbsensiCheckDistanceResponse.Selfie(childComplexity), true + + case "TransAbsensiCheckDistanceResponse.status": + if e.complexity.TransAbsensiCheckDistanceResponse.Status == nil { + break + } + + return e.complexity.TransAbsensiCheckDistanceResponse.Status(childComplexity), true + + case "TransAbsensiCheckDistanceResponse.unit": + if e.complexity.TransAbsensiCheckDistanceResponse.Unit == nil { + break + } + + return e.complexity.TransAbsensiCheckDistanceResponse.Unit(childComplexity), true + case "TransAbsensiResponse.message": if e.complexity.TransAbsensiResponse.Message == nil { break @@ -445,23 +480,21 @@ var sources = []*ast.Source{ {Name: "../graphqls/schema.graphqls", Input: ``, BuiltIn: false}, {Name: "../graphqls/staff.graphqls", Input: `# model staff type Staff { - staff_id: ID! - nip: String! - name: String! - email: String! - phone_number: String - company_id: ID! - company_name: String - company_latitude:String - company_longitude:String - is_active: String - is_login: String - token: String - expired: String - id_google_sign_in: String! - display_name_google_sign_in: String - created_at: String - last_updated_at: String + staff_id: ID! + nip: String! + name: String! + email: String! + phone_number: String + company_id: ID! + company_name: String + is_active: String + is_login: String + token: String + expired: String + id_google_sign_in: String! + display_name_google_sign_in: String + created_at: String + last_updated_at: String } # model token response ketika login @@ -487,16 +520,26 @@ type TransAbsensiResponse { message: String } +# check distance response +type TransAbsensiCheckDistanceResponse { + status: String + message: String + selfie: String + max_distance: String + current_distance: String + unit: String +} + # query extend type Query { - # untuk cek distance dengan fungsi distance_v2 di database - queryCheckDistance(M_StaffID:String!, M_CompanyID:String!, M_CompanyLatitude:String!, M_CompanyLongitude:String!, CurrentLatitude:String!, CurrentLongitude:String!) : TransAbsensiResponse! + # untuk cek distance dengan fungsi distance_v2 di database + queryCheckDistance(M_StaffID:String!, M_CompanyID:String!,CurrentLatitude:String!, CurrentLongitude:String!) : TransAbsensiCheckDistanceResponse! } # mutation extend type Mutation { - # untuk clock in absensi (absensi masuk) - mutationClockInAttendance(T_TransactionM_AbsensiTypeID:String!, T_TransactionM_StaffID:String!, T_TransactionM_CompanyID:String!, T_TransactionCurrentLatitude:String!, T_TransactionCurrentLongitude:String!, T_TransactionDistance:String!, T_TransactionSelfiePhoto:String, T_TransactionNote:String):TransAbsensiResponse! + # untuk clock in absensi (absensi masuk) + mutationClockInAttendance(T_TransactionM_AbsensiTypeID:String!, T_TransactionM_StaffID:String!, T_TransactionM_CompanyID:String!, T_TransactionCurrentLatitude:String!, T_TransactionCurrentLongitude:String!, T_TransactionDistance:String!, T_TransactionSelfiePhoto:String, T_TransactionNote:String):TransAbsensiResponse! } `, BuiltIn: false}, } var parsedSchema = gqlparser.MustLoadSchema(sources...) @@ -644,41 +687,23 @@ func (ec *executionContext) field_Query_queryCheckDistance_args(ctx context.Cont } args["M_CompanyID"] = arg1 var arg2 string - if tmp, ok := rawArgs["M_CompanyLatitude"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("M_CompanyLatitude")) + if tmp, ok := rawArgs["CurrentLatitude"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("CurrentLatitude")) arg2, err = ec.unmarshalNString2string(ctx, tmp) if err != nil { return nil, err } } - args["M_CompanyLatitude"] = arg2 + args["CurrentLatitude"] = arg2 var arg3 string - if tmp, ok := rawArgs["M_CompanyLongitude"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("M_CompanyLongitude")) + if tmp, ok := rawArgs["CurrentLongitude"]; ok { + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("CurrentLongitude")) arg3, err = ec.unmarshalNString2string(ctx, tmp) if err != nil { return nil, err } } - args["M_CompanyLongitude"] = arg3 - var arg4 string - if tmp, ok := rawArgs["CurrentLatitude"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("CurrentLatitude")) - arg4, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } - } - args["CurrentLatitude"] = arg4 - var arg5 string - if tmp, ok := rawArgs["CurrentLongitude"]; ok { - ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("CurrentLongitude")) - arg5, err = ec.unmarshalNString2string(ctx, tmp) - if err != nil { - return nil, err - } - } - args["CurrentLongitude"] = arg5 + args["CurrentLongitude"] = arg3 return args, nil } @@ -836,10 +861,6 @@ func (ec *executionContext) fieldContext_Mutation_loginAttendance(ctx context.Co return ec.fieldContext_Staff_company_id(ctx, field) case "company_name": return ec.fieldContext_Staff_company_name(ctx, field) - case "company_latitude": - return ec.fieldContext_Staff_company_latitude(ctx, field) - case "company_longitude": - return ec.fieldContext_Staff_company_longitude(ctx, field) case "is_active": return ec.fieldContext_Staff_is_active(ctx, field) case "is_login": @@ -988,10 +1009,6 @@ func (ec *executionContext) fieldContext_Query_searchStaffByEmail(ctx context.Co return ec.fieldContext_Staff_company_id(ctx, field) case "company_name": return ec.fieldContext_Staff_company_name(ctx, field) - case "company_latitude": - return ec.fieldContext_Staff_company_latitude(ctx, field) - case "company_longitude": - return ec.fieldContext_Staff_company_longitude(ctx, field) case "is_active": return ec.fieldContext_Staff_is_active(ctx, field) case "is_login": @@ -1079,10 +1096,6 @@ func (ec *executionContext) fieldContext_Query_staffGetByStaffId(ctx context.Con return ec.fieldContext_Staff_company_id(ctx, field) case "company_name": return ec.fieldContext_Staff_company_name(ctx, field) - case "company_latitude": - return ec.fieldContext_Staff_company_latitude(ctx, field) - case "company_longitude": - return ec.fieldContext_Staff_company_longitude(ctx, field) case "is_active": return ec.fieldContext_Staff_is_active(ctx, field) case "is_login": @@ -1170,10 +1183,6 @@ func (ec *executionContext) fieldContext_Query_staffListBySearch(ctx context.Con return ec.fieldContext_Staff_company_id(ctx, field) case "company_name": return ec.fieldContext_Staff_company_name(ctx, field) - case "company_latitude": - return ec.fieldContext_Staff_company_latitude(ctx, field) - case "company_longitude": - return ec.fieldContext_Staff_company_longitude(ctx, field) case "is_active": return ec.fieldContext_Staff_is_active(ctx, field) case "is_login": @@ -1222,7 +1231,7 @@ func (ec *executionContext) _Query_queryCheckDistance(ctx context.Context, field }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return ec.resolvers.Query().QueryCheckDistance(rctx, fc.Args["M_StaffID"].(string), fc.Args["M_CompanyID"].(string), fc.Args["M_CompanyLatitude"].(string), fc.Args["M_CompanyLongitude"].(string), fc.Args["CurrentLatitude"].(string), fc.Args["CurrentLongitude"].(string)) + return ec.resolvers.Query().QueryCheckDistance(rctx, fc.Args["M_StaffID"].(string), fc.Args["M_CompanyID"].(string), fc.Args["CurrentLatitude"].(string), fc.Args["CurrentLongitude"].(string)) }) if err != nil { ec.Error(ctx, err) @@ -1234,9 +1243,9 @@ func (ec *executionContext) _Query_queryCheckDistance(ctx context.Context, field } return graphql.Null } - res := resTmp.(*model.TransAbsensiResponse) + res := resTmp.(*model.TransAbsensiCheckDistanceResponse) fc.Result = res - return ec.marshalNTransAbsensiResponse2ᚖcomᚗsismedikaᚗcomᚗabsensiᚋgraphᚋmodelᚐTransAbsensiResponse(ctx, field.Selections, res) + return ec.marshalNTransAbsensiCheckDistanceResponse2ᚖcomᚗsismedikaᚗcomᚗabsensiᚋgraphᚋmodelᚐTransAbsensiCheckDistanceResponse(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_Query_queryCheckDistance(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -1248,11 +1257,19 @@ func (ec *executionContext) fieldContext_Query_queryCheckDistance(ctx context.Co Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { switch field.Name { case "status": - return ec.fieldContext_TransAbsensiResponse_status(ctx, field) + return ec.fieldContext_TransAbsensiCheckDistanceResponse_status(ctx, field) case "message": - return ec.fieldContext_TransAbsensiResponse_message(ctx, field) + return ec.fieldContext_TransAbsensiCheckDistanceResponse_message(ctx, field) + case "selfie": + return ec.fieldContext_TransAbsensiCheckDistanceResponse_selfie(ctx, field) + case "max_distance": + return ec.fieldContext_TransAbsensiCheckDistanceResponse_max_distance(ctx, field) + case "current_distance": + return ec.fieldContext_TransAbsensiCheckDistanceResponse_current_distance(ctx, field) + case "unit": + return ec.fieldContext_TransAbsensiCheckDistanceResponse_unit(ctx, field) } - return nil, fmt.Errorf("no field named %q was found under type TransAbsensiResponse", field.Name) + return nil, fmt.Errorf("no field named %q was found under type TransAbsensiCheckDistanceResponse", field.Name) }, } defer func() { @@ -1700,88 +1717,6 @@ func (ec *executionContext) fieldContext_Staff_company_name(ctx context.Context, return fc, nil } -func (ec *executionContext) _Staff_company_latitude(ctx context.Context, field graphql.CollectedField, obj *model.Staff) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Staff_company_latitude(ctx, field) - if err != nil { - return graphql.Null - } - ctx = graphql.WithFieldContext(ctx, fc) - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = graphql.Null - } - }() - resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.CompanyLatitude, nil - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*string) - fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) -} - -func (ec *executionContext) fieldContext_Staff_company_latitude(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "Staff", - Field: field, - IsMethod: false, - IsResolver: false, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") - }, - } - return fc, nil -} - -func (ec *executionContext) _Staff_company_longitude(ctx context.Context, field graphql.CollectedField, obj *model.Staff) (ret graphql.Marshaler) { - fc, err := ec.fieldContext_Staff_company_longitude(ctx, field) - if err != nil { - return graphql.Null - } - ctx = graphql.WithFieldContext(ctx, fc) - defer func() { - if r := recover(); r != nil { - ec.Error(ctx, ec.Recover(ctx, r)) - ret = graphql.Null - } - }() - resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { - ctx = rctx // use context from middleware stack in children - return obj.CompanyLongitude, nil - }) - if err != nil { - ec.Error(ctx, err) - return graphql.Null - } - if resTmp == nil { - return graphql.Null - } - res := resTmp.(*string) - fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) -} - -func (ec *executionContext) fieldContext_Staff_company_longitude(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { - fc = &graphql.FieldContext{ - Object: "Staff", - Field: field, - IsMethod: false, - IsResolver: false, - Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") - }, - } - return fc, nil -} - func (ec *executionContext) _Staff_is_active(ctx context.Context, field graphql.CollectedField, obj *model.Staff) (ret graphql.Marshaler) { fc, err := ec.fieldContext_Staff_is_active(ctx, field) if err != nil { @@ -2195,6 +2130,252 @@ func (ec *executionContext) fieldContext_TokenResponse_message(ctx context.Conte return fc, nil } +func (ec *executionContext) _TransAbsensiCheckDistanceResponse_status(ctx context.Context, field graphql.CollectedField, obj *model.TransAbsensiCheckDistanceResponse) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_TransAbsensiCheckDistanceResponse_status(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Status, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_TransAbsensiCheckDistanceResponse_status(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "TransAbsensiCheckDistanceResponse", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _TransAbsensiCheckDistanceResponse_message(ctx context.Context, field graphql.CollectedField, obj *model.TransAbsensiCheckDistanceResponse) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_TransAbsensiCheckDistanceResponse_message(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Message, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_TransAbsensiCheckDistanceResponse_message(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "TransAbsensiCheckDistanceResponse", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _TransAbsensiCheckDistanceResponse_selfie(ctx context.Context, field graphql.CollectedField, obj *model.TransAbsensiCheckDistanceResponse) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_TransAbsensiCheckDistanceResponse_selfie(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Selfie, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_TransAbsensiCheckDistanceResponse_selfie(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "TransAbsensiCheckDistanceResponse", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _TransAbsensiCheckDistanceResponse_max_distance(ctx context.Context, field graphql.CollectedField, obj *model.TransAbsensiCheckDistanceResponse) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_TransAbsensiCheckDistanceResponse_max_distance(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.MaxDistance, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_TransAbsensiCheckDistanceResponse_max_distance(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "TransAbsensiCheckDistanceResponse", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _TransAbsensiCheckDistanceResponse_current_distance(ctx context.Context, field graphql.CollectedField, obj *model.TransAbsensiCheckDistanceResponse) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_TransAbsensiCheckDistanceResponse_current_distance(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.CurrentDistance, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_TransAbsensiCheckDistanceResponse_current_distance(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "TransAbsensiCheckDistanceResponse", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _TransAbsensiCheckDistanceResponse_unit(ctx context.Context, field graphql.CollectedField, obj *model.TransAbsensiCheckDistanceResponse) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_TransAbsensiCheckDistanceResponse_unit(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Unit, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.(*string) + fc.Result = res + return ec.marshalOString2ᚖstring(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_TransAbsensiCheckDistanceResponse_unit(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "TransAbsensiCheckDistanceResponse", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _TransAbsensiResponse_status(ctx context.Context, field graphql.CollectedField, obj *model.TransAbsensiResponse) (ret graphql.Marshaler) { fc, err := ec.fieldContext_TransAbsensiResponse_status(ctx, field) if err != nil { @@ -4292,10 +4473,6 @@ func (ec *executionContext) _Staff(ctx context.Context, sel ast.SelectionSet, ob } case "company_name": out.Values[i] = ec._Staff_company_name(ctx, field, obj) - case "company_latitude": - out.Values[i] = ec._Staff_company_latitude(ctx, field, obj) - case "company_longitude": - out.Values[i] = ec._Staff_company_longitude(ctx, field, obj) case "is_active": out.Values[i] = ec._Staff_is_active(ctx, field, obj) case "is_login": @@ -4376,6 +4553,52 @@ func (ec *executionContext) _TokenResponse(ctx context.Context, sel ast.Selectio return out } +var transAbsensiCheckDistanceResponseImplementors = []string{"TransAbsensiCheckDistanceResponse"} + +func (ec *executionContext) _TransAbsensiCheckDistanceResponse(ctx context.Context, sel ast.SelectionSet, obj *model.TransAbsensiCheckDistanceResponse) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, transAbsensiCheckDistanceResponseImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("TransAbsensiCheckDistanceResponse") + case "status": + out.Values[i] = ec._TransAbsensiCheckDistanceResponse_status(ctx, field, obj) + case "message": + out.Values[i] = ec._TransAbsensiCheckDistanceResponse_message(ctx, field, obj) + case "selfie": + out.Values[i] = ec._TransAbsensiCheckDistanceResponse_selfie(ctx, field, obj) + case "max_distance": + out.Values[i] = ec._TransAbsensiCheckDistanceResponse_max_distance(ctx, field, obj) + case "current_distance": + out.Values[i] = ec._TransAbsensiCheckDistanceResponse_current_distance(ctx, field, obj) + case "unit": + out.Values[i] = ec._TransAbsensiCheckDistanceResponse_unit(ctx, field, obj) + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + var transAbsensiResponseImplementors = []string{"TransAbsensiResponse"} func (ec *executionContext) _TransAbsensiResponse(ctx context.Context, sel ast.SelectionSet, obj *model.TransAbsensiResponse) graphql.Marshaler { @@ -4843,6 +5066,20 @@ func (ec *executionContext) marshalNString2string(ctx context.Context, sel ast.S return res } +func (ec *executionContext) marshalNTransAbsensiCheckDistanceResponse2comᚗsismedikaᚗcomᚗabsensiᚋgraphᚋmodelᚐTransAbsensiCheckDistanceResponse(ctx context.Context, sel ast.SelectionSet, v model.TransAbsensiCheckDistanceResponse) graphql.Marshaler { + return ec._TransAbsensiCheckDistanceResponse(ctx, sel, &v) +} + +func (ec *executionContext) marshalNTransAbsensiCheckDistanceResponse2ᚖcomᚗsismedikaᚗcomᚗabsensiᚋgraphᚋmodelᚐTransAbsensiCheckDistanceResponse(ctx context.Context, sel ast.SelectionSet, v *model.TransAbsensiCheckDistanceResponse) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._TransAbsensiCheckDistanceResponse(ctx, sel, v) +} + func (ec *executionContext) marshalNTransAbsensiResponse2comᚗsismedikaᚗcomᚗabsensiᚋgraphᚋmodelᚐTransAbsensiResponse(ctx context.Context, sel ast.SelectionSet, v model.TransAbsensiResponse) graphql.Marshaler { return ec._TransAbsensiResponse(ctx, sel, &v) } diff --git a/backend/graph/graphqls/staff.graphqls b/backend/graph/graphqls/staff.graphqls index b3df76d..b73c818 100644 --- a/backend/graph/graphqls/staff.graphqls +++ b/backend/graph/graphqls/staff.graphqls @@ -7,8 +7,6 @@ type Staff { phone_number: String company_id: ID! company_name: String - company_latitude:String - company_longitude:String is_active: String is_login: String token: String diff --git a/backend/graph/graphqls/transabsensi.graphqls b/backend/graph/graphqls/transabsensi.graphqls index ebfbdd7..c898bbe 100644 --- a/backend/graph/graphqls/transabsensi.graphqls +++ b/backend/graph/graphqls/transabsensi.graphqls @@ -4,14 +4,24 @@ type TransAbsensiResponse { message: String } +# check distance response +type TransAbsensiCheckDistanceResponse { + status: String + message: String + selfie: String + max_distance: String + current_distance: String + unit: String +} + # query extend type Query { - # untuk cek distance dengan fungsi distance_v2 di database - queryCheckDistance(M_StaffID:String!, M_CompanyID:String!, M_CompanyLatitude:String!, M_CompanyLongitude:String!, CurrentLatitude:String!, CurrentLongitude:String!) : TransAbsensiResponse! + # untuk cek distance dengan fungsi distance_v2 di database + queryCheckDistance(M_StaffID:String!, M_CompanyID:String!,CurrentLatitude:String!, CurrentLongitude:String!) : TransAbsensiCheckDistanceResponse! } # mutation extend type Mutation { - # untuk clock in absensi (absensi masuk) - mutationClockInAttendance(T_TransactionM_AbsensiTypeID:String!, T_TransactionM_StaffID:String!, T_TransactionM_CompanyID:String!, T_TransactionCurrentLatitude:String!, T_TransactionCurrentLongitude:String!, T_TransactionDistance:String!, T_TransactionSelfiePhoto:String, T_TransactionNote:String):TransAbsensiResponse! + # untuk clock in absensi (absensi masuk) + mutationClockInAttendance(T_TransactionM_AbsensiTypeID:String!, T_TransactionM_StaffID:String!, T_TransactionM_CompanyID:String!, T_TransactionCurrentLatitude:String!, T_TransactionCurrentLongitude:String!, T_TransactionDistance:String!, T_TransactionSelfiePhoto:String, T_TransactionNote:String):TransAbsensiResponse! } \ No newline at end of file diff --git a/backend/graph/model/models_gen.go b/backend/graph/model/models_gen.go index dca75f0..e9e9bd8 100644 --- a/backend/graph/model/models_gen.go +++ b/backend/graph/model/models_gen.go @@ -16,8 +16,6 @@ type Staff struct { PhoneNumber *string `json:"phone_number,omitempty"` CompanyID string `json:"company_id"` CompanyName *string `json:"company_name,omitempty"` - CompanyLatitude *string `json:"company_latitude,omitempty"` - CompanyLongitude *string `json:"company_longitude,omitempty"` IsActive *string `json:"is_active,omitempty"` IsLogin *string `json:"is_login,omitempty"` Token *string `json:"token,omitempty"` @@ -33,6 +31,15 @@ type TokenResponse struct { Message *string `json:"message,omitempty"` } +type TransAbsensiCheckDistanceResponse struct { + Status *string `json:"status,omitempty"` + Message *string `json:"message,omitempty"` + Selfie *string `json:"selfie,omitempty"` + MaxDistance *string `json:"max_distance,omitempty"` + CurrentDistance *string `json:"current_distance,omitempty"` + Unit *string `json:"unit,omitempty"` +} + type TransAbsensiResponse struct { Status *string `json:"status,omitempty"` Message *string `json:"message,omitempty"` diff --git a/backend/graph/resolver/transabsensi.resolvers.go b/backend/graph/resolver/transabsensi.resolvers.go index 7d5de40..bd509ff 100644 --- a/backend/graph/resolver/transabsensi.resolvers.go +++ b/backend/graph/resolver/transabsensi.resolvers.go @@ -9,6 +9,7 @@ import ( "fmt" "com.sismedika.com.absensi/graph/model" + transabsensiinternal "com.sismedika.com.absensi/internal/transabsensi" ) // MutationClockInAttendance is the resolver for the mutationClockInAttendance field. @@ -17,19 +18,8 @@ func (r *mutationResolver) MutationClockInAttendance(ctx context.Context, tTrans } // QueryCheckDistance is the resolver for the queryCheckDistance field. -func (r *queryResolver) QueryCheckDistance(ctx context.Context, mStaffID string, mCompanyID string, mCompanyLatitude string, mCompanyLongitude string, currentLatitude string, currentLongitude string) (*model.TransAbsensiResponse, error) { - panic(fmt.Errorf("not implemented: QueryCheckDistance - queryCheckDistance")) -} - -// !!! WARNING !!! -// The code below was going to be deleted when updating resolvers. It has been copied here so you have -// one last chance to move it out of harms way if you want. There are two reasons this happens: -// - When renaming or deleting a resolver the old code will be put in here. You can safely delete -// it when you're done. -// - You have helper methods in this file. Move them out to keep these resolver files clean. -func (r *mutationResolver) MClockInAttendance(ctx context.Context, tTransactionMAbsensiTypeID string, tTransactionMStaffID string, tTransactionMCompanyID string, tTransactionCurrentLatitude string, tTransactionCurrentLongitude string, tTransactionDistance string, tTransactionSelfiePhoto *string, tTransactionNote *string) (*model.TransAbsensiResponse, error) { - panic(fmt.Errorf("not implemented: MClockInAttendance - mClockInAttendance")) -} -func (r *queryResolver) QCheckDistance(ctx context.Context, mStaffID string, mCompanyID string, mCompanyLatitude string, mCompanyLongitude string, currentLatitude string, currentLongitude string) (*model.TransAbsensiResponse, error) { - panic(fmt.Errorf("not implemented: QCheckDistance - qCheckDistance")) +func (r *queryResolver) QueryCheckDistance(ctx context.Context, mStaffID string, mCompanyID string, currentLatitude string, currentLongitude string) (*model.TransAbsensiCheckDistanceResponse, error) { + // panic(fmt.Errorf("not implemented: QueryCheckDistance - queryCheckDistance")) + var transabsensiinternal transabsensiinternal.TransAbsensiCheckDistanceResponse + return transabsensiinternal.CheckDistance(mStaffID, mCompanyID, currentLatitude, currentLongitude) } diff --git a/backend/internal/staff/staff.go b/backend/internal/staff/staff.go index a1cd119..8a7c876 100644 --- a/backend/internal/staff/staff.go +++ b/backend/internal/staff/staff.go @@ -92,8 +92,6 @@ func (staff *Staff) LoginAttendance(email string, id_google_sign_in string) (*mo M_StaffNoHp, M_CompanyID, M_CompanyName, - M_CompanyLatitude, - M_CompanyLongitude, M_StaffIsActive, M_StaffIsLogin, M_StaffToken, @@ -123,8 +121,6 @@ func (staff *Staff) LoginAttendance(email string, id_google_sign_in string) (*mo &ret.PhoneNumber, &ret.CompanyID, &ret.CompanyName, - &ret.CompanyLatitude, - &ret.CompanyLongitude, &ret.IsActive, &ret.IsLogin, &ret.Token, diff --git a/backend/internal/transabsensi/transabsensi.go b/backend/internal/transabsensi/transabsensi.go new file mode 100644 index 0000000..4f21efd --- /dev/null +++ b/backend/internal/transabsensi/transabsensi.go @@ -0,0 +1,129 @@ +package transabsensi + +import ( + "log" + "strconv" + + "com.sismedika.com.absensi/graph/model" + db "com.sismedika.com.absensi/pkg/database" +) + +// diambil dari graph/model/struct nya TransAbsensiResponse +type TransAbsensiCheckDistanceResponse model.TransAbsensiCheckDistanceResponse + +func (transabsensi *TransAbsensiCheckDistanceResponse) CheckDistance(M_StaffID string, M_CompanyID string, CurrentLatitude string, CurrentLongitude string) (*model.TransAbsensiCheckDistanceResponse, error) { + // inisialisasi + var err error + var ret model.TransAbsensiCheckDistanceResponse + var rMaxDistance int + var rCurrentDistance float64 + var rMCompanyLongitude string + var rMCompanyLatitude string + var statusCheck string + + q := `SELECT + M_CompanyLatitude, + M_CompanyLongitude, + M_CompanyMaxDistance + FROM m_company + WHERE M_CompanyIsActive = 'Y' + AND M_CompanyID = ?` + + row := db.Handle.QueryRow( + q, + M_CompanyID) + db.LogSQL(q) + err = row.Scan( + &rMCompanyLatitude, + &rMCompanyLongitude, + &rMaxDistance, + ) + + if err != nil { + log.Printf("Error m_company select max distance: %v", err) + log.Printf("Executing query: %s\n", q) + return nil, err + } + + // get distance + qCurrentDistance := `SELECT distance_v2(?, ?, ?, ?)` + + rowxCurrentDistance := db.Handle.QueryRow( + qCurrentDistance, + CurrentLatitude, + CurrentLongitude, + rMCompanyLatitude, + rMCompanyLongitude, + ) + db.LogSQL(qCurrentDistance) + err = rowxCurrentDistance.Scan( + &rCurrentDistance, + ) + + if err != nil { + log.Printf("Error m_staff select: %v", err) + log.Printf("Executing query: %s\n", qCurrentDistance) + return nil, err + } + + // check distance + qCheckDistance := `SELECT IF(distance_v2(?, ?, ?, ?) < ?, 'range', 'not range') AS distance_status` + + rowx := db.Handle.QueryRow( + qCheckDistance, + CurrentLatitude, + CurrentLongitude, + rMCompanyLatitude, + rMCompanyLongitude, + rMaxDistance, + ) + db.LogSQL(qCheckDistance) + err = rowx.Scan( + &statusCheck, + ) + + if err != nil { + log.Printf("Error m_staff select: %v", err) + log.Printf("Executing query: %s\n", qCheckDistance) + return nil, err + } + + if statusCheck == "range" { + // buat di set isi nya kosong dulu + ret.Status = new(string) + ret.Message = new(string) + ret.Selfie = new(string) + ret.CurrentDistance = new(string) + ret.MaxDistance = new(string) + ret.Unit = new(string) + + // di set kan langsung dengan * atau pointer + *ret.Status = "OK" + *ret.Selfie = "FALSE" + *ret.Unit = "m" + *ret.CurrentDistance = strconv.FormatFloat(rCurrentDistance, 'f', -1, 64) + *ret.MaxDistance = strconv.Itoa(rMaxDistance) + *ret.Message = "Masih dalam jarak absensi" + } + + if statusCheck != "range" { + // buat di set isi nya kosong dulu + ret.Status = new(string) + ret.Message = new(string) + ret.Selfie = new(string) + ret.CurrentDistance = new(string) + ret.MaxDistance = new(string) + ret.Unit = new(string) + + // di set kan langsung dengan * atau pointer + *ret.Status = "OK" + *ret.Selfie = "TRUE" + *ret.Unit = "m" + *ret.CurrentDistance = strconv.FormatFloat(rCurrentDistance, 'f', -1, 64) + *ret.MaxDistance = strconv.Itoa(rMaxDistance) + *ret.Message = "Max Distance : " + strconv.Itoa(rMaxDistance) + " meter. Current Distance: " + strconv.FormatFloat(rCurrentDistance, 'f', -1, 64) + ". Jauh dari area absensi, perlu foto selfie" + } + + // hasil return nya + return &ret, err +}