gm-mcp 2.0.3 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,15 @@
1
1
  import { Gimo } from "./types";
2
+ import { PayPeriod } from "./types/pay-period";
3
+ import { TimeSheet } from "./types/time-keeper";
2
4
  export declare function getAccessToken(): Promise<string>;
3
5
  export declare function findCustomerEWAByPhonenumber(phoneNumber: string): Promise<Gimo.CustomerEWA | null>;
6
+ export declare function getPayPeriods(params: {
7
+ orgId: number;
8
+ parnterId: number;
9
+ }): Promise<PayPeriod[]>;
10
+ export declare function getTimeSheets(params: {
11
+ payPeriodId: number;
12
+ employeeId: number;
13
+ }): Promise<TimeSheet[]>;
4
14
  export declare function getEmployeeByCustomerId(customerId: number): Promise<Gimo.EmployeeInfo>;
5
15
  export declare function findCustomerEWAById(id: number): Promise<Gimo.CustomerEWA>;
@@ -14,6 +14,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.getAccessToken = getAccessToken;
16
16
  exports.findCustomerEWAByPhonenumber = findCustomerEWAByPhonenumber;
17
+ exports.getPayPeriods = getPayPeriods;
18
+ exports.getTimeSheets = getTimeSheets;
17
19
  exports.getEmployeeByCustomerId = getEmployeeByCustomerId;
18
20
  exports.findCustomerEWAById = findCustomerEWAById;
19
21
  const axios_1 = __importDefault(require("axios"));
@@ -51,6 +53,46 @@ function findCustomerEWAByPhonenumber(phoneNumber) {
51
53
  return findCustomerEWAById(foundedCustomer.customer_id);
52
54
  });
53
55
  }
56
+ function getPayPeriods(params) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ const { orgId, parnterId } = params;
59
+ const url = `${(0, env_1.getEnv)().DASH_URL}/api/v1/admin/partners/${parnterId}/pay-periods`;
60
+ const access_token = yield getAccessToken();
61
+ const customer = yield axios_1.default
62
+ .get(url, {
63
+ headers: {
64
+ Authorization: "Bearer " + access_token,
65
+ },
66
+ params: {
67
+ orgId,
68
+ sort: "start_date,desc",
69
+ },
70
+ })
71
+ .then((res) => res.data);
72
+ // Select first customer
73
+ return customer || null;
74
+ });
75
+ }
76
+ function getTimeSheets(params) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const { payPeriodId, employeeId } = params;
79
+ const url = `${(0, env_1.getEnv)().DASH_URL}/api/v2/admin/time-sheets/by-period`;
80
+ const access_token = yield getAccessToken();
81
+ const customer = yield axios_1.default
82
+ .get(url, {
83
+ headers: {
84
+ Authorization: "Bearer " + access_token,
85
+ },
86
+ params: {
87
+ employeeId,
88
+ payPeriodId,
89
+ },
90
+ })
91
+ .then((res) => res.data);
92
+ // Select first customer
93
+ return customer || null;
94
+ });
95
+ }
54
96
  function getEmployeeByCustomerId(customerId) {
55
97
  return __awaiter(this, void 0, void 0, function* () {
56
98
  const url = `${(0, env_1.getEnv)().DASH_URL}/api/v1/admin/customers/${customerId}/employee-info`;
@@ -0,0 +1,41 @@
1
+ export interface PayPeriod {
2
+ id: number;
3
+ start_date: string;
4
+ end_date: string;
5
+ principal_due_date: string;
6
+ limit_total_enable: boolean;
7
+ limit_total_allowed: any;
8
+ limit_total_accumulated: number;
9
+ config: Config;
10
+ config_name: string;
11
+ created_at: string;
12
+ }
13
+ export interface Config {
14
+ id: number;
15
+ active: boolean;
16
+ code: string;
17
+ name: string;
18
+ note: string;
19
+ limit_total_enable: boolean;
20
+ limit_total_allowed: any;
21
+ partner_id: number;
22
+ partner_name: string;
23
+ organization_structure_id: number;
24
+ organization_structure_name: string;
25
+ config_type: string;
26
+ month_start_day: number;
27
+ month_start_at: string;
28
+ cycle_start_at: any;
29
+ cycle_day_num: any;
30
+ created_at: string;
31
+ amount_for_preview: number;
32
+ editable: boolean;
33
+ marker: string;
34
+ duration_type: string;
35
+ extend: number;
36
+ time: string;
37
+ pay_period_num_from_current: number;
38
+ path: any;
39
+ version_number: number;
40
+ previous_config_id: any;
41
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,11 @@
1
+ export interface TimeSheet {
2
+ id: string;
3
+ employee_id: number;
4
+ employee_full_name: any;
5
+ employee_code: any;
6
+ date: string;
7
+ value: number;
8
+ created_at: string;
9
+ check_in: string;
10
+ check_out: string;
11
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,4 +3,5 @@ export declare const DEBT_COLLECTION_TYPE: {
3
3
  readonly PARTNER_IN_CHARGE: "PARTNER_IN_CHARGE";
4
4
  readonly DIRECT_FROM_CUSTOMER_ACCOUNT: "DIRECT_FROM_CUSTOMER_ACCOUNT";
5
5
  };
6
+ export declare const EMPLOYEE_STATUS_MAPS: Record<string, any>;
6
7
  export declare function accessibleTool(phoneNumber: string): Promise<CallToolResult>;
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.DEBT_COLLECTION_TYPE = void 0;
12
+ exports.EMPLOYEE_STATUS_MAPS = exports.DEBT_COLLECTION_TYPE = void 0;
13
13
  exports.accessibleTool = accessibleTool;
14
14
  const gimo_service_1 = require("../services/gimo.service");
15
15
  const PRODUCT_TYPE = {
@@ -48,6 +48,28 @@ function getProductType(options) {
48
48
  }
49
49
  return null;
50
50
  }
51
+ exports.EMPLOYEE_STATUS_MAPS = {
52
+ ACTIVE: "Đang làm việc",
53
+ SUSPEND__WAITING_TO_APPROVE: "Chờ công đoàn phê duyệt",
54
+ SUSPEND__MATERNITY_LEAVE: "Nhân sự nghỉ thai sản",
55
+ SUSPEND__UNPAID_LEAVE: "Nhân sự nghỉ không lương",
56
+ SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT: "Chờ cập nhật chứng minh thu nhập",
57
+ SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT: "Chờ phê duyệt chứng minh thu nhập",
58
+ SUSPEND__DEFAULT: "Tạm nghỉ",
59
+ INACTIVE: "Nghỉ việc",
60
+ };
61
+ const BASE_REQUIRED_CRITERIA = {
62
+ ewa_status: "ACTIVE",
63
+ seniority: ">= 0.3 year",
64
+ working_status: exports.EMPLOYEE_STATUS_MAPS.ACTIVE,
65
+ longest_overdue_bill: "<=10 days",
66
+ outstanding_balance: "0",
67
+ parnter_contract_expirity: "Not yet expired",
68
+ time_sheet: "The data exists",
69
+ geofencing_status: "??",
70
+ };
71
+ const EWA_02_CRITERIA = Object.assign(Object.assign({}, BASE_REQUIRED_CRITERIA), { dda: "REGISTERED" });
72
+ const EWA_03_CRITERIA = Object.assign(Object.assign({}, BASE_REQUIRED_CRITERIA), { dda: "REGISTERED" });
51
73
  function accessibleTool(phoneNumber) {
52
74
  return __awaiter(this, void 0, void 0, function* () {
53
75
  try {
@@ -56,6 +78,15 @@ function accessibleTool(phoneNumber) {
56
78
  throw "Customer not found";
57
79
  }
58
80
  const { employee, partner } = yield (0, gimo_service_1.getEmployeeByCustomerId)(customer.customer_id);
81
+ let periods = [];
82
+ let timeSheets = [];
83
+ if (employee) {
84
+ const payPeriods = yield (0, gimo_service_1.getPayPeriods)({ orgId: employee === null || employee === void 0 ? void 0 : employee.organization_id, parnterId: employee.partner_id });
85
+ if (payPeriods === null || payPeriods === void 0 ? void 0 : payPeriods.length) {
86
+ periods = payPeriods;
87
+ timeSheets = yield (0, gimo_service_1.getTimeSheets)({ payPeriodId: payPeriods[0].id, employeeId: employee.id });
88
+ }
89
+ }
59
90
  const { debt_collection, onboard_method } = partner || {};
60
91
  const productType = getProductType({
61
92
  debt_collection_type: debt_collection || "",
@@ -65,15 +96,23 @@ function accessibleTool(phoneNumber) {
65
96
  ewa_status: customer === null || customer === void 0 ? void 0 : customer.ewa_status,
66
97
  dda: customer === null || customer === void 0 ? void 0 : customer.dda_status,
67
98
  seniority: employee === null || employee === void 0 ? void 0 : employee.seniority,
68
- working_status: employee === null || employee === void 0 ? void 0 : employee.status,
99
+ working_status: exports.EMPLOYEE_STATUS_MAPS[(employee === null || employee === void 0 ? void 0 : employee.status) || "ACTIVE"],
69
100
  product_type: productType,
101
+ time_sheet: (timeSheets === null || timeSheets === void 0 ? void 0 : timeSheets.length) ? "The data exists" : "The data does't exists",
70
102
  };
71
- const requiredCriteria = {
72
- ewa_status: "ACTIVE",
73
- dda: "REGISTERED",
74
- seniority: ">= 0.3 year",
75
- working_status: "ACTIVE",
103
+ const getRequriedCriteria = (productType) => {
104
+ if (productType === PRODUCT_TYPE.EWA_01) {
105
+ return BASE_REQUIRED_CRITERIA;
106
+ }
107
+ if (productType === PRODUCT_TYPE.EWA_02) {
108
+ return EWA_02_CRITERIA;
109
+ }
110
+ if (productType === PRODUCT_TYPE.EWA_03) {
111
+ return EWA_03_CRITERIA;
112
+ }
113
+ return BASE_REQUIRED_CRITERIA;
76
114
  };
115
+ const requiredCriteria = getRequriedCriteria(productType);
77
116
  const returnData = {
78
117
  current_information: currentInformation,
79
118
  valid_information: requiredCriteria,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-mcp",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "Mcp server for Gm",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,6 +1,8 @@
1
1
  import axios from "axios";
2
2
  import { Gimo } from "./types";
3
3
  import { getEnv } from "../env";
4
+ import { PayPeriod } from "./types/pay-period";
5
+ import { TimeSheet } from "./types/time-keeper";
4
6
 
5
7
  export async function getAccessToken() {
6
8
  const url = `${getEnv().DASH_URL}/api/v1/auth/admin/login`;
@@ -33,6 +35,44 @@ export async function findCustomerEWAByPhonenumber(phoneNumber: string) {
33
35
  return findCustomerEWAById(foundedCustomer.customer_id);
34
36
  }
35
37
 
38
+ export async function getPayPeriods(params: { orgId: number; parnterId: number }) {
39
+ const { orgId, parnterId } = params;
40
+ const url = `${getEnv().DASH_URL}/api/v1/admin/partners/${parnterId}/pay-periods`;
41
+ const access_token = await getAccessToken();
42
+ const customer = await axios
43
+ .get<PayPeriod[]>(url, {
44
+ headers: {
45
+ Authorization: "Bearer " + access_token,
46
+ },
47
+ params: {
48
+ orgId,
49
+ sort: "start_date,desc",
50
+ },
51
+ })
52
+ .then((res) => res.data);
53
+ // Select first customer
54
+ return customer || null;
55
+ }
56
+
57
+ export async function getTimeSheets(params: { payPeriodId: number; employeeId: number }) {
58
+ const { payPeriodId, employeeId } = params;
59
+ const url = `${getEnv().DASH_URL}/api/v2/admin/time-sheets/by-period`;
60
+ const access_token = await getAccessToken();
61
+ const customer = await axios
62
+ .get<TimeSheet[]>(url, {
63
+ headers: {
64
+ Authorization: "Bearer " + access_token,
65
+ },
66
+ params: {
67
+ employeeId,
68
+ payPeriodId,
69
+ },
70
+ })
71
+ .then((res) => res.data);
72
+ // Select first customer
73
+ return customer || null;
74
+ }
75
+
36
76
  export async function getEmployeeByCustomerId(customerId: number) {
37
77
  const url = `${getEnv().DASH_URL}/api/v1/admin/customers/${customerId}/employee-info`;
38
78
  const access_token = await getAccessToken();
@@ -0,0 +1,42 @@
1
+ export interface PayPeriod {
2
+ id: number;
3
+ start_date: string;
4
+ end_date: string;
5
+ principal_due_date: string;
6
+ limit_total_enable: boolean;
7
+ limit_total_allowed: any;
8
+ limit_total_accumulated: number;
9
+ config: Config;
10
+ config_name: string;
11
+ created_at: string;
12
+ }
13
+
14
+ export interface Config {
15
+ id: number;
16
+ active: boolean;
17
+ code: string;
18
+ name: string;
19
+ note: string;
20
+ limit_total_enable: boolean;
21
+ limit_total_allowed: any;
22
+ partner_id: number;
23
+ partner_name: string;
24
+ organization_structure_id: number;
25
+ organization_structure_name: string;
26
+ config_type: string;
27
+ month_start_day: number;
28
+ month_start_at: string;
29
+ cycle_start_at: any;
30
+ cycle_day_num: any;
31
+ created_at: string;
32
+ amount_for_preview: number;
33
+ editable: boolean;
34
+ marker: string;
35
+ duration_type: string;
36
+ extend: number;
37
+ time: string;
38
+ pay_period_num_from_current: number;
39
+ path: any;
40
+ version_number: number;
41
+ previous_config_id: any;
42
+ }
@@ -0,0 +1,11 @@
1
+ export interface TimeSheet {
2
+ id: string;
3
+ employee_id: number;
4
+ employee_full_name: any;
5
+ employee_code: any;
6
+ date: string;
7
+ value: number;
8
+ created_at: string;
9
+ check_in: string;
10
+ check_out: string;
11
+ }
@@ -1,5 +1,12 @@
1
1
  import { CallToolResult } from "@modelcontextprotocol/sdk/types";
2
- import { findCustomerEWAByPhonenumber, getEmployeeByCustomerId } from "../services/gimo.service";
2
+ import {
3
+ findCustomerEWAByPhonenumber,
4
+ getEmployeeByCustomerId,
5
+ getPayPeriods,
6
+ getTimeSheets,
7
+ } from "../services/gimo.service";
8
+ import { PayPeriod } from "../services/types/pay-period";
9
+ import { TimeSheet } from "../services/types/time-keeper";
3
10
 
4
11
  const PRODUCT_TYPE = {
5
12
  EWA_01: "EWA_01",
@@ -41,6 +48,38 @@ function getProductType(options: { partner_onboard_method: string; debt_collecti
41
48
  return null;
42
49
  }
43
50
 
51
+ export const EMPLOYEE_STATUS_MAPS: Record<string, any> = {
52
+ ACTIVE: "Đang làm việc",
53
+ SUSPEND__WAITING_TO_APPROVE: "Chờ công đoàn phê duyệt",
54
+ SUSPEND__MATERNITY_LEAVE: "Nhân sự nghỉ thai sản",
55
+ SUSPEND__UNPAID_LEAVE: "Nhân sự nghỉ không lương",
56
+ SUSPEND__RE_UPLOAD_ACCOUNT_STATEMENT: "Chờ cập nhật chứng minh thu nhập",
57
+ SUSPEND__WAITING_APPRAISALS_ACCOUNT_STATEMENT: "Chờ phê duyệt chứng minh thu nhập",
58
+ SUSPEND__DEFAULT: "Tạm nghỉ",
59
+ INACTIVE: "Nghỉ việc",
60
+ };
61
+
62
+ const BASE_REQUIRED_CRITERIA = {
63
+ ewa_status: "ACTIVE",
64
+ seniority: ">= 0.3 year",
65
+ working_status: EMPLOYEE_STATUS_MAPS.ACTIVE,
66
+ longest_overdue_bill: "<=10 days",
67
+ outstanding_balance: "0",
68
+ parnter_contract_expirity: "Not yet expired",
69
+ time_sheet: "The data exists",
70
+ geofencing_status: "??",
71
+ };
72
+
73
+ const EWA_02_CRITERIA = {
74
+ ...BASE_REQUIRED_CRITERIA,
75
+ dda: "REGISTERED",
76
+ };
77
+
78
+ const EWA_03_CRITERIA = {
79
+ ...BASE_REQUIRED_CRITERIA,
80
+ dda: "REGISTERED",
81
+ };
82
+
44
83
  export async function accessibleTool(phoneNumber: string): Promise<CallToolResult> {
45
84
  try {
46
85
  const customer = await findCustomerEWAByPhonenumber(phoneNumber);
@@ -48,6 +87,15 @@ export async function accessibleTool(phoneNumber: string): Promise<CallToolResul
48
87
  throw "Customer not found";
49
88
  }
50
89
  const { employee, partner } = await getEmployeeByCustomerId(customer.customer_id);
90
+ let periods: PayPeriod[] = [];
91
+ let timeSheets: TimeSheet[] = [];
92
+ if (employee) {
93
+ const payPeriods = await getPayPeriods({ orgId: employee?.organization_id, parnterId: employee.partner_id });
94
+ if (payPeriods?.length) {
95
+ periods = payPeriods;
96
+ timeSheets = await getTimeSheets({ payPeriodId: payPeriods[0].id, employeeId: employee.id });
97
+ }
98
+ }
51
99
  const { debt_collection, onboard_method } = partner || {};
52
100
 
53
101
  const productType = getProductType({
@@ -59,17 +107,26 @@ export async function accessibleTool(phoneNumber: string): Promise<CallToolResul
59
107
  ewa_status: customer?.ewa_status,
60
108
  dda: customer?.dda_status,
61
109
  seniority: employee?.seniority,
62
- working_status: employee?.status,
110
+ working_status: EMPLOYEE_STATUS_MAPS[employee?.status || "ACTIVE"],
63
111
  product_type: productType,
112
+ time_sheet: timeSheets?.length ? "The data exists" : "The data does't exists",
64
113
  };
65
114
 
66
- const requiredCriteria: Record<string, any> = {
67
- ewa_status: "ACTIVE",
68
- dda: "REGISTERED",
69
- seniority: ">= 0.3 year",
70
- working_status: "ACTIVE",
115
+ const getRequriedCriteria = (productType: keyof typeof PRODUCT_TYPE | null) => {
116
+ if (productType === PRODUCT_TYPE.EWA_01) {
117
+ return BASE_REQUIRED_CRITERIA;
118
+ }
119
+ if (productType === PRODUCT_TYPE.EWA_02) {
120
+ return EWA_02_CRITERIA;
121
+ }
122
+ if (productType === PRODUCT_TYPE.EWA_03) {
123
+ return EWA_03_CRITERIA;
124
+ }
125
+ return BASE_REQUIRED_CRITERIA;
71
126
  };
72
127
 
128
+ const requiredCriteria: Record<string, any> = getRequriedCriteria(productType);
129
+
73
130
  const returnData = {
74
131
  current_information: currentInformation,
75
132
  valid_information: requiredCriteria,