Created
March 5, 2024 05:03
-
-
Save margauxflores/31085ad1818be784401783a4446e302a to your computer and use it in GitHub Desktop.
Sample Call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package resolvers | |
| import ( | |
| schema "github.com/tailor-inc/platform-core-services/cmd/tailorctl/schema/v1:pipeline" | |
| "{{ .Values.cue.package }}/{{ .Values.cue.dist }}/directory:directories" | |
| "{{ .Values.cue.package }}/{{ .Values.cue.dist }}/pipeline:settings" | |
| ) | |
| // input moveToDeletedWorkrecordInput | |
| // id: ID! | |
| // deleteReason: String | |
| // deletedDate: Date! | |
| // currentState: String! | |
| // moveToDeletedWorkrecord(input: moveToDeletedWorkrecordInput): Boolean | |
| moveToDeletedWorkrecordInput: { | |
| name: "moveToDeletedWorkrecordInput" | |
| fields: [ | |
| { name: "id", type: schema.ID, required: true }, | |
| { name: "deleteReason", type: schema.String }, | |
| { name: "deletedDate", type: schema.Date, required: true }, | |
| { name: "currentState", type: schema.String, required: true }, | |
| ] | |
| } | |
| moveToDeletedWorkrecord: schema.#Resolver & { | |
| id: {{generateUUID | quote}} | |
| authorization: """ | |
| ifThen(user.roles.exists(e, e == "\(directories.roleMap.SiteManager.id)"), | |
| ["siteManagerApprove", "clerkApprove"].exists(e, e == context.args.input.currentState), false) | |
| || | |
| size(intersect(user.roles, [ | |
| "\(directories.roleMap.Clerk.id)", | |
| "\(directories.roleMap.AreaManager.id)", | |
| "\(directories.roleMap.SalesOfficeManager.id)", | |
| "\(directories.roleMap.Admin.id)", | |
| ])) > 0""" | |
| name: "moveToDeletedWorkrecord" | |
| description: "Delete workrecord to move to deletedWorkrecord" | |
| inputs: [ | |
| { name: "input", type: moveToDeletedWorkrecordInput, required: true }, | |
| ] | |
| response: { type: schema.Boolean } | |
| invoker: directories.roleMap.Admin.id | |
| postScript: "true" | |
| pipeline: [ | |
| { | |
| id: {{generateUUID | quote}} | |
| name: "getWorkRecord" | |
| description: "query workRecord" | |
| url: settings.services.gateway | |
| preScript: """ | |
| { | |
| "id": context.args.input.id, | |
| "userID": user.id | |
| }""" | |
| graphqlQuery: """ | |
| query ($id: ID! $userID: ID!){ | |
| workRecord:workRecord(id: $id) { | |
| id | |
| applicantID | |
| applicant{ | |
| user{ | |
| id | |
| } | |
| } | |
| applicationDate | |
| startedAt | |
| endedAt | |
| breakTime | |
| scheduledStartedAt | |
| scheduledEndedAt | |
| scheduledBreakTime | |
| transportCostType | |
| recordTypeID | |
| contractCode | |
| contractID | |
| stateID | |
| applicantCategoryCode | |
| workComment | |
| currentState | |
| bindingTime | |
| workingTime | |
| prescribedTime | |
| inPrescribedTime | |
| legalWorkingTime | |
| legalOverworkingTime | |
| statutoryOverworkingTime | |
| holidayWorkingTime | |
| lateWorkingTime | |
| } | |
| integrationWorkRecord: integrationWorkRecords( | |
| query: { workRecordID: { eq: $id } } | |
| ) { | |
| collection { | |
| id | |
| } | |
| } | |
| workRecordPermission: workRecordPermission(id: $id) { | |
| read { | |
| id | |
| permit | |
| } | |
| update { | |
| id | |
| permit | |
| } | |
| delete { | |
| id | |
| permit | |
| } | |
| } | |
| employees: employees(query: {userID: {eq: $userID}}) { | |
| collection { | |
| id | |
| } | |
| } | |
| }""" | |
| postScript: """ | |
| { | |
| "workRecord": args.workRecord, | |
| "integrationWorkRecordID": args.integrationWorkRecord.collection == [] ? null : args.integrationWorkRecord.collection[0].id, | |
| "workRecordPermission": args.workRecordPermission, | |
| "employeeID": args.employees.collection[0].id, | |
| "creatorPermission": [{ "id":args.workRecord.applicant.user.id, "permit":"allow" }] | |
| }""" | |
| }, | |
| { | |
| id: {{generateUUID | quote}} | |
| name: "deleteWorkRecord" | |
| description: "delete workRecord" | |
| url: settings.services.gateway | |
| preValidation: """ | |
| context.pipeline.getWorkRecord.workRecord != null ? "" : "勤怠レコードが存在しません" | |
| """ | |
| preScript: """ | |
| { | |
| "id": context.pipeline.getWorkRecord.workRecord.id | |
| }""" | |
| graphqlQuery: """ | |
| mutation ($id:ID!) { | |
| deleteWorkRecord(id:$id) | |
| }""" | |
| postValidation: """ | |
| args.deleteWorkRecord ? "" : "勤怠レコードが削除できませんでした。" | |
| """ | |
| }, | |
| { | |
| id: {{generateUUID | quote}} | |
| name: "deleteIntegrationWorkRecord" | |
| description: "delete IntegrationWorkRecord" | |
| url: settings.services.gateway | |
| test: "context.pipeline.getWorkRecord.integrationWorkRecordID != null" | |
| preValidation: """ | |
| context.pipeline.getWorkRecord.workRecord != null ? "" : "統合システム連携用の勤怠レコードが存在しません" | |
| """ | |
| preScript: """ | |
| { | |
| "id": context.pipeline.getWorkRecord.integrationWorkRecordID | |
| }""" | |
| graphqlQuery: """ | |
| mutation ($id:ID!) { | |
| deleteIntegrationWorkRecord(id:$id) | |
| }""" | |
| postValidation: """ | |
| args.deleteIntegrationWorkRecord ? "" : "統合システム連携用の勤怠レコードが削除できませんでした。" | |
| """ | |
| }, | |
| { | |
| id: {{generateUUID | quote}} | |
| name: "createDeletedWorkRecord" | |
| description: "create deletedWorkRecord" | |
| url: settings.services.gateway | |
| preScript: """ | |
| { | |
| "input": | |
| compact({ | |
| "originalWorkrecordID": context.pipeline.getWorkRecord.workRecord.id, | |
| "applicantID": context.pipeline.getWorkRecord.workRecord.applicantID, | |
| "applicationDate": context.pipeline.getWorkRecord.workRecord.applicationDate, | |
| "startedAt": context.pipeline.getWorkRecord.workRecord.startedAt, | |
| "endedAt": context.pipeline.getWorkRecord.workRecord.endedAt, | |
| "breakTime": context.pipeline.getWorkRecord.workRecord.breakTime, | |
| "scheduledStartedAt": context.pipeline.getWorkRecord.workRecord.scheduledStartedAt, | |
| "scheduledEndedAt": context.pipeline.getWorkRecord.workRecord.scheduledEndedAt, | |
| "scheduledBreakTime": context.pipeline.getWorkRecord.workRecord.scheduledBreakTime, | |
| "transportCostType": context.pipeline.getWorkRecord.workRecord.transportCostType, | |
| "recordTypeID": context.pipeline.getWorkRecord.workRecord.recordTypeID, | |
| "contractCode": context.pipeline.getWorkRecord.workRecord.contractCode, | |
| "workComment": context.pipeline.getWorkRecord.workRecord.workComment, | |
| "contractID": context.pipeline.getWorkRecord.workRecord.contractID, | |
| "currentState": context.pipeline.getWorkRecord.workRecord.currentState, | |
| "stateID": context.pipeline.getWorkRecord.workRecord.stateID, | |
| "deletedByID": context.pipeline.getWorkRecord.employeeID, | |
| "deleteReason": context.args.input.deleteReason, | |
| "deletedDate": context.args.input.deletedDate, | |
| "applicantCategoryCode": context.pipeline.getWorkRecord.workRecord.applicantCategoryCode, | |
| "bindingTime": context.pipeline.getWorkRecord.workRecord.bindingTime, | |
| "workingTime": context.pipeline.getWorkRecord.workRecord.workingTime, | |
| "prescribedTime": context.pipeline.getWorkRecord.workRecord.prescribedTime, | |
| "inPrescribedTime": context.pipeline.getWorkRecord.workRecord.inPrescribedTime, | |
| "legalWorkingTime": context.pipeline.getWorkRecord.workRecord.legalWorkingTime, | |
| "legalOverworkingTime": context.pipeline.getWorkRecord.workRecord.legalOverworkingTime, | |
| "statutoryOverworkingTime": context.pipeline.getWorkRecord.workRecord.statutoryOverworkingTime, | |
| "holidayWorkingTime": context.pipeline.getWorkRecord.workRecord.holidayWorkingTime, | |
| "lateWorkingTime": context.pipeline.getWorkRecord.workRecord.lateWorkingTime | |
| }) | |
| }""" | |
| graphqlQuery: """ | |
| mutation ($input: DeletedWorkRecordCreateInput) { | |
| createDeletedWorkRecord(input: $input) { | |
| id | |
| } | |
| }""" | |
| postScript: "args.createDeletedWorkRecord" | |
| }, | |
| { | |
| id: {{generateUUID | quote}} | |
| name: "changeDeletedWorkRecord" | |
| description: "setting same permission of original workrecord to deletedWorkRecord " | |
| url: settings.services.gateway | |
| preScript: """ | |
| { | |
| "id": context.pipeline.createDeletedWorkRecord.id, | |
| "read": context.pipeline.getWorkRecord.workRecordPermission.read == null ? [] : context.pipeline.getWorkRecord.workRecordPermission.read + context.pipeline.getWorkRecord.creatorPermission, | |
| "update": context.pipeline.getWorkRecord.workRecordPermission.update == null ? [] : context.pipeline.getWorkRecord.workRecordPermission.update, | |
| "delete": context.pipeline.getWorkRecord.workRecordPermission.delete == null ? [] : context.pipeline.getWorkRecord.workRecordPermission.delete | |
| }""" | |
| graphqlQuery: """ | |
| mutation ( | |
| $id: ID! | |
| $read: [PermissionItemInput] | |
| $update: [PermissionItemInput] | |
| $delete: [PermissionItemInput] | |
| ) { | |
| changeDeletedWorkRecord( | |
| id: $id | |
| read: $read | |
| update: $update | |
| delete: $delete | |
| ) | |
| }""" | |
| postScript: "args.changeDeletedWorkRecord" | |
| }, | |
| { | |
| id: {{generateUUID | quote}} | |
| name: "searchWorkRecords" | |
| description: "search existing work records" | |
| url: settings.services.gateway | |
| preScript: """ | |
| { | |
| "applicantID": context.pipeline.getWorkRecord.workRecord.applicantID, | |
| "applicationDate": context.pipeline.getWorkRecord.workRecord.applicationDate | |
| }""" | |
| graphqlQuery: """ | |
| query ( | |
| $applicationDate: Date! | |
| $applicantID: ID! | |
| ) { | |
| workRecords( | |
| query: { | |
| applicationDate: {eq: $applicationDate} | |
| applicantID: {eq: $applicantID} | |
| } | |
| order: { field: startedAt, direction: Asc }, | |
| ) { | |
| collection { | |
| id | |
| recordTypeID | |
| applicationDate | |
| startedAt | |
| endedAt | |
| breakTime | |
| lateTime | |
| applicantID | |
| stateID | |
| applicantCategoryCode | |
| contractID | |
| contractCode | |
| currentState | |
| workComment | |
| applicantCode | |
| applicantName | |
| employeeCategory | |
| contractName | |
| contractWorkplaceName | |
| transportCostType | |
| scheduledStartedAt | |
| scheduledEndedAt | |
| scheduledBreakTime | |
| } | |
| } | |
| }""" | |
| postScript: """ | |
| { | |
| "collection": args.workRecords.collection, | |
| }""" | |
| }, | |
| { | |
| id: {{generateUUID | quote}} | |
| name: "calculateWorkRecords" | |
| description: "calculate work records" | |
| url: settings.services.gateway | |
| forEach: "context.pipeline.searchWorkRecords.collection" | |
| preScript: """ | |
| { | |
| "input": { | |
| "id": each.id, | |
| "recordTypeID": each.recordTypeID, | |
| "applicationDate": each.applicationDate, | |
| "applicantID": context.pipeline.getWorkRecord.workRecord.applicantID, | |
| "startedAt": each.startedAt, | |
| "endedAt": each.endedAt, | |
| "breakTime": get(each.breakTime, time("00:00")), | |
| "lateTime": get(each.lateTime, time("00:00")), | |
| "defaultScheduledStartedAt": get(each.scheduledStartedAt), | |
| "defaultScheduledEndedAt": get(each.scheduledEndedAt), | |
| "defaultScheduledBreakTime": get(each.scheduledBreakTime), | |
| "remainingPrescribedTime": ifThen( key == 0, time("08:00"), results[key - 1].result.remainingPrescribedTime) | |
| } | |
| }""" | |
| graphqlQuery: """ | |
| mutation calculateWorkRecord($input: CalculateWorkRecordInput!) { | |
| calculateWorkRecord(input:$input) { | |
| id | |
| startedAt | |
| endedAt | |
| breakTime | |
| lateTime | |
| scheduledStartedAt | |
| scheduledEndedAt | |
| scheduledBreakTime | |
| legalWorkingTime | |
| remainingPrescribedTime | |
| workingTime | |
| bindingTime | |
| prescribedTime | |
| inPrescribedTime | |
| legalOverworkingTime | |
| statutoryOverworkingTime | |
| lateWorkingTime | |
| holidayWorkingTime | |
| recordTypeID | |
| } | |
| }""" | |
| postScript: """ | |
| { | |
| "result": args.calculateWorkRecord | |
| }""" | |
| }, | |
| { | |
| id: {{generateUUID | quote}} | |
| name: "updateWorkRecords", | |
| description: "update work records", | |
| forEach: "args" | |
| url: settings.services.gateway | |
| preScript: """ | |
| { | |
| "input": [compact({ | |
| "id": each.result.id, | |
| "stateID": context.pipeline.searchWorkRecords.collection[key].stateID, | |
| "currentState": context.pipeline.searchWorkRecords.collection[key].currentState, | |
| "contractID": context.pipeline.searchWorkRecords.collection[key].contractID, | |
| "applicantID": context.pipeline.searchWorkRecords.collection[key].applicantID, | |
| "recordTypeID": context.pipeline.searchWorkRecords.collection[key].recordTypeID, | |
| "applicationDate": context.pipeline.searchWorkRecords.collection[key].applicationDate, | |
| "applicantCategoryCode": context.pipeline.searchWorkRecords.collection[key].applicantCategoryCode, | |
| "applicantCode": context.pipeline.searchWorkRecords.collection[key].applicantCode, | |
| "applicantName": context.pipeline.searchWorkRecords.collection[key].applicantName, | |
| "employeeCategory": context.pipeline.searchWorkRecords.collection[key].employeeCategory, | |
| "contractCode": context.pipeline.searchWorkRecords.collection[key].contractCode, | |
| "contractName": context.pipeline.searchWorkRecords.collection[key].contractName, | |
| "contractWorkplaceName": context.pipeline.searchWorkRecords.collection[key].contractWorkplaceName, | |
| "workComment": context.pipeline.searchWorkRecords.collection[key].workComment, | |
| "transportCostType": context.pipeline.searchWorkRecords.collection[key].transportCostType, | |
| "startedAt": get(each.result.startedAt), | |
| "endedAt": get(each.result.endedAt), | |
| "breakTime": get(each.result.breakTime), | |
| "scheduledStartedAt": get(each.result.scheduledStartedAt), | |
| "scheduledEndedAt": get(each.result.scheduledEndedAt), | |
| "scheduledBreakTime": get(each.result.scheduledBreakTime), | |
| "legalWorkingTime": get(each.result.legalWorkingTime), | |
| "workingTime": get(each.result.workingTime), | |
| "bindingTime": get(each.result.bindingTime), | |
| "lateTime": get(each.result.lateTime), | |
| "prescribedTime": get(each.result.prescribedTime), | |
| "inPrescribedTime": get(each.result.inPrescribedTime), | |
| "legalOverworkingTime": get(each.result.legalOverworkingTime), | |
| "statutoryOverworkingTime": get(each.result.statutoryOverworkingTime), | |
| "lateWorkingTime": get(each.result.lateWorkingTime), | |
| "holidayWorkingTime": get(each.result.holidayWorkingTime), | |
| })] | |
| }""" | |
| graphqlQuery: """ | |
| mutation bulkUpsertWorkRecords($input: [WorkRecordCreateInput]!) { | |
| bulkUpsertWorkRecords(input:$input) | |
| }""" | |
| postScript: """ | |
| { | |
| "workRecord": compact({ | |
| "id": context.pipeline.searchWorkRecords.collection[key].id, | |
| "contractID": context.pipeline.searchWorkRecords.collection[key].contractID, | |
| "contractCode": context.pipeline.searchWorkRecords.collection[key].contractCode, | |
| "contractName": context.pipeline.searchWorkRecords.collection[key].contractName, | |
| "contractWorkplaceName": context.pipeline.searchWorkRecords.collection[key].contractWorkplaceName, | |
| "applicationDate": context.pipeline.searchWorkRecords.collection[key].applicationDate, | |
| "wokrComment": context.pipeline.searchWorkRecords.collection[key].workComment, | |
| "startedAt": get(each.result.startedAt), | |
| "endedAt": get(each.result.endedAt), | |
| "breakTime": get(each.result.breakTime), | |
| "scheduledStartedAt": get(each.result.scheduledStartedAt), | |
| "scheduledEndedAt": get(each.result.scheduledEndedAt), | |
| "scheduledBreakTime": get(each.result.scheduledBreakTime), | |
| "legalWorkingTime": get(each.result.legalWorkingTime), | |
| "workingTime": get(each.result.workingTime), | |
| "bindingTime": get(each.result.bindingTime), | |
| "lateTime": get(each.result.lateTime), | |
| "prescribedTime": get(each.result.prescribedTime), | |
| "inPrescribedTime": get(each.result.inPrescribedTime), | |
| "legalOverworkingTime": get(each.result.legalOverworkingTime), | |
| "statutoryOverworkingTime": get(each.result.statutoryOverworkingTime), | |
| "lateWorkingTime": get(each.result.lateWorkingTime), | |
| "holidayWorkingTime": get(each.result.holidayWorkingTime), | |
| "recordTypeID": get(each.result.recordTypeID), | |
| "transportCostType": get(each.result.transportCostType), | |
| }) | |
| }""" | |
| }, | |
| { | |
| id: {{generateUUID | quote}} | |
| name: "searchIntegrationWorkRecords" | |
| description: "search existing integration work records" | |
| url: settings.services.gateway | |
| forEach: "args" | |
| preScript: """ | |
| { | |
| "workRecordID": each.workRecord.id, | |
| }""" | |
| graphqlQuery: """ | |
| query ($workRecordID: ID!) { | |
| integrationWorkRecords( | |
| query: {workRecordID: {eq: $workRecordID} } | |
| ) { | |
| collection { | |
| id | |
| } | |
| } | |
| }""" | |
| postScript: """ | |
| { | |
| "id": size(args.integrationWorkRecords.collection) > 0 ? args.integrationWorkRecords.collection[0].id : null, | |
| "workRecord": each.workRecord, | |
| }""" | |
| }, | |
| { | |
| id: {{generateUUID | quote}} | |
| name: "updateIntegrationWorkRecords", | |
| description: "update integration workrecords", | |
| forEach: "args" | |
| url: settings.services.gateway | |
| test: "each.id != null" | |
| preScript: """ | |
| { | |
| "id": get(each.id), | |
| "input": compact({ | |
| "workRecordID": each.workRecord.id, | |
| "startTime": dyn(int(time(each.workRecord.startedAt))), | |
| "endTime": dyn(int(time(each.workRecord.endedAt))), | |
| "breakTime": dyn(int(time(each.workRecord.breakTime))), | |
| "scheduledStartTime": dyn(int(time(each.workRecord.scheduledStartedAt))), | |
| "scheduledEndTime": dyn(int(time(each.workRecord.scheduledEndedAt))), | |
| "scheduledBreakTime": dyn(int(time(each.workRecord.scheduledBreakTime))), | |
| "isImported": false | |
| }) | |
| }""" | |
| graphqlQuery: """ | |
| mutation updateIntegrationWorkRecord( | |
| $id: ID!, | |
| $input: IntegrationWorkRecordUpdateInput) { | |
| updateIntegrationWorkRecord(id:$id, input: $input) { | |
| id | |
| } | |
| } | |
| """ | |
| postScript: """ | |
| { | |
| "result": has(args.updateIntegrationWorkRecord) ? true : false | |
| } | |
| """ | |
| }, | |
| { | |
| id: {{generateUUID | quote}} | |
| name: "checkBulkUpsertResult", | |
| description: "check bulk upsert result", | |
| forEach: "args" | |
| preValidation: """ | |
| each.result ? "" : "IntegrationWorkRecordの更新に失敗しました。" | |
| """ | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment