|
| 1 | +import { PAYMENT_METHOD_OPTIONS } from "../../common/constants.mjs"; |
| 2 | +import app from "../../teach_n_go.app.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "teach_n_go-create-student", |
| 6 | + name: "Create Student", |
| 7 | + description: "Registers a new student in Teach 'n Go. [See the documentation](https://intercom.help/teach-n-go/en/articles/6807235-new-student-and-class-registration-api)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + app, |
| 12 | + firstName: { |
| 13 | + propDefinition: [ |
| 14 | + app, |
| 15 | + "firstName", |
| 16 | + ], |
| 17 | + description: "The student's first name.", |
| 18 | + }, |
| 19 | + lastName: { |
| 20 | + propDefinition: [ |
| 21 | + app, |
| 22 | + "lastName", |
| 23 | + ], |
| 24 | + description: "The student's last name.", |
| 25 | + }, |
| 26 | + gender: { |
| 27 | + propDefinition: [ |
| 28 | + app, |
| 29 | + "gender", |
| 30 | + ], |
| 31 | + description: "The student's gender.", |
| 32 | + optional: true, |
| 33 | + }, |
| 34 | + registrationDate: { |
| 35 | + type: "string", |
| 36 | + label: "Registration Date", |
| 37 | + description: "The student's registration date. **Format: YYYY-MM-DD**", |
| 38 | + optional: true, |
| 39 | + }, |
| 40 | + dateOfBirth: { |
| 41 | + propDefinition: [ |
| 42 | + app, |
| 43 | + "dateOfBirth", |
| 44 | + ], |
| 45 | + description: "The student's date of birth. **Format: YYYY-MM-DD**", |
| 46 | + optional: true, |
| 47 | + }, |
| 48 | + identificationNumber: { |
| 49 | + type: "string", |
| 50 | + label: "Identification Number", |
| 51 | + description: "The external number to identify the student.", |
| 52 | + optional: true, |
| 53 | + }, |
| 54 | + preferredPaymentMethod: { |
| 55 | + type: "integer", |
| 56 | + label: "Preferred Payment Method", |
| 57 | + description: "The payment method the student want to use.", |
| 58 | + options: PAYMENT_METHOD_OPTIONS, |
| 59 | + optional: true, |
| 60 | + }, |
| 61 | + discountPercentage: { |
| 62 | + type: "string", |
| 63 | + label: "Discount Percentage", |
| 64 | + description: "The discount percentage on the payment amount.", |
| 65 | + optional: true, |
| 66 | + }, |
| 67 | + mobilePhoneCode: { |
| 68 | + type: "integer", |
| 69 | + label: "Mobile Phone Code", |
| 70 | + description: "The region code of the mobile phone. Min length: 2, Max length: 4", |
| 71 | + optional: true, |
| 72 | + }, |
| 73 | + mobilePhone: { |
| 74 | + type: "integer", |
| 75 | + label: "Mobile Phone", |
| 76 | + description: "The student's mobile phone", |
| 77 | + optional: true, |
| 78 | + }, |
| 79 | + homePhoneCode: { |
| 80 | + type: "integer", |
| 81 | + label: "Home Phone Code", |
| 82 | + description: "The region code of the home phone. Min length: 2, Max length: 4", |
| 83 | + optional: true, |
| 84 | + }, |
| 85 | + homePhone: { |
| 86 | + type: "integer", |
| 87 | + label: "Home Phone", |
| 88 | + description: "The student's home phone", |
| 89 | + optional: true, |
| 90 | + }, |
| 91 | + emailAddress: { |
| 92 | + propDefinition: [ |
| 93 | + app, |
| 94 | + "emailAddress", |
| 95 | + ], |
| 96 | + description: "The student's email address.", |
| 97 | + optional: true, |
| 98 | + }, |
| 99 | + streetNameAndNumber: { |
| 100 | + type: "string", |
| 101 | + label: "Street Name And Number", |
| 102 | + description: "The student's full address.", |
| 103 | + optional: true, |
| 104 | + }, |
| 105 | + flatFloor: { |
| 106 | + type: "string", |
| 107 | + label: "Flat Floor", |
| 108 | + description: "The student's address flat floor if it exists.", |
| 109 | + optional: true, |
| 110 | + }, |
| 111 | + area: { |
| 112 | + type: "string", |
| 113 | + label: "Area", |
| 114 | + description: "The student's address area.", |
| 115 | + optional: true, |
| 116 | + }, |
| 117 | + city: { |
| 118 | + type: "string", |
| 119 | + label: "City", |
| 120 | + description: "The student's city.", |
| 121 | + optional: true, |
| 122 | + }, |
| 123 | + postcode: { |
| 124 | + type: "string", |
| 125 | + label: "Postcode", |
| 126 | + description: "The student's postcode.", |
| 127 | + optional: true, |
| 128 | + }, |
| 129 | + countryCode: { |
| 130 | + type: "string", |
| 131 | + label: "Country Code", |
| 132 | + description: "The student's ISO 2 letter country code, e.g. (US, UK, IN).", |
| 133 | + optional: true, |
| 134 | + }, |
| 135 | + generalNotes: { |
| 136 | + type: "string", |
| 137 | + label: "General Notes", |
| 138 | + description: "Some student's additional notes.", |
| 139 | + optional: true, |
| 140 | + }, |
| 141 | + medicalNotes: { |
| 142 | + type: "string", |
| 143 | + label: "Medical Notes", |
| 144 | + description: "Some student's additional medical notes.", |
| 145 | + optional: true, |
| 146 | + }, |
| 147 | + courses: { |
| 148 | + propDefinition: [ |
| 149 | + app, |
| 150 | + "courses", |
| 151 | + ], |
| 152 | + optional: true, |
| 153 | + }, |
| 154 | + enrolmentDate: { |
| 155 | + type: "string", |
| 156 | + label: "Enrolment Date", |
| 157 | + description: "The date of the student's enrolment.", |
| 158 | + optional: true, |
| 159 | + }, |
| 160 | + }, |
| 161 | + async run({ $ }) { |
| 162 | + const response = await this.app.registerStudent({ |
| 163 | + $, |
| 164 | + data: { |
| 165 | + fname: this.firstName, |
| 166 | + lname: this.lastName, |
| 167 | + gender: this.gender, |
| 168 | + registration_date: this.registrationDate, |
| 169 | + date_of_birth: this.dateOfBirth, |
| 170 | + identification_number: this.identificationNumber, |
| 171 | + preferred_payment_method: this.preferredPaymentMethod, |
| 172 | + discount_percentage: this.discountPercentage && parseFloat(this.discountPercentage), |
| 173 | + mobile_phone_code: this.mobilePhoneCode, |
| 174 | + mobile_phone: this.mobilePhone, |
| 175 | + home_phone_code: this.homePhoneCode, |
| 176 | + home_phone: this.homePhone, |
| 177 | + email_address: this.emailAddress, |
| 178 | + street_name_and_number: this.streetNameAndNumber, |
| 179 | + flat_floor: this.flatFloor, |
| 180 | + area: this.area, |
| 181 | + city: this.city, |
| 182 | + postcode: this.postcode, |
| 183 | + country_code: this.countryCode, |
| 184 | + general_notes: this.generalNotes, |
| 185 | + medical_notes: this.medicalNotes, |
| 186 | + courses: this.courses, |
| 187 | + enrolment_date: this.enrolmentDate, |
| 188 | + }, |
| 189 | + }); |
| 190 | + |
| 191 | + $.export("$summary", `Successfully registered student with ID: ${response.data.id}`); |
| 192 | + return response; |
| 193 | + }, |
| 194 | +}; |
0 commit comments