storemw-core-api 1.0.136 → 1.0.138

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.
Files changed (44) hide show
  1. package/dist/app.js +1 -0
  2. package/dist/app.js.map +1 -1
  3. package/dist/controllers/auth/authController.js +81 -49
  4. package/dist/controllers/auth/authController.js.map +1 -1
  5. package/dist/controllers/index.d.ts +1 -0
  6. package/dist/controllers/index.js +5 -2
  7. package/dist/controllers/index.js.map +1 -1
  8. package/dist/controllers/user/userMeController.d.ts +6 -0
  9. package/dist/controllers/user/userMeController.js +411 -0
  10. package/dist/controllers/user/userMeController.js.map +1 -0
  11. package/dist/lib/service_factory/ServiceFactory.d.ts +5 -0
  12. package/dist/lib/service_factory/ServiceFactory.js +5 -0
  13. package/dist/lib/service_factory/ServiceFactory.js.map +1 -1
  14. package/dist/middlewares/route/index.d.ts +1 -0
  15. package/dist/middlewares/route/index.js +5 -4
  16. package/dist/middlewares/route/index.js.map +1 -1
  17. package/dist/middlewares/route/validateUserMe.d.ts +3 -0
  18. package/dist/middlewares/route/validateUserMe.js +21 -0
  19. package/dist/middlewares/route/validateUserMe.js.map +1 -0
  20. package/dist/routes/index.d.ts +1 -0
  21. package/dist/routes/index.js +3 -1
  22. package/dist/routes/index.js.map +1 -1
  23. package/dist/routes/user/userMeRoutes.d.ts +2 -0
  24. package/dist/routes/user/userMeRoutes.js +13 -0
  25. package/dist/routes/user/userMeRoutes.js.map +1 -0
  26. package/dist/schema/middleware/route/schemaAccessControl.d.ts +2 -2
  27. package/dist/schema/payload/auth/schemaAuthToken.d.ts +59 -7
  28. package/dist/schema/payload/auth/schemaAuthToken.js +12 -3
  29. package/dist/schema/payload/auth/schemaAuthToken.js.map +1 -1
  30. package/dist/schema/payload/index.d.ts +2 -2
  31. package/dist/schema/payload/index.js +3 -2
  32. package/dist/schema/payload/index.js.map +1 -1
  33. package/dist/schema/payload/injection_field/schemaInjectionField.d.ts +16 -16
  34. package/dist/services/auth/AuthService.d.ts +1 -2
  35. package/dist/services/auth/AuthService.js +78 -40
  36. package/dist/services/auth/AuthService.js.map +1 -1
  37. package/dist/services/index.d.ts +2 -0
  38. package/dist/services/index.js +3 -1
  39. package/dist/services/index.js.map +1 -1
  40. package/dist/services/injection_field/InjectionFieldService.d.ts +3 -3
  41. package/dist/services/user/UserMeService.d.ts +25 -0
  42. package/dist/services/user/UserMeService.js +274 -0
  43. package/dist/services/user/UserMeService.js.map +1 -0
  44. package/package.json +1 -1
@@ -24,46 +24,84 @@ const AuthService = (props) => {
24
24
  return ["worker_injection_fields"];
25
25
  return [];
26
26
  };
27
- const getAuthToken = async ({ authType, data, accountId = 0, accountCode = "" }) => {
27
+ const validateAuthAccount = async (accountCode) => {
28
+ if (accountCode === "") {
29
+ return 0;
30
+ }
31
+ // check if the accountId & accountCode is not empty
32
+ // if (!accountId && !accountCode) throwError(`accountId or accountCode is required`)
33
+ let selectAccountId = 0;
34
+ // check account id is choose
35
+ // if (selectAccountId === 0) {
36
+ const globalAccountService = (0, services_1.AccountService)({ ...rest, isOperator: true });
37
+ // use account code to find the account id
38
+ if (accountCode) {
39
+ let { data: responseAcc } = await globalAccountService.listAccounts({
40
+ limit: 1,
41
+ offset: 0,
42
+ sortfield: `${models_1.ModelAccountFields.account_id}`,
43
+ sortorder: `ASC`,
44
+ filters: [{
45
+ field: `${models_1.ModelAccountFields.account_code}`,
46
+ operator: `=`,
47
+ value: `${accountCode}`,
48
+ }],
49
+ datatypes: []
50
+ });
51
+ selectAccountId = responseAcc.length > 0 ? responseAcc[0].account_id : "";
52
+ let selectAccountStatus = responseAcc.length > 0 ? responseAcc[0].account_status : "";
53
+ if (selectAccountStatus !== true)
54
+ (0, utils_1.throwError)(`Inactive account: ${accountCode}`);
55
+ }
56
+ if (!selectAccountId) {
57
+ (0, utils_1.throwError)(`Invalid account code: ${accountCode}`);
58
+ }
59
+ // }
60
+ return Number(selectAccountId ?? 0);
61
+ };
62
+ const getAuthToken = async ({ authType, data, accountCode = "" }) => {
28
63
  let _rest = rest;
29
- // check the option pass in using account id or account code
64
+ let _accountId = 0;
30
65
  if (authType !== "operator") {
31
- // _rest.accountId = accountId
32
- // check if the accountId & accountCode is not empty
33
- if (!accountId && !accountCode)
34
- (0, utils_1.throwError)(`accountId or accountCode is required`);
35
- let selectAccountId = `${accountId}`;
36
- // check account id is choose
37
- if (selectAccountId === "0") {
38
- const globalAccountService = (0, services_1.AccountService)({ ...rest, isOperator: true });
39
- // use account code to find the account id
40
- if (accountCode) {
41
- let { data: responseAcc } = await globalAccountService.listAccounts({
42
- limit: 1,
43
- offset: 0,
44
- sortfield: `${models_1.ModelAccountFields.account_id}`,
45
- sortorder: `ASC`,
46
- filters: [{
47
- field: `${models_1.ModelAccountFields.account_code}`,
48
- operator: `=`,
49
- value: `${accountCode}`,
50
- }],
51
- datatypes: []
52
- });
53
- selectAccountId = responseAcc.length > 0 ? responseAcc[0].account_id : "";
54
- let selectAccountStatus = responseAcc.length > 0 ? responseAcc[0].account_status : "";
55
- if (selectAccountStatus !== true)
56
- (0, utils_1.throwError)(`Inactive account: ${accountCode}`);
57
- }
58
- if (!selectAccountId) {
59
- (0, utils_1.throwError)(`Invalid account code: ${accountCode}`);
60
- }
61
- }
62
- _rest.accountId = Number(selectAccountId);
63
- }
64
- else {
65
- _rest.accountId = accountId;
66
+ _accountId = await validateAuthAccount(accountCode);
66
67
  }
68
+ // _rest.accountId = accountId
69
+ _rest.accountId = _accountId;
70
+ // check the option pass in using account id or account code
71
+ // if (authType !== "operator") {
72
+ // _rest.accountId = accountId
73
+ // // check if the accountId & accountCode is not empty
74
+ // if (!accountId && !accountCode) throwError(`accountId or accountCode is required`)
75
+ // let selectAccountId = `${accountId}`
76
+ // // check account id is choose
77
+ // if (selectAccountId === "0") {
78
+ // const globalAccountService = AccountService({ ...rest, isOperator: true })
79
+ // // use account code to find the account id
80
+ // if (accountCode) {
81
+ // let { data: responseAcc } = await globalAccountService.listAccounts({
82
+ // limit: 1,
83
+ // offset: 0,
84
+ // sortfield: `${ModelAccountFields.account_id}`,
85
+ // sortorder: `ASC`,
86
+ // filters: [{
87
+ // field: `${ModelAccountFields.account_code}`,
88
+ // operator: `=`,
89
+ // value: `${accountCode}`,
90
+ // }],
91
+ // datatypes: []
92
+ // })
93
+ // selectAccountId = responseAcc.length > 0 ? responseAcc[0].account_id : ""
94
+ // let selectAccountStatus = responseAcc.length > 0 ? responseAcc[0].account_status : ""
95
+ // if (selectAccountStatus !== true) throwError(`Inactive account: ${accountCode}`)
96
+ // }
97
+ // if (!selectAccountId) {
98
+ // throwError(`Invalid account code: ${accountCode}`)
99
+ // }
100
+ // }
101
+ // _rest.accountId = Number(selectAccountId)
102
+ // } else {
103
+ // _rest.accountId = accountId
104
+ // }
67
105
  const userService = (0, services_1.UserService)({ userType: authType, ...rest });
68
106
  const accountService = (0, services_1.AccountService)({ ...rest, isOperator: true });
69
107
  const locationService = (0, services_1.LocationService)({ ...rest, locationType: "location" });
@@ -84,7 +122,7 @@ const AuthService = (props) => {
84
122
  limit: 1,
85
123
  offset: 0,
86
124
  sortfield: "user_id",
87
- sortorder: "ASC",
125
+ sortorder: "DESC",
88
126
  filters: [
89
127
  { field: "username", operator: "=", value: `${data["username"]}` },
90
128
  { field: "user_type", operator: "=", value: `${authType}` }
@@ -95,7 +133,7 @@ const AuthService = (props) => {
95
133
  foundUser = foundOtherUser.length > 0 ? foundOtherUser[0] : {};
96
134
  }
97
135
  if (!foundUser?.user_id) {
98
- throw Error(`Invalid username: ${data["username"]} `);
136
+ throw Error(`Invalid username: ${data["username"]}`);
99
137
  }
100
138
  let user = foundUser;
101
139
  // foundUser.length > 0 ? foundUser[0] : {}
@@ -107,7 +145,7 @@ const AuthService = (props) => {
107
145
  throw error;
108
146
  }
109
147
  if (decryptedPass === false) {
110
- throw Error(`Invalid credential: ${data["username"]} `);
148
+ throw Error(`Invalid credential: ${data["username"]}`);
111
149
  }
112
150
  // dont show out to result
113
151
  delete user.password;
@@ -1 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IAAI,SAAS,GAAU,EAAE,CAAA;QAEzB,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACzB,MAAM,WAAW,GAAsB;gBACnC,KAAK,EAAE,GAAG;gBACV,MAAM,EAAE,CAAC;gBACT,SAAS,EAAE,aAAa;gBACxB,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,CAAC;wBACN,KAAK,EAAE,aAAa;wBACpB,QAAQ,EAAE,UAAU;wBACpB,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;qBAChD,CAAC;gBACF,SAAS,EAAE,EAAE;aAChB,CAAA;YAED,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,eAAe,CAAC,aAAa,CAAC,WAAW,CAAC,CAAA;YACjE,SAAS,GAAG,IAAI,CAAA;QACpB,CAAC;QAED,OAAO;YACH,KAAK,EAAE,SAAS;YAChB,OAAO;YACP,IAAI;YACJ,cAAc,EAAE,SAAS;YACzB,qBAAqB;YACrB,WAAW;YACX,IAAI;YACJ,cAAc;YACd,uBAAuB;YACvB,IAAI;YACJ,KAAK;YACL,mBAAmB;YACnB,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;YACjC,cAAc;SACjB,CAAA;IACL,CAAC,CAAC;IAEF,OAAO;QACH,YAAY;QACZ,eAAe,EAAf,uBAAe;KAClB,CAAA;AAEL,CAAC,CAAA;AA1LY,QAAA,WAAW,eA0LvB","sourcesContent":["// import { QueryList, QueryGet } from \"@/schema/common\";\nimport { DefaultServiceProps, throwError } from \"@/utils\";\nimport {\n UserService,\n // UserGetProps,\n UserType,\n UserListProps,\n // userTypes,\n AccountService,\n LocationService,\n LocationListProps\n} from \"@/services\";\n\nimport jwt, { JwtPayload } from \"jsonwebtoken\";\n\nimport { generateAuthToken, verifyPassword, verifyAuthToken, hashPassword } from \"@/utils\"\nimport { ModelAccountFields, ModelUserFields, UserModel } from \"@/models\";\n\nexport const authTypes = {\n operator: \"operator\",\n administrator: \"administrator\",\n worker: \"worker\",\n customer: \"customer\",\n member: \"member\",\n} as const\n\nexport type AuthType = typeof authTypes[keyof typeof authTypes]\n\nexport type AuthJwtToken = JwtPayload & {\n user?: { id: number, user_id: number, user_type: AuthType };\n account?: { id: number, account_id: number };\n};\n\nexport type AuthServiceProps = DefaultServiceProps & {\n secretKey: string,\n authType: AuthType\n};\n\nexport type AuthGetTokenProps = {\n authType: AuthType,\n accountId?: number,\n accountCode?: string,\n data:\n // get token\n {\n username: string,\n password: string\n }\n};\n\nexport const AuthService = (props: AuthServiceProps) => {\n\n const {\n secretKey,\n authType = \"administrator\",\n ...rest\n } = props\n\n const getUserInjectionFieldName = (authType: AuthType) => {\n\n if (authType === \"administrator\") return [\"administrator_injection_fields\"]\n if (authType === \"customer\") return [\"customer_injection_fields\"]\n if (authType === \"worker\") return [\"worker_injection_fields\"]\n\n return []\n }\n\n const getAuthToken = async ({ authType, data, accountId = 0, accountCode = \"\" }: AuthGetTokenProps) => {\n\n let _rest = rest\n\n // check the option pass in using account id or account code\n if (authType !== \"operator\") {\n // _rest.accountId = accountId\n\n // check if the accountId & accountCode is not empty\n if (!accountId && !accountCode) throwError(`accountId or accountCode is required`)\n\n let selectAccountId = `${accountId}`\n\n // check account id is choose \n if (selectAccountId === \"0\") {\n\n const globalAccountService = AccountService({ ...rest, isOperator: true })\n\n // use account code to find the account id\n if (accountCode) {\n\n let { data: responseAcc } = await globalAccountService.listAccounts({\n limit: 1,\n offset: 0,\n sortfield: `${ModelAccountFields.account_id}`,\n sortorder: `ASC`,\n filters: [{\n field: `${ModelAccountFields.account_code}`,\n operator: `=`,\n value: `${accountCode}`,\n }],\n datatypes: []\n })\n\n selectAccountId = responseAcc.length > 0 ? responseAcc[0].account_id : \"\"\n let selectAccountStatus = responseAcc.length > 0 ? responseAcc[0].account_status : \"\"\n\n if (selectAccountStatus !== true) throwError(`Inactive account: ${accountCode}`)\n\n }\n\n if (!selectAccountId) {\n throwError(`Invalid account code: ${accountCode}`)\n }\n\n }\n\n _rest.accountId = Number(selectAccountId)\n\n } else {\n _rest.accountId = accountId\n }\n\n const userService = UserService({ userType: authType as UserType, ...rest })\n const accountService = AccountService({ ...rest, isOperator: true })\n const locationService = LocationService({ ...rest, locationType: \"location\" })\n\n let foundUser: any = {}\n\n // only for operator & administrator\n if (authType === \"operator\" || authType === \"administrator\") {\n\n // const operatorService = UserService({ ...rest })\n\n const _user = await userService.getUserByUsername({\n username: `${data[\"username\"]}`,\n includePassword: true,\n datatypes: getUserInjectionFieldName(authType) as any\n })\n\n foundUser = _user\n\n } else { // other user type\n\n let payload: UserListProps = {\n includePassword: true,\n limit: 1,\n offset: 0,\n sortfield: \"user_id\",\n sortorder: \"ASC\",\n filters: [\n { field: \"username\", operator: \"=\", value: `${data[\"username\"]}` },\n { field: \"user_type\", operator: \"=\", value: `${authType}` }\n ],\n datatypes: getUserInjectionFieldName(authType)\n }\n\n const { data: foundOtherUser } = await userService.listUsers(payload)\n\n foundUser = foundOtherUser.length > 0 ? foundOtherUser[0] : {}\n\n }\n\n if (!foundUser?.user_id) {\n throw Error(`Invalid username: ${data[\"username\"]} `)\n }\n\n let user = foundUser\n // foundUser.length > 0 ? foundUser[0] : {}\n\n let decryptedPass: boolean\n\n try {\n decryptedPass = await verifyPassword(data.password, user.password)\n } catch (error) {\n throw error\n }\n\n if (decryptedPass === false) {\n throw Error(`Invalid credential: ${data[\"username\"]} `)\n }\n\n // dont show out to result\n delete user.password\n\n let account: any = {}\n\n if (_rest.accountId && authType !== \"operator\") {\n account = await accountService.getAccount({ id: Number(_rest.accountId), datatypes: [] })\n }\n\n const authToken = generateAuthToken(user, account, secretKey)\n\n // get the locations for user\n const locationIds = user?.location_id ? user.location_id.split(\", \") : []\n\n let locations: any[] = []\n\n if (locationIds.length > 0) {\n const listPayload: LocationListProps = {\n limit: 100,\n offset: 0,\n sortfield: \"location_id\",\n sortorder: \"ASC\",\n filters: [{\n field: \"location_id\",\n operator: \"where_in\",\n value: locationIds.map((i: any) => Number(i))\n }],\n datatypes: []\n }\n\n const { data } = await locationService.listLocations(listPayload)\n locations = data\n }\n\n return {\n token: authToken,\n account,\n user,\n user_locations: locations,\n // parent_user_id: 0,\n // roles: [\n // {\n // id: 23,\n // role_name: \"123\"\n // }\n // ],\n // permissions: [],\n is_owner: Boolean(user?.is_owner),\n // owner_id: 0\n }\n };\n\n return {\n getAuthToken,\n verifyAuthToken,\n }\n\n}\n\n"]}
1
+ {"version":3,"file":"AuthService.js","sourceRoot":"","sources":["../../../src/services/auth/AuthService.ts"],"names":[],"mappings":";;;AAAA,yDAAyD;AACzD,mCAA0D;AAC1D,yCASoB;AAIpB,mCAA0F;AAC1F,qCAA0E;AAE7D,QAAA,SAAS,GAAG;IACrB,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,eAAe;IAC9B,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;CACV,CAAA;AA0BH,MAAM,WAAW,GAAG,CAAC,KAAuB,EAAE,EAAE;IAEnD,MAAM,EACF,SAAS,EACT,QAAQ,GAAG,eAAe,EAC1B,GAAG,IAAI,EACV,GAAG,KAAK,CAAA;IAET,MAAM,yBAAyB,GAAG,CAAC,QAAkB,EAAE,EAAE;QAErD,IAAI,QAAQ,KAAK,eAAe;YAAE,OAAO,CAAC,gCAAgC,CAAC,CAAA;QAC3E,IAAI,QAAQ,KAAK,UAAU;YAAE,OAAO,CAAC,2BAA2B,CAAC,CAAA;QACjE,IAAI,QAAQ,KAAK,QAAQ;YAAE,OAAO,CAAC,yBAAyB,CAAC,CAAA;QAE7D,OAAO,EAAE,CAAA;IACb,CAAC,CAAA;IAED,MAAM,mBAAmB,GAAG,KAAK,EAAE,WAAmB,EAAE,EAAE;QAEtD,IAAI,WAAW,KAAK,EAAE,EAAE,CAAC;YACrB,OAAO,CAAC,CAAA;QACZ,CAAC;QAED,oDA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CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;qBAChD,CAAC;gBACF,SAAS,EAAE,EAAE;aAChB,CAAA;YAED,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,eAAe,CAAC,aAAa,CAAC,WAAW,CAAC,CAAA;YACjE,SAAS,GAAG,IAAI,CAAA;QACpB,CAAC;QAED,OAAO;YACH,KAAK,EAAE,SAAS;YAChB,OAAO;YACP,IAAI;YACJ,cAAc,EAAE,SAAS;YACzB,qBAAqB;YACrB,WAAW;YACX,IAAI;YACJ,cAAc;YACd,uBAAuB;YACvB,IAAI;YACJ,KAAK;YACL,mBAAmB;YACnB,QAAQ,EAAE,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;YACjC,cAAc;SACjB,CAAA;IACL,CAAC,CAAC;IAEF,OAAO;QACH,YAAY;QACZ,eAAe,EAAf,uBAAe;KAClB,CAAA;AAEL,CAAC,CAAA;AAnPY,QAAA,WAAW,eAmPvB","sourcesContent":["// import { QueryList, QueryGet } from \"@/schema/common\";\nimport { DefaultServiceProps, throwError } from \"@/utils\";\nimport {\n UserService,\n // UserGetProps,\n UserType,\n UserListProps,\n // userTypes,\n AccountService,\n LocationService,\n LocationListProps\n} from \"@/services\";\n\nimport jwt, { JwtPayload } from \"jsonwebtoken\";\n\nimport { generateAuthToken, verifyPassword, verifyAuthToken, hashPassword } from \"@/utils\"\nimport { ModelAccountFields, ModelUserFields, UserModel } from \"@/models\";\n\nexport const authTypes = {\n operator: \"operator\",\n administrator: \"administrator\",\n worker: \"worker\",\n customer: \"customer\",\n member: \"member\",\n} as const\n\nexport type AuthType = typeof authTypes[keyof typeof authTypes]\n\nexport type AuthJwtToken = JwtPayload & {\n user?: { id: number, user_id: number, user_type: AuthType };\n account?: { id: number, account_id: number };\n};\n\nexport type AuthServiceProps = DefaultServiceProps & {\n secretKey: string,\n authType: AuthType\n};\n\nexport type AuthGetTokenProps = {\n authType: AuthType,\n // accountId?: number,\n accountCode?: string,\n data:\n // get token\n {\n username: string,\n password: string\n }\n};\n\nexport const AuthService = (props: AuthServiceProps) => {\n\n const {\n secretKey,\n authType = \"administrator\",\n ...rest\n } = props\n\n const getUserInjectionFieldName = (authType: AuthType) => {\n\n if (authType === \"administrator\") return [\"administrator_injection_fields\"]\n if (authType === \"customer\") return [\"customer_injection_fields\"]\n if (authType === \"worker\") return [\"worker_injection_fields\"]\n\n return []\n }\n\n const validateAuthAccount = async (accountCode: string) => {\n\n if (accountCode === \"\") {\n return 0\n }\n\n // check if the accountId & accountCode is not empty\n // if (!accountId && !accountCode) throwError(`accountId or accountCode is required`)\n\n let selectAccountId = 0\n\n // check account id is choose \n // if (selectAccountId === 0) {\n\n const globalAccountService = AccountService({ ...rest, isOperator: true })\n\n // use account code to find the account id\n if (accountCode) {\n\n let { data: responseAcc } = await globalAccountService.listAccounts({\n limit: 1,\n offset: 0,\n sortfield: `${ModelAccountFields.account_id}`,\n sortorder: `ASC`,\n filters: [{\n field: `${ModelAccountFields.account_code}`,\n operator: `=`,\n value: `${accountCode}`,\n }],\n datatypes: []\n })\n\n selectAccountId = responseAcc.length > 0 ? responseAcc[0].account_id : \"\"\n let selectAccountStatus = responseAcc.length > 0 ? responseAcc[0].account_status : \"\"\n\n if (selectAccountStatus !== true) throwError(`Inactive account: ${accountCode}`)\n\n }\n\n if (!selectAccountId) {\n throwError(`Invalid account code: ${accountCode}`)\n }\n\n // }\n\n return Number(selectAccountId ?? 0)\n\n }\n\n const getAuthToken = async ({ authType, data, accountCode = \"\" }: AuthGetTokenProps) => {\n\n let _rest = rest\n let _accountId = 0\n\n if (authType !== \"operator\") {\n _accountId = await validateAuthAccount(accountCode)\n }\n\n // _rest.accountId = accountId\n _rest.accountId = _accountId\n\n // check the option pass in using account id or account code\n // if (authType !== \"operator\") {\n // _rest.accountId = accountId\n\n // // check if the accountId & accountCode is not empty\n // if (!accountId && !accountCode) throwError(`accountId or accountCode is required`)\n\n // let selectAccountId = `${accountId}`\n\n // // check account id is choose \n // if (selectAccountId === \"0\") {\n\n // const globalAccountService = AccountService({ ...rest, isOperator: true })\n\n // // use account code to find the account id\n // if (accountCode) {\n\n // let { data: responseAcc } = await globalAccountService.listAccounts({\n // limit: 1,\n // offset: 0,\n // sortfield: `${ModelAccountFields.account_id}`,\n // sortorder: `ASC`,\n // filters: [{\n // field: `${ModelAccountFields.account_code}`,\n // operator: `=`,\n // value: `${accountCode}`,\n // }],\n // datatypes: []\n // })\n\n // selectAccountId = responseAcc.length > 0 ? responseAcc[0].account_id : \"\"\n // let selectAccountStatus = responseAcc.length > 0 ? responseAcc[0].account_status : \"\"\n\n // if (selectAccountStatus !== true) throwError(`Inactive account: ${accountCode}`)\n\n // }\n\n // if (!selectAccountId) {\n // throwError(`Invalid account code: ${accountCode}`)\n // }\n\n // }\n\n // _rest.accountId = Number(selectAccountId)\n\n // } else {\n // _rest.accountId = accountId\n // }\n\n const userService = UserService({ userType: authType as UserType, ...rest })\n const accountService = AccountService({ ...rest, isOperator: true })\n const locationService = LocationService({ ...rest, locationType: \"location\" })\n\n let foundUser: any = {}\n\n // only for operator & administrator\n if (authType === \"operator\" || authType === \"administrator\") {\n\n // const operatorService = UserService({ ...rest })\n\n const _user = await userService.getUserByUsername({\n username: `${data[\"username\"]}`,\n includePassword: true,\n datatypes: getUserInjectionFieldName(authType) as any\n })\n\n foundUser = _user\n\n } else { // other user type\n\n let payload: UserListProps = {\n includePassword: true,\n limit: 1,\n offset: 0,\n sortfield: \"user_id\",\n sortorder: \"DESC\",\n filters: [\n { field: \"username\", operator: \"=\", value: `${data[\"username\"]}` },\n { field: \"user_type\", operator: \"=\", value: `${authType}` }\n ],\n datatypes: getUserInjectionFieldName(authType)\n }\n\n const { data: foundOtherUser } = await userService.listUsers(payload)\n\n foundUser = foundOtherUser.length > 0 ? foundOtherUser[0] : {}\n\n }\n\n if (!foundUser?.user_id) {\n throw Error(`Invalid username: ${data[\"username\"]}`)\n }\n\n let user = foundUser\n // foundUser.length > 0 ? foundUser[0] : {}\n\n let decryptedPass: boolean\n\n try {\n decryptedPass = await verifyPassword(data.password, user.password)\n } catch (error) {\n throw error\n }\n\n if (decryptedPass === false) {\n throw Error(`Invalid credential: ${data[\"username\"]}`)\n }\n\n // dont show out to result\n delete user.password\n\n let account: any = {}\n\n if (_rest.accountId && authType !== \"operator\") {\n account = await accountService.getAccount({ id: Number(_rest.accountId), datatypes: [] })\n }\n\n const authToken = generateAuthToken(user, account, secretKey)\n\n // get the locations for user\n const locationIds = user?.location_id ? user.location_id.split(\", \") : []\n\n let locations: any[] = []\n\n if (locationIds.length > 0) {\n const listPayload: LocationListProps = {\n limit: 100,\n offset: 0,\n sortfield: \"location_id\",\n sortorder: \"ASC\",\n filters: [{\n field: \"location_id\",\n operator: \"where_in\",\n value: locationIds.map((i: any) => Number(i))\n }],\n datatypes: []\n }\n\n const { data } = await locationService.listLocations(listPayload)\n locations = data\n }\n\n return {\n token: authToken,\n account,\n user,\n user_locations: locations,\n // parent_user_id: 0,\n // roles: [\n // {\n // id: 23,\n // role_name: \"123\"\n // }\n // ],\n // permissions: [],\n is_owner: Boolean(user?.is_owner),\n // owner_id: 0\n }\n };\n\n return {\n getAuthToken,\n verifyAuthToken,\n }\n\n}\n\n"]}
@@ -12,6 +12,8 @@ export { BusinessService } from "../services/business/BusinessService";
12
12
  export type { BusinessServiceProps, Business, BusinessGetProps, BusinessListProps, BusinessCreateProps, BusinessUpdateProps } from "../services/business/BusinessService";
13
13
  export { UserService, userTypes } from "../services/user/UserService";
14
14
  export type { UserServiceProps, UserType, UserGetProps, UserListProps, UserCreateProps, UserUpdateProps, UserRemoveProps, UserReplacePasswordProps } from "../services/user/UserService";
15
+ export { UserMeService } from "../services/user/UserMeService";
16
+ export type { UserMeServiceProps } from "../services/user/UserMeService";
15
17
  export { UserBranchService, userBranchTypes } from "../services/branch/UserBranchService";
16
18
  export type { UserBranchServiceProps, UserBranchType, UserBranchGetProps, UserBranchListProps, UserBranchCreateProps, UserBranchUpdateProps, UserBranchRemoveProps } from "../services/branch/UserBranchService";
17
19
  export { RegionService } from "../services/region/RegionService";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AccessKeyUtilService = exports.ChangePasswordUtilService = exports.SmtpEmailService = exports.oneTimeCodeStatus = exports.oneTimeCodePurposeTypes = exports.oneTimeCodeTypes = exports.OneTimeCodeService = exports.NumberDateSequenceService = exports.injectionFieldDataTypes = exports.injectionFieldTypes = exports.InjectionFieldService = exports.LocationService = exports.FileService = exports.itemTypes = exports.ItemService = exports.DocumentService = exports.RegionService = exports.userBranchTypes = exports.UserBranchService = exports.userTypes = exports.UserService = exports.BusinessService = exports.AccountService = exports.resetPasswordMethods = exports.ResetPasswordService = exports.AccessControlService = exports.accessKeyStatus = exports.accessKeyUserTypes = exports.AccessKeyService = exports.authTypes = exports.AuthService = void 0;
3
+ exports.AccessKeyUtilService = exports.ChangePasswordUtilService = exports.SmtpEmailService = exports.oneTimeCodeStatus = exports.oneTimeCodePurposeTypes = exports.oneTimeCodeTypes = exports.OneTimeCodeService = exports.NumberDateSequenceService = exports.injectionFieldDataTypes = exports.injectionFieldTypes = exports.InjectionFieldService = exports.LocationService = exports.FileService = exports.itemTypes = exports.ItemService = exports.DocumentService = exports.RegionService = exports.userBranchTypes = exports.UserBranchService = exports.UserMeService = exports.userTypes = exports.UserService = exports.BusinessService = exports.AccountService = exports.resetPasswordMethods = exports.ResetPasswordService = exports.AccessControlService = exports.accessKeyStatus = exports.accessKeyUserTypes = exports.AccessKeyService = exports.authTypes = exports.AuthService = void 0;
4
4
  var AuthService_1 = require("../services/auth/AuthService");
5
5
  Object.defineProperty(exports, "AuthService", { enumerable: true, get: function () { return AuthService_1.AuthService; } });
6
6
  Object.defineProperty(exports, "authTypes", { enumerable: true, get: function () { return AuthService_1.authTypes; } });
@@ -20,6 +20,8 @@ Object.defineProperty(exports, "BusinessService", { enumerable: true, get: funct
20
20
  var UserService_1 = require("../services/user/UserService");
21
21
  Object.defineProperty(exports, "UserService", { enumerable: true, get: function () { return UserService_1.UserService; } });
22
22
  Object.defineProperty(exports, "userTypes", { enumerable: true, get: function () { return UserService_1.userTypes; } });
23
+ var UserMeService_1 = require("../services/user/UserMeService");
24
+ Object.defineProperty(exports, "UserMeService", { enumerable: true, get: function () { return UserMeService_1.UserMeService; } });
23
25
  // export { AdministratorService, administratorDataTypes } from "../services/user/AdministratorService"
24
26
  // export type { AdministratorServiceProps, AdministratorGetProps, AdministratorListProps, AdministratorCreateProps, AdministratorUpdateProps, AdministratorRemoveProps } from "../services/user/AdministratorService"
25
27
  // export { OperatorService, operatorDataTypes } from "../services/user/OperatorService"
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,2DAAoE;AAA3D,0GAAA,WAAW,OAAA;AAAE,wGAAA,SAAS,OAAA;AAE/B,2EAA8G;AAArG,oHAAA,gBAAgB,OAAA;AAAE,sHAAA,kBAAkB,OAAA;AAAE,mHAAA,eAAe,OAAA;AAE9D,uFAAqF;AAA5E,4HAAA,oBAAoB,OAAA;AAE7B,uFAA2G;AAAlG,4HAAA,oBAAoB,OAAA;AAAE,4HAAA,oBAAoB,OAAA;AAEnD,oEAAkE;AAAzD,gHAAA,cAAc,OAAA;AAEvB,uEAAqE;AAA5D,kHAAA,eAAe,OAAA;AAGxB,2DAAoE;AAA3D,0GAAA,WAAW,OAAA;AAAE,wGAAA,SAAS,OAAA;AAE/B,sGAAsG;AACtG,qNAAqN;AACrN,uFAAuF;AACvF,kLAAkL;AAElL,yEAAwF;AAA/E,sHAAA,iBAAiB,OAAA;AAAE,oHAAA,eAAe,OAAA;AAE3C,iEAA+D;AAAtD,8GAAA,aAAa,OAAA;AAEtB,uEAAqE;AAA5D,kHAAA,eAAe,OAAA;AAExB,2DAAoE;AAA3D,0GAAA,WAAW,OAAA;AAAE,wGAAA,SAAS,OAAA;AAE/B,2DAAyD;AAAhD,0GAAA,WAAW,OAAA;AAEpB,uEAAqE;AAA5D,kHAAA,eAAe,OAAA;AAExB,0FAAsI;AAA7H,8HAAA,qBAAqB,OAAA;AAAE,4HAAA,mBAAmB,OAAA;AAAE,gIAAA,uBAAuB,OAAA;AAE5E,yFAAuF;AAA9E,sIAAA,yBAAyB,OAAA;AAElC,kFAA8I;AAArI,wHAAA,kBAAkB,OAAA;AAAE,sHAAA,gBAAgB,OAAA;AAAE,6HAAA,uBAAuB,OAAA;AAAE,uHAAA,iBAAiB,OAAA;AAEzF,wEAAsE;AAA7D,oHAAA,gBAAgB,OAAA;AAGzB,wFAAsF;AAA7E,sIAAA,yBAAyB,OAAA;AAElC,8EAA4E;AAAnE,4HAAA,oBAAoB,OAAA","sourcesContent":["export { AuthService, authTypes } from \"@/services/auth/AuthService\"\nexport type { AuthServiceProps, AuthType, AuthJwtToken, AuthGetTokenProps } from \"@/services/auth/AuthService\"\nexport { AccessKeyService, accessKeyUserTypes, accessKeyStatus } from \"@/services/access_key/AccessKeyService\"\nexport type { AccessKeyServiceProps, AccessKeyStatus, AccessKeyUserType, AccessKeyCreateProps, AccessKeyRevokeProps } from \"@/services/access_key/AccessKeyService\"\nexport { AccessControlService } from \"@/services/access_control/AccessControlService\"\nexport type { AccessControlServiceProps, AccessControlScopeOrExtra, AccessControlListOptionsProps } from \"@/services/access_control/AccessControlService\"\nexport { ResetPasswordService, resetPasswordMethods } from \"@/services/reset_password/ResetPasswordService\"\nexport type { ResetPasswordServiceProps, ResetPasswordMethod, ResetPasswordRequestProps, ResetPasswordValidateCodeProps, ResetPasswordPerformProps } from \"@/services/reset_password/ResetPasswordService\"\nexport { AccountService } from \"@/services/account/AccountService\"\nexport type { AccountServiceProps, Account, AccountGetProps, AccountListProps, AccountCreateProps, AccountUpdateProps } from \"@/services/account/AccountService\"\nexport { BusinessService } from \"@/services/business/BusinessService\"\nexport type { BusinessServiceProps, Business, BusinessGetProps, BusinessListProps, BusinessCreateProps, BusinessUpdateProps } from \"@/services/business/BusinessService\"\n\nexport { UserService, userTypes } from \"@/services/user/UserService\"\nexport type { UserServiceProps, UserType, UserGetProps, UserListProps, UserCreateProps, UserUpdateProps, UserRemoveProps, UserReplacePasswordProps } from \"@/services/user/UserService\"\n// export { AdministratorService, administratorDataTypes } from \"@/services/user/AdministratorService\"\n// export type { AdministratorServiceProps, AdministratorGetProps, AdministratorListProps, AdministratorCreateProps, AdministratorUpdateProps, AdministratorRemoveProps } from \"@/services/user/AdministratorService\"\n// export { OperatorService, operatorDataTypes } from \"@/services/user/OperatorService\"\n// export type { OperatorServiceProps, OperatorGetProps, OperatorListProps, OperatorCreateProps, OperatorUpdateProps, OperatorRemoveProps } from \"@/services/user/OperatorService\"\n\nexport { UserBranchService, userBranchTypes } from \"@/services/branch/UserBranchService\"\nexport type { UserBranchServiceProps, UserBranchType, UserBranchGetProps, UserBranchListProps, UserBranchCreateProps, UserBranchUpdateProps, UserBranchRemoveProps } from \"@/services/branch/UserBranchService\"\nexport { RegionService } from \"@/services/region/RegionService\"\nexport type { RegionServiceProps, RegionType, RegionGetProps, RegionCreateProps, RegionListProps, RegionUpdateProps, RegionRemoveProps } from \"@/services/region/RegionService\"\nexport { DocumentService } from \"@/services/document/DocumentService\"\nexport type { DocumentServiceProps, DocumentType, DocumentGetProps, DocumentUpdateProps, DocumentCreateProps, DocumentListProps, DocumentRemoveProps } from \"@/services/document/DocumentService\"\nexport { ItemService, itemTypes } from \"@/services/item/ItemService\"\nexport type { ItemServiceProps, ItemType, ItemGetProps, ItemUpdateProps, ItemCreateProps, ItemListProps, ItemRemoveProps } from \"@/services/item/ItemService\"\nexport { FileService } from \"@/services/file/FileService\"\nexport type { FileImageCompressionOptions, FileVideoCompressionOptions, FileStorageProviderType, FileLocalProviderOptions, FileGoogleCloudProviderOptions, FileAwsS3ProviderOptions, FileCategoryName, FileUploadItem, FileServiceProps, FileGetProps, FileUploadProps, FileCreateProps, FileListProps, FileRemoveProps } from \"@/services/file/FileService\"\nexport { LocationService } from \"@/services/location/LocationService\"\nexport type { LocationServiceProps, LocationType, LocationGetProps, LocationUpdateProps, LocationCreateProps, LocationListProps, LocationRemoveProps } from \"@/services/location/LocationService\"\nexport { InjectionFieldService, injectionFieldTypes, injectionFieldDataTypes } from \"@/services/injection_field/InjectionFieldService\"\nexport type { InjectionFieldModuleRef, InjectionFieldServiceProps, InjectionFieldType, InjectionFieldDataType, InjectionFieldCreateProps, InjectionFieldListProps, InjectionFieldGetProps, InjectionFieldReplaceProps } from \"@/services/injection_field/InjectionFieldService\"\nexport { NumberDateSequenceService } from \"@/services/others/NumberDateSequenceService\"\nexport type { NumberDateSequenceModuleRef, NumberDateSequenceServiceProps, NumberDateSequenceInitProps, NumberDateSequenceCreateProps } from \"@/services/others/NumberDateSequenceService\"\nexport { OneTimeCodeService, oneTimeCodeTypes, oneTimeCodePurposeTypes, oneTimeCodeStatus } from \"@/services/one_time_code/OneTimeCodeService\"\nexport type { OneTimeCodeModuleRef, OneTimeCodeType, OneTimeCodePurposeType, OneTimeCodeStatus, OneTimeCodeServiceProps, OneTimeCodeCreateProps } from \"@/services/one_time_code/OneTimeCodeService\"\nexport { SmtpEmailService } from \"@/services/gateway/SmtpEmailService\"\nexport type { SmtpEmailServiceProps, SmtpEmailSendProps, SmtpEmailTransporterOptions } from \"@/services/gateway/SmtpEmailService\"\n\nexport { ChangePasswordUtilService } from \"@/services/utils/ChangePasswordUtilService\"\nexport type { ChangePasswordUtilServiceProps, ChangePasswordUtilChangeProps } from \"@/services/utils/ChangePasswordUtilService\"\nexport { AccessKeyUtilService } from \"@/services/utils/AccessKeyUtilService\"\nexport type { AccessKeyUtilServiceProps, AccessKeyUtilValidateProps, AccessKeyUtilAccountOwnerProps } from \"@/services/utils/AccessKeyUtilService\""]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;AAAA,2DAAoE;AAA3D,0GAAA,WAAW,OAAA;AAAE,wGAAA,SAAS,OAAA;AAE/B,2EAA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ken, AuthGetTokenProps } from \"@/services/auth/AuthService\"\nexport { AccessKeyService, accessKeyUserTypes, accessKeyStatus } from \"@/services/access_key/AccessKeyService\"\nexport type { AccessKeyServiceProps, AccessKeyStatus, AccessKeyUserType, AccessKeyCreateProps, AccessKeyRevokeProps } from \"@/services/access_key/AccessKeyService\"\nexport { AccessControlService } from \"@/services/access_control/AccessControlService\"\nexport type { AccessControlServiceProps, AccessControlScopeOrExtra, AccessControlListOptionsProps } from \"@/services/access_control/AccessControlService\"\nexport { ResetPasswordService, resetPasswordMethods } from \"@/services/reset_password/ResetPasswordService\"\nexport type { ResetPasswordServiceProps, ResetPasswordMethod, ResetPasswordRequestProps, ResetPasswordValidateCodeProps, ResetPasswordPerformProps } from \"@/services/reset_password/ResetPasswordService\"\nexport { AccountService } from \"@/services/account/AccountService\"\nexport type { AccountServiceProps, Account, AccountGetProps, AccountListProps, AccountCreateProps, AccountUpdateProps } from \"@/services/account/AccountService\"\nexport { BusinessService } from \"@/services/business/BusinessService\"\nexport type { BusinessServiceProps, Business, BusinessGetProps, BusinessListProps, BusinessCreateProps, BusinessUpdateProps } from \"@/services/business/BusinessService\"\n\nexport { UserService, userTypes } from \"@/services/user/UserService\"\nexport type { UserServiceProps, UserType, UserGetProps, UserListProps, UserCreateProps, UserUpdateProps, UserRemoveProps, UserReplacePasswordProps } from \"@/services/user/UserService\"\n\nexport { UserMeService } from \"@/services/user/UserMeService\"\nexport type { UserMeServiceProps } from \"@/services/user/UserMeService\"\n\n// export { AdministratorService, administratorDataTypes } from \"@/services/user/AdministratorService\"\n// export type { AdministratorServiceProps, AdministratorGetProps, AdministratorListProps, AdministratorCreateProps, AdministratorUpdateProps, AdministratorRemoveProps } from \"@/services/user/AdministratorService\"\n// export { OperatorService, operatorDataTypes } from \"@/services/user/OperatorService\"\n// export type { OperatorServiceProps, OperatorGetProps, OperatorListProps, OperatorCreateProps, OperatorUpdateProps, OperatorRemoveProps } from \"@/services/user/OperatorService\"\n\nexport { UserBranchService, userBranchTypes } from \"@/services/branch/UserBranchService\"\nexport type { UserBranchServiceProps, UserBranchType, UserBranchGetProps, UserBranchListProps, UserBranchCreateProps, UserBranchUpdateProps, UserBranchRemoveProps } from \"@/services/branch/UserBranchService\"\nexport { RegionService } from \"@/services/region/RegionService\"\nexport type { RegionServiceProps, RegionType, RegionGetProps, RegionCreateProps, RegionListProps, RegionUpdateProps, RegionRemoveProps } from \"@/services/region/RegionService\"\nexport { DocumentService } from \"@/services/document/DocumentService\"\nexport type { DocumentServiceProps, DocumentType, DocumentGetProps, DocumentUpdateProps, DocumentCreateProps, DocumentListProps, DocumentRemoveProps } from \"@/services/document/DocumentService\"\nexport { ItemService, itemTypes } from \"@/services/item/ItemService\"\nexport type { ItemServiceProps, ItemType, ItemGetProps, ItemUpdateProps, ItemCreateProps, ItemListProps, ItemRemoveProps } from \"@/services/item/ItemService\"\nexport { FileService } from \"@/services/file/FileService\"\nexport type { FileImageCompressionOptions, FileVideoCompressionOptions, FileStorageProviderType, FileLocalProviderOptions, FileGoogleCloudProviderOptions, FileAwsS3ProviderOptions, FileCategoryName, FileUploadItem, FileServiceProps, FileGetProps, FileUploadProps, FileCreateProps, FileListProps, FileRemoveProps } from \"@/services/file/FileService\"\nexport { LocationService } from \"@/services/location/LocationService\"\nexport type { LocationServiceProps, LocationType, LocationGetProps, LocationUpdateProps, LocationCreateProps, LocationListProps, LocationRemoveProps } from \"@/services/location/LocationService\"\nexport { InjectionFieldService, injectionFieldTypes, injectionFieldDataTypes } from \"@/services/injection_field/InjectionFieldService\"\nexport type { InjectionFieldModuleRef, InjectionFieldServiceProps, InjectionFieldType, InjectionFieldDataType, InjectionFieldCreateProps, InjectionFieldListProps, InjectionFieldGetProps, InjectionFieldReplaceProps } from \"@/services/injection_field/InjectionFieldService\"\nexport { NumberDateSequenceService } from \"@/services/others/NumberDateSequenceService\"\nexport type { NumberDateSequenceModuleRef, NumberDateSequenceServiceProps, NumberDateSequenceInitProps, NumberDateSequenceCreateProps } from \"@/services/others/NumberDateSequenceService\"\nexport { OneTimeCodeService, oneTimeCodeTypes, oneTimeCodePurposeTypes, oneTimeCodeStatus } from \"@/services/one_time_code/OneTimeCodeService\"\nexport type { OneTimeCodeModuleRef, OneTimeCodeType, OneTimeCodePurposeType, OneTimeCodeStatus, OneTimeCodeServiceProps, OneTimeCodeCreateProps } from \"@/services/one_time_code/OneTimeCodeService\"\nexport { SmtpEmailService } from \"@/services/gateway/SmtpEmailService\"\nexport type { SmtpEmailServiceProps, SmtpEmailSendProps, SmtpEmailTransporterOptions } from \"@/services/gateway/SmtpEmailService\"\n\nexport { ChangePasswordUtilService } from \"@/services/utils/ChangePasswordUtilService\"\nexport type { ChangePasswordUtilServiceProps, ChangePasswordUtilChangeProps } from \"@/services/utils/ChangePasswordUtilService\"\nexport { AccessKeyUtilService } from \"@/services/utils/AccessKeyUtilService\"\nexport type { AccessKeyUtilServiceProps, AccessKeyUtilValidateProps, AccessKeyUtilAccountOwnerProps } from \"@/services/utils/AccessKeyUtilService\""]}
@@ -42,12 +42,12 @@ declare const modulePrefixMap: {
42
42
  trip: string;
43
43
  administrator: string;
44
44
  worker: string;
45
- customer: string;
45
+ driver: string;
46
46
  member: string;
47
+ agent: string;
48
+ customer: string;
47
49
  supplier: string;
48
- driver: string;
49
50
  retailer: string;
50
- agent: string;
51
51
  };
52
52
  declare const refPrefixMap: {
53
53
  logistic: string;
@@ -0,0 +1,25 @@
1
+ import { DefaultServiceProps } from "../../utils";
2
+ export declare const userTypes: {
3
+ readonly operator: "operator";
4
+ readonly administrator: "administrator";
5
+ readonly worker: "worker";
6
+ readonly supplier: "supplier";
7
+ readonly customer: "customer";
8
+ readonly driver: "driver";
9
+ readonly retailer: "retailer";
10
+ readonly member: "member";
11
+ readonly agent: "agent";
12
+ };
13
+ export type UserType = typeof userTypes[keyof typeof userTypes];
14
+ export type UserMeServiceProps = DefaultServiceProps & {};
15
+ export type UserMeReplacePasswordProps = {
16
+ id: number;
17
+ data: {
18
+ unhashLoginPassword: string;
19
+ };
20
+ isOperator: boolean;
21
+ };
22
+ export declare const UserMeService: (props: UserMeServiceProps) => {
23
+ getUserMe: () => Promise<any>;
24
+ removeUserMe: () => Promise<any>;
25
+ };
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserMeService = exports.userTypes = void 0;
4
+ // import { hashPassword } from "../../utils";
5
+ const lib_1 = require("../../lib");
6
+ const services_1 = require("../../services");
7
+ exports.userTypes = {
8
+ operator: "operator",
9
+ administrator: "administrator",
10
+ worker: "worker",
11
+ supplier: "supplier",
12
+ customer: "customer",
13
+ driver: "driver",
14
+ retailer: "retailer",
15
+ member: "member",
16
+ agent: "agent",
17
+ };
18
+ // const getUpdatePayload = async (
19
+ // userType: UserType,
20
+ // data: UserMeUpdateProps["data"],
21
+ // contact: {
22
+ // countryCode: number,
23
+ // phoneNumber: string
24
+ // }
25
+ // ) => {
26
+ // if ("user" in data) {
27
+ // const newHashPassword = data?.user?.loginPassword ? await hashPassword(data.user.loginPassword) : ""
28
+ // return {
29
+ // [`${ModelUserFields.login_username}`]: data.user.loginUsername,
30
+ // ...(newHashPassword ? { [`${ModelUserFields.login_password}`]: newHashPassword } : {}),
31
+ // [`${ModelUserFields.address}`]: data.user.address,
32
+ // [`${ModelUserFields.contact_country_code}`]: contact.countryCode,
33
+ // [`${ModelUserFields.contact_phone_number}`]: contact.phoneNumber,
34
+ // [`${ModelUserFields.email}`]: data.user.email,
35
+ // [`${ModelUserFields.firstname}`]: data.user.firstname,
36
+ // [`${ModelUserFields.lastname}`]: data.user.lastname,
37
+ // [`${ModelUserFields.status}`]: Boolean(data.user.status),
38
+ // [`${ModelUserFields.user_type}`]: `${userType}`
39
+ // }
40
+ // }
41
+ // return false
42
+ // }
43
+ const UserMeService = (props) => {
44
+ const { ...rest } = props;
45
+ const userType = rest.actionUserType;
46
+ const userId = rest.actionUserId;
47
+ const userService = (0, services_1.UserService)({ ...rest, userType });
48
+ // const userModel = UserModel({ ...rest })
49
+ // const userPropService = UserPropService({ ...rest, userPropType: "LOCATION_ID" })
50
+ // const customerService = CustomerService({ ...rest })
51
+ // const administratorService = AdministratorService({ ...rest })
52
+ // const operatorService = OperatorService({ ...rest })
53
+ // const workerService = WorkerService({ ...rest })
54
+ // const driverService = DriverService({ ...rest })
55
+ // const retailerService = RetailerService({ ...rest })
56
+ // const memberService = MemberService({ ...rest })
57
+ // const agentService = AgentService({ ...rest })
58
+ // const validateAuthToken = (token: string) => {
59
+ // // retrive core configuration
60
+ // const coreConfig = getCoreConfiguration()
61
+ // // const authSecretKey = config.AUTH_SECRET_KEY
62
+ // const authSecretKey = coreConfig.authSecretKey
63
+ // // const jwtData = jwt.verify(token, authSecretKey) as AuthJwtToken; // Verify JWT token
64
+ // const jwtData = verifyAuthToken(token, authSecretKey); // Verify JWT token
65
+ // }
66
+ // const validateAuthAccessKey = async (accessKey: string) => {
67
+ // const accessKeyUtilService = AccessKeyUtilService({
68
+ // accessKeyUserType: "administrator",
69
+ // accountId: 0,
70
+ // actionUserId: 0,
71
+ // actionUserType: "",
72
+ // authToken: "",
73
+ // isOperator: true,
74
+ // })
75
+ // const accessKeyData = await accessKeyUtilService.validateAccessKey({ data: { accessKey } });
76
+ // }
77
+ // const updateMe = async ({ id, data, userType: overrideUserType }: UserMeUpdateProps) => {
78
+ // const _userType = overrideUserType || userType
79
+ // // validate the credential contact no
80
+ // const userLoginUsername = data.user.loginUsername
81
+ // const userLoginPassword = data.user?.loginPassword ?? ""
82
+ // const userContactCountryCode = data.user.contact.countryCode
83
+ // const userContactPhoneNumber = data.user.contact.phoneNumber
84
+ // // validate the contact no only can be digit in text only
85
+ // // validate the country code in prefix
86
+ // // await validateUserContact(userContactCountryCode, userContactPhoneNumber)
87
+ // // validate login username
88
+ // // validateLoginUsernameFormat(userLoginUsername)
89
+ // // validate login password
90
+ // // if (userLoginPassword) {
91
+ // // validateLoginPasswordFormat(userLoginPassword)
92
+ // // }
93
+ // // check the username duplicated?
94
+ // const checkUsername = await userModel.list({
95
+ // limit: 1,
96
+ // offset: 0,
97
+ // orderBy: {
98
+ // [`${ModelUserFields.user_id}`]: "asc"
99
+ // },
100
+ // include: [],
101
+ // where: {
102
+ // [`${ModelUserFields.login_username}`]: data.user.loginUsername,
103
+ // [`${ModelUserFields.isdelete}`]: false,
104
+ // [`${ModelUserFields.istrash}`]: false,
105
+ // [`${ModelUserFields.accountid}`]: rest.accountId,
106
+ // },
107
+ // })
108
+ // // console.log('ch', checkUsername)
109
+ // if (checkUsername.length > 0) {
110
+ // if (Number(checkUsername[0]?.user_id) !== Number(id)) { // if not self user id
111
+ // throwError(`Duplicated username: ${data.user.loginUsername}(${checkUsername[0]?.user_type})`)
112
+ // }
113
+ // }
114
+ // // validation before insertion
115
+ // // if (_userType === "member" && "member" in data) {
116
+ // // }
117
+ // const _data = await getUpdatePayload(
118
+ // _userType,
119
+ // data,
120
+ // {
121
+ // countryCode: userContactCountryCode,
122
+ // phoneNumber: userContactPhoneNumber
123
+ // }
124
+ // )
125
+ // if (!_data) {
126
+ // throw new Error(`Invalid update payload: ${JSON.stringify(_data)}`);
127
+ // }
128
+ // // update user
129
+ // let responseUser = await userModel.update({ id, data: _data })
130
+ // let updateUserId = responseUser.user_id
131
+ // let response: any = {}
132
+ // if (_userType === "customer" && "customer" in data) {
133
+ // let dataCustomer: CustomerUpdateProps["data"] = {
134
+ // customer: {
135
+ // ...data.customer
136
+ // }
137
+ // }
138
+ // await customerService.updateCustomer({ userId: Number(updateUserId), data: dataCustomer })
139
+ // response = await customerService.getCustomer({ id: Number(updateUserId), datatypes: [] })
140
+ // }
141
+ // if (_userType === "operator" && "operator" in data) {
142
+ // let dataOperator: OperatorUpdateProps["data"] = {
143
+ // operator: {
144
+ // ...data.operator
145
+ // }
146
+ // }
147
+ // await operatorService.updateOperator({ userId: Number(updateUserId), data: dataOperator })
148
+ // response = await operatorService.getOperator({ id: Number(updateUserId), datatypes: [] })
149
+ // }
150
+ // if (_userType === "administrator" && "administrator" in data) {
151
+ // let dataCustomer: AdministratorUpdateProps["data"] = {
152
+ // administrator: {
153
+ // ...data.administrator
154
+ // }
155
+ // }
156
+ // await administratorService.updateAdministrator({ userId: Number(updateUserId), data: dataCustomer })
157
+ // // replace user prop
158
+ // await userPropService.replaceUserProp({
159
+ // userPropType: "LOCATION_ID",
160
+ // data: {
161
+ // userProp: {
162
+ // userId: Number(updateUserId),
163
+ // locationIds: data.props.locationIds
164
+ // }
165
+ // }
166
+ // })
167
+ // response = await administratorService.getAdministrator({ id: Number(updateUserId), datatypes: [] })
168
+ // }
169
+ // if (_userType === "worker" && "worker" in data) {
170
+ // let dataWorker: WorkerUpdateProps["data"] = {
171
+ // worker: {
172
+ // ...data.worker
173
+ // }
174
+ // }
175
+ // await workerService.updateWorker({ userId: Number(updateUserId), data: dataWorker })
176
+ // // replace user prop
177
+ // await userPropService.replaceUserProp({
178
+ // userPropType: "LOCATION_ID",
179
+ // data: {
180
+ // userProp: {
181
+ // userId: Number(updateUserId),
182
+ // locationIds: data.props.locationIds
183
+ // }
184
+ // }
185
+ // })
186
+ // response = await workerService.getWorker({ id: Number(updateUserId), datatypes: [] })
187
+ // }
188
+ // if (_userType === "driver" && "driver" in data) {
189
+ // let dataDriver: DriverUpdateProps["data"] = {
190
+ // driver: {
191
+ // ...data.driver
192
+ // }
193
+ // }
194
+ // await driverService.updateDriver({ userId: Number(updateUserId), data: dataDriver })
195
+ // // replace user prop
196
+ // await userPropService.replaceUserProp({
197
+ // userPropType: "LOCATION_ID",
198
+ // data: {
199
+ // userProp: {
200
+ // userId: Number(updateUserId),
201
+ // locationIds: data.props.locationIds
202
+ // }
203
+ // }
204
+ // })
205
+ // response = await driverService.getDriver({ id: Number(updateUserId), datatypes: [] })
206
+ // }
207
+ // if (_userType === "member" && "member" in data) {
208
+ // let dataMember: MemberUpdateProps["data"] = {
209
+ // member: {
210
+ // ...data.member
211
+ // }
212
+ // }
213
+ // await memberService.updateMember({ userId: Number(updateUserId), data: dataMember })
214
+ // // replace user prop
215
+ // // await userPropService.replaceUserProp({
216
+ // // userPropType: "LOCATION_ID",
217
+ // // data: {
218
+ // // userProp: {
219
+ // // userId: Number(updateUserId),
220
+ // // locationIds: data.props.locationIds
221
+ // // }
222
+ // // }
223
+ // // })
224
+ // response = await memberService.getUserMember({ id: Number(updateUserId), datatypes: [] })
225
+ // }
226
+ // if (_userType === "agent" && "agent" in data) {
227
+ // let dataAgent: AgentUpdateProps["data"] = {
228
+ // agent: {
229
+ // ...data.agent
230
+ // }
231
+ // }
232
+ // await agentService.updateAgent({ userId: Number(updateUserId), data: dataAgent })
233
+ // // replace user prop
234
+ // // await userPropService.replaceUserProp({
235
+ // // userPropType: "LOCATION_ID",
236
+ // // data: {
237
+ // // userProp: {
238
+ // // userId: Number(updateUserId),
239
+ // // locationIds: data.props.locationIds
240
+ // // }
241
+ // // }
242
+ // // })
243
+ // response = await agentService.getAgent({ id: Number(updateUserId), datatypes: [] })
244
+ // }
245
+ // if (_userType === "retailer" && "retailer" in data) {
246
+ // let dataRetailer: RetailerUpdateProps["data"] = {
247
+ // retailer: {
248
+ // ...data.retailer
249
+ // }
250
+ // }
251
+ // await retailerService.updateRetailer({ userId: Number(updateUserId), data: dataRetailer })
252
+ // response = await retailerService.getRetailer({ id: Number(updateUserId), datatypes: [] })
253
+ // }
254
+ // return response
255
+ // }
256
+ const getUserMe = async () => {
257
+ const id = userId;
258
+ const data = await userService.getUser({ id: userId, datatypes: [] });
259
+ return data;
260
+ };
261
+ const removeUserMe = async () => {
262
+ const response = await userService.removeUsers({ ids: [BigInt(userId)] });
263
+ return response.length > 0 ? response[0] : {};
264
+ };
265
+ const allowUserTypes = ["any"];
266
+ const methodConfigs = {
267
+ getUserMe: { fn: getUserMe, allowUserTypes, actionName: "get user/me" },
268
+ // updateMe: { fn: updateMe, allowUserTypes, actionName: "update user/me" },
269
+ removeUserMe: { fn: removeUserMe, allowUserTypes, actionName: "remove user/me" },
270
+ };
271
+ return (0, lib_1.ServiceFactory)("UserMeService", rest, methodConfigs);
272
+ };
273
+ exports.UserMeService = UserMeService;
274
+ //# sourceMappingURL=UserMeService.js.map