storemw-core-api 1.0.138 → 1.0.140

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 (57) hide show
  1. package/dist/app.js +1 -1
  2. package/dist/app.js.map +1 -1
  3. package/dist/controllers/index.d.ts +1 -2
  4. package/dist/controllers/index.js +5 -4
  5. package/dist/controllers/index.js.map +1 -1
  6. package/dist/controllers/user/userMeController.d.ts +3 -0
  7. package/dist/controllers/user/userMeController.js +52 -361
  8. package/dist/controllers/user/userMeController.js.map +1 -1
  9. package/dist/controllers/utils/unuse/changePasswordUtilController.d.ts +1 -0
  10. package/dist/controllers/utils/unuse/changePasswordUtilController.js +55 -0
  11. package/dist/controllers/utils/unuse/changePasswordUtilController.js.map +1 -0
  12. package/dist/middlewares/route/index.d.ts +1 -1
  13. package/dist/middlewares/route/index.js +4 -2
  14. package/dist/middlewares/route/index.js.map +1 -1
  15. package/dist/middlewares/route/validateUserMe.d.ts +2 -0
  16. package/dist/middlewares/route/validateUserMe.js +9 -1
  17. package/dist/middlewares/route/validateUserMe.js.map +1 -1
  18. package/dist/routes/index.d.ts +0 -1
  19. package/dist/routes/index.js +2 -3
  20. package/dist/routes/index.js.map +1 -1
  21. package/dist/routes/user/userMeRoutes.js +4 -0
  22. package/dist/routes/user/userMeRoutes.js.map +1 -1
  23. package/dist/routes/utils/unuse/changePasswordUtilRoutes.d.ts +1 -0
  24. package/dist/routes/utils/unuse/changePasswordUtilRoutes.js +10 -0
  25. package/dist/routes/utils/unuse/changePasswordUtilRoutes.js.map +1 -0
  26. package/dist/schema/payload/index.d.ts +2 -2
  27. package/dist/schema/payload/index.js +7 -4
  28. package/dist/schema/payload/index.js.map +1 -1
  29. package/dist/schema/payload/user/schemaUserMe.d.ts +31 -0
  30. package/dist/schema/payload/user/schemaUserMe.js +17 -0
  31. package/dist/schema/payload/user/schemaUserMe.js.map +1 -0
  32. package/dist/schema/payload/utils/unuse/schemaChangePasswordUtil.d.ts +53 -0
  33. package/dist/schema/payload/utils/unuse/schemaChangePasswordUtil.js +18 -0
  34. package/dist/schema/payload/utils/unuse/schemaChangePasswordUtil.js.map +1 -0
  35. package/dist/services/auth/AuthService.js +7 -4
  36. package/dist/services/auth/AuthService.js.map +1 -1
  37. package/dist/services/index.d.ts +1 -3
  38. package/dist/services/index.js +3 -3
  39. package/dist/services/index.js.map +1 -1
  40. package/dist/services/user/UserMeService.d.ts +30 -7
  41. package/dist/services/user/UserMeService.js +71 -3
  42. package/dist/services/user/UserMeService.js.map +1 -1
  43. package/dist/services/user/UserService.d.ts +22 -1
  44. package/dist/services/user/UserService.js +21 -22
  45. package/dist/services/user/UserService.js.map +1 -1
  46. package/dist/services/utils/ChangePasswordUtilService.js +1 -1
  47. package/dist/services/utils/ChangePasswordUtilService.js.map +1 -1
  48. package/dist/services/utils/unuse/ChangePasswordUtilService.d.ts +13 -0
  49. package/dist/services/utils/unuse/ChangePasswordUtilService.js +78 -0
  50. package/dist/services/utils/unuse/ChangePasswordUtilService.js.map +1 -0
  51. package/dist/utils/index.d.ts +1 -1
  52. package/dist/utils/index.js +3 -1
  53. package/dist/utils/index.js.map +1 -1
  54. package/dist/utils/passwordUtils.d.ts +3 -0
  55. package/dist/utils/passwordUtils.js +22 -0
  56. package/dist/utils/passwordUtils.js.map +1 -1
  57. package/package.json +1 -1
@@ -0,0 +1,53 @@
1
+ import { z } from "zod";
2
+ /** Utils: Change Password */
3
+ export declare const schemaChangePasswordUtilPayload: z.ZodObject<{
4
+ scope: z.ZodObject<{
5
+ target: z.ZodEnum<["change_password"]>;
6
+ action: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ target: "change_password";
9
+ action: string;
10
+ }, {
11
+ target: "change_password";
12
+ action: string;
13
+ }>;
14
+ payload: z.ZodObject<{
15
+ authToken: z.ZodString;
16
+ currentPassword: z.ZodString;
17
+ newPassword: z.ZodString;
18
+ confirmPassword: z.ZodString;
19
+ }, "strip", z.ZodTypeAny, {
20
+ authToken: string;
21
+ currentPassword: string;
22
+ confirmPassword: string;
23
+ newPassword: string;
24
+ }, {
25
+ authToken: string;
26
+ currentPassword: string;
27
+ confirmPassword: string;
28
+ newPassword: string;
29
+ }>;
30
+ }, "strip", z.ZodTypeAny, {
31
+ scope: {
32
+ target: "change_password";
33
+ action: string;
34
+ };
35
+ payload: {
36
+ authToken: string;
37
+ currentPassword: string;
38
+ confirmPassword: string;
39
+ newPassword: string;
40
+ };
41
+ }, {
42
+ scope: {
43
+ target: "change_password";
44
+ action: string;
45
+ };
46
+ payload: {
47
+ authToken: string;
48
+ currentPassword: string;
49
+ confirmPassword: string;
50
+ newPassword: string;
51
+ };
52
+ }>;
53
+ export type SchemaChangePasswordUtilPayload = z.infer<typeof schemaChangePasswordUtilPayload>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.schemaChangePasswordUtilPayload = void 0;
4
+ const zod_1 = require("zod");
5
+ /** Utils: Change Password */
6
+ exports.schemaChangePasswordUtilPayload = zod_1.z.object({
7
+ scope: zod_1.z.object({
8
+ target: zod_1.z.enum(["change_password"]),
9
+ action: zod_1.z.string(), // can be "" if you want to allow empty string
10
+ }),
11
+ payload: zod_1.z.object({
12
+ authToken: zod_1.z.string().min(1),
13
+ currentPassword: zod_1.z.string().min(1),
14
+ newPassword: zod_1.z.string().min(1),
15
+ confirmPassword: zod_1.z.string().min(1),
16
+ })
17
+ });
18
+ //# sourceMappingURL=schemaChangePasswordUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemaChangePasswordUtil.js","sourceRoot":"","sources":["../../../../../src/schema/payload/utils/unuse/schemaChangePasswordUtil.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AAIxB,6BAA6B;AAChB,QAAA,+BAA+B,GAAG,OAAC,CAAC,MAAM,CAAC;IACpD,KAAK,EAAE,OAAC,CAAC,MAAM,CAAC;QACZ,MAAM,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,iBAAiB,CAAC,CAAC;QACnC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,8CAA8C;KACrE,CAAC;IACF,OAAO,EAAE,OAAC,CAAC,MAAM,CAAC;QACd,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5B,eAAe,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAClC,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9B,eAAe,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;KACrC,CAAC;CACL,CAAC,CAAC","sourcesContent":["import { z } from \"zod\";\n\nimport { _, dayjs } from \"@/utils\";\n\n/** Utils: Change Password */\nexport const schemaChangePasswordUtilPayload = z.object({\n scope: z.object({\n target: z.enum([\"change_password\"]),\n action: z.string(), // can be \"\" if you want to allow empty string\n }),\n payload: z.object({\n authToken: z.string().min(1),\n currentPassword: z.string().min(1),\n newPassword: z.string().min(1),\n confirmPassword: z.string().min(1),\n })\n});\n\nexport type SchemaChangePasswordUtilPayload = z.infer<typeof schemaChangePasswordUtilPayload>;"]}
@@ -133,7 +133,10 @@ const AuthService = (props) => {
133
133
  foundUser = foundOtherUser.length > 0 ? foundOtherUser[0] : {};
134
134
  }
135
135
  if (!foundUser?.user_id) {
136
- throw Error(`Invalid username: ${data["username"]}`);
136
+ throw Error(`Invalid username: ${data.username}`);
137
+ }
138
+ if (foundUser?.status !== true) {
139
+ throw new Error(`User is inactive: ${data.username}`);
137
140
  }
138
141
  let user = foundUser;
139
142
  // foundUser.length > 0 ? foundUser[0] : {}
@@ -150,9 +153,9 @@ const AuthService = (props) => {
150
153
  // dont show out to result
151
154
  delete user.password;
152
155
  let account = {};
153
- if (_rest.accountId && authType !== "operator") {
154
- account = await accountService.getAccount({ id: Number(_rest.accountId), datatypes: [] });
155
- }
156
+ // if (_rest.accountId && authType !== "operator") {
157
+ account = await accountService.getAccount({ id: Number(_rest.accountId), datatypes: [] });
158
+ // }
156
159
  const authToken = (0, utils_2.generateAuthToken)(user, account, secretKey);
157
160
  // get the locations for user
158
161
  const locationIds = user?.location_id ? user.location_id.split(", ") : [];
@@ -1 +1 @@
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,oDAAoD;QACpD,qFAAqF;QAErF,IAAI,eAAe,GAAG,CAAC,CAAA;QAEvB,8BAA8B;QAC9B,+BAA+B;QAE/B,MAAM,oBAAoB,GAAG,IAAA,yBA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M,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"]}
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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AAC,CAAC,CAAC,EAAE,CAAA;QAEzE,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;AAvPY,QAAA,WAAW,eAuPvB","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 if (foundUser?.status !== true) {\n throw new Error(`User is inactive: ${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"]}
@@ -13,7 +13,7 @@ export type { BusinessServiceProps, Business, BusinessGetProps, BusinessListProp
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
15
  export { UserMeService } from "../services/user/UserMeService";
16
- export type { UserMeServiceProps } from "../services/user/UserMeService";
16
+ export type { UserMeServiceProps, UserMeUpdateProps, UserMeChangePasswordProps } from "../services/user/UserMeService";
17
17
  export { UserBranchService, userBranchTypes } from "../services/branch/UserBranchService";
18
18
  export type { UserBranchServiceProps, UserBranchType, UserBranchGetProps, UserBranchListProps, UserBranchCreateProps, UserBranchUpdateProps, UserBranchRemoveProps } from "../services/branch/UserBranchService";
19
19
  export { RegionService } from "../services/region/RegionService";
@@ -34,7 +34,5 @@ export { OneTimeCodeService, oneTimeCodeTypes, oneTimeCodePurposeTypes, oneTimeC
34
34
  export type { OneTimeCodeModuleRef, OneTimeCodeType, OneTimeCodePurposeType, OneTimeCodeStatus, OneTimeCodeServiceProps, OneTimeCodeCreateProps } from "../services/one_time_code/OneTimeCodeService";
35
35
  export { SmtpEmailService } from "../services/gateway/SmtpEmailService";
36
36
  export type { SmtpEmailServiceProps, SmtpEmailSendProps, SmtpEmailTransporterOptions } from "../services/gateway/SmtpEmailService";
37
- export { ChangePasswordUtilService } from "../services/utils/ChangePasswordUtilService";
38
- export type { ChangePasswordUtilServiceProps, ChangePasswordUtilChangeProps } from "../services/utils/ChangePasswordUtilService";
39
37
  export { AccessKeyUtilService } from "../services/utils/AccessKeyUtilService";
40
38
  export type { AccessKeyUtilServiceProps, AccessKeyUtilValidateProps, AccessKeyUtilAccountOwnerProps } from "../services/utils/AccessKeyUtilService";
@@ -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.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;
3
+ exports.AccessKeyUtilService = 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; } });
@@ -53,8 +53,8 @@ Object.defineProperty(exports, "oneTimeCodePurposeTypes", { enumerable: true, ge
53
53
  Object.defineProperty(exports, "oneTimeCodeStatus", { enumerable: true, get: function () { return OneTimeCodeService_1.oneTimeCodeStatus; } });
54
54
  var SmtpEmailService_1 = require("../services/gateway/SmtpEmailService");
55
55
  Object.defineProperty(exports, "SmtpEmailService", { enumerable: true, get: function () { return SmtpEmailService_1.SmtpEmailService; } });
56
- var ChangePasswordUtilService_1 = require("../services/utils/ChangePasswordUtilService");
57
- Object.defineProperty(exports, "ChangePasswordUtilService", { enumerable: true, get: function () { return ChangePasswordUtilService_1.ChangePasswordUtilService; } });
56
+ // export { ChangePasswordUtilService } from "../services/utils/unuse/ChangePasswordUtilService"
57
+ // export type { ChangePasswordUtilServiceProps, ChangePasswordUtilChangeProps } from "../services/utils/unuse/ChangePasswordUtilService"
58
58
  var AccessKeyUtilService_1 = require("../services/utils/AccessKeyUtilService");
59
59
  Object.defineProperty(exports, "AccessKeyUtilService", { enumerable: true, get: function () { return AccessKeyUtilService_1.AccessKeyUtilService; } });
60
60
  //# sourceMappingURL=index.js.map
@@ -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;AAG/B,+DAA6D;AAApD,8GAAA,aAAa,OAAA;AAGtB,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\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\""]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;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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\nexport { UserMeService } from \"@/services/user/UserMeService\"\nexport type { UserMeServiceProps, UserMeUpdateProps, UserMeChangePasswordProps } 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\n// export { ChangePasswordUtilService } from \"@/services/utils/unuse/ChangePasswordUtilService\"\n// export type { ChangePasswordUtilServiceProps, ChangePasswordUtilChangeProps } from \"@/services/utils/unuse/ChangePasswordUtilService\"\nexport { AccessKeyUtilService } from \"@/services/utils/AccessKeyUtilService\"\nexport type { AccessKeyUtilServiceProps, AccessKeyUtilValidateProps, AccessKeyUtilAccountOwnerProps } from \"@/services/utils/AccessKeyUtilService\""]}
@@ -12,14 +12,37 @@ export declare const userTypes: {
12
12
  };
13
13
  export type UserType = typeof userTypes[keyof typeof userTypes];
14
14
  export type UserMeServiceProps = DefaultServiceProps & {};
15
- export type UserMeReplacePasswordProps = {
16
- id: number;
17
- data: {
18
- unhashLoginPassword: string;
19
- };
20
- isOperator: boolean;
15
+ export type UserMeChangePasswordProps = {
16
+ currentPassword: string;
17
+ newPassword: string;
18
+ confirmPassword: string;
19
+ };
20
+ export type UserMeUpdateProps = {
21
+ firstName: string;
22
+ lastName: string;
23
+ address: string;
21
24
  };
22
25
  export declare const UserMeService: (props: UserMeServiceProps) => {
23
26
  getUserMe: () => Promise<any>;
24
- removeUserMe: () => Promise<any>;
27
+ updateUserMe: (args_0: UserMeUpdateProps) => Promise<any>;
28
+ changePasswordUserMe: (args_0: UserMeChangePasswordProps) => Promise<any>;
29
+ removeUserMe: () => Promise<{
30
+ createdatetime: Date | null;
31
+ createuserid: bigint;
32
+ updatedatetime: Date | null;
33
+ updateuserid: bigint;
34
+ isdelete: boolean | null;
35
+ istrash: boolean | null;
36
+ accountid: bigint;
37
+ status: boolean | null;
38
+ user_id: bigint;
39
+ login_username: string | null;
40
+ user_type: string | null;
41
+ firstname: string | null;
42
+ lastname: string | null;
43
+ email: string | null;
44
+ address: string | null;
45
+ contact_country_code: number;
46
+ contact_phone_number: string | null;
47
+ }>;
25
48
  };
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UserMeService = exports.userTypes = void 0;
4
+ const models_1 = require("../../models");
5
+ // import { buildSqlRelation, buildSqlRawSelect, buildSqlWhere, buildSqlSelect, buildSqlLimitOffset, buildSqlOrderBy, buildInjectionFieldsSqlSelect } from "../../lib";
6
+ const utils_1 = require("../../utils");
4
7
  // import { hashPassword } from "../../utils";
5
8
  const lib_1 = require("../../lib");
6
9
  const services_1 = require("../../services");
@@ -45,6 +48,7 @@ const UserMeService = (props) => {
45
48
  const userType = rest.actionUserType;
46
49
  const userId = rest.actionUserId;
47
50
  const userService = (0, services_1.UserService)({ ...rest, userType });
51
+ const userModel = (0, models_1.UserModel)({ ...rest });
48
52
  // const userModel = UserModel({ ...rest })
49
53
  // const userPropService = UserPropService({ ...rest, userPropType: "LOCATION_ID" })
50
54
  // const customerService = CustomerService({ ...rest })
@@ -258,14 +262,78 @@ const UserMeService = (props) => {
258
262
  const data = await userService.getUser({ id: userId, datatypes: [] });
259
263
  return data;
260
264
  };
265
+ const updateUserMe = async ({ firstName = "", lastName = "", address = "" }) => {
266
+ const user = await userService.getUser({ id: Number(userId), datatypes: [] });
267
+ // console.log('user', user)
268
+ // check the userId is valid
269
+ if (!user?.user_id) {
270
+ (0, utils_1.throwError)(`Invalid user id in auth token`);
271
+ }
272
+ // change user information
273
+ await userModel.update({
274
+ id: Number(userId),
275
+ data: {
276
+ [`${models_1.ModelUserFields.firstname}`]: firstName,
277
+ [`${models_1.ModelUserFields.lastname}`]: lastName,
278
+ [`${models_1.ModelUserFields.address}`]: address,
279
+ }
280
+ });
281
+ return await userService.getUser({ id: Number(userId), datatypes: [] });
282
+ };
261
283
  const removeUserMe = async () => {
262
- const response = await userService.removeUsers({ ids: [BigInt(userId)] });
263
- return response.length > 0 ? response[0] : {};
284
+ const response = await userService.suspendUsers({ ids: [BigInt(userId)] });
285
+ return response;
286
+ };
287
+ const changePasswordUserMe = async ({ currentPassword, confirmPassword, newPassword }) => {
288
+ const accountId = rest?.accountId ?? 0;
289
+ const accountService = (0, services_1.AccountService)({ ...rest, isOperator: true });
290
+ const user = await userService.getUser({ id: Number(userId), datatypes: [], includePassword: true });
291
+ const account = await accountService.getAccount({ id: Number(accountId), datatypes: [] });
292
+ // console.log('user', user)
293
+ // console.log('account', account)
294
+ // check the accountId / userId is valid
295
+ if (!user?.user_id) {
296
+ (0, utils_1.throwError)(`Invalid user id in auth token`);
297
+ }
298
+ if (Object.keys(account).length <= 0) { // must have account id record
299
+ (0, utils_1.throwError)(`Invalid account id in auth token`);
300
+ }
301
+ // new password cannot same with current password
302
+ if (newPassword === currentPassword) {
303
+ (0, utils_1.throwError)(`New and current password cannot be same`);
304
+ }
305
+ // new password must same with confirm
306
+ if (newPassword !== confirmPassword) {
307
+ (0, utils_1.throwError)(`New and confirm password not matched`);
308
+ }
309
+ // validate the login password new format
310
+ (0, utils_1.validateLoginPasswordFormat)(newPassword);
311
+ // check the current password
312
+ try {
313
+ const decryptedPass = await (0, utils_1.verifyPassword)(currentPassword, user?.password);
314
+ // console.log('decryptedPass', decryptedPass)
315
+ if (!decryptedPass) {
316
+ throw Error(`Invalid current password`);
317
+ }
318
+ }
319
+ catch (error) {
320
+ (0, utils_1.throwError)(`Auth Token: ${error?.message}`);
321
+ }
322
+ // perform update credential
323
+ const responseUser = await userService.replacePassword({
324
+ id: Number(userId),
325
+ data: {
326
+ unhashLoginPassword: newPassword
327
+ },
328
+ isOperator: Boolean(userType === "operator")
329
+ });
330
+ return responseUser;
264
331
  };
265
332
  const allowUserTypes = ["any"];
266
333
  const methodConfigs = {
267
334
  getUserMe: { fn: getUserMe, allowUserTypes, actionName: "get user/me" },
268
- // updateMe: { fn: updateMe, allowUserTypes, actionName: "update user/me" },
335
+ updateUserMe: { fn: updateUserMe, allowUserTypes, actionName: "update user/me" },
336
+ changePasswordUserMe: { fn: changePasswordUserMe, allowUserTypes, actionName: "change password user/me" },
269
337
  removeUserMe: { fn: removeUserMe, allowUserTypes, actionName: "remove user/me" },
270
338
  };
271
339
  return (0, lib_1.ServiceFactory)("UserMeService", rest, methodConfigs);
@@ -1 +1 @@
1
- {"version":3,"file":"UserMeService.js","sourceRoot":"","sources":["../../../src/services/user/UserMeService.ts"],"names":[],"mappings":";;;AA0BA,0CAA0C;AAE1C,+BAAuC;AAEvC,yCAAyC;AAE5B,QAAA,SAAS,GAAG;IACrB,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,eAAe;IAC9B,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;CACR,CAAA;AAmGV,mCAAmC;AACnC,0BAA0B;AAC1B,uCAAuC;AACvC,iBAAiB;AACjB,+BAA+B;AAC/B,8BAA8B;AAC9B,QAAQ;AACR,SAAS;AAET,4BAA4B;AAE5B,+GAA+G;AAE/G,mBAAmB;AACnB,8EAA8E;AAC9E,sGAAsG;AACtG,iEAAiE;AACjE,gFAAgF;AAChF,gFAAgF;AAChF,6DAA6D;AAC7D,qEAAqE;AACrE,mEAAmE;AACnE,wEAAwE;AACxE,8DAA8D;AAC9D,YAAY;AACZ,QAAQ;AAER,mBAAmB;AAEnB,IAAI;AAEG,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AC,EAAE,CAAC,CAAA;QAEzE,OAAO,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;IACjD,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,CAAC,KAAK,CAAU,CAAA;IAEvC,MAAM,aAAa,GAAG;QAClB,SAAS,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,cAAc,EAAE,UAAU,EAAE,aAAa,EAAE;QACvE,4EAA4E;QAC5E,YAAY,EAAE,EAAE,EAAE,EAAE,YAAY,EAAE,cAAc,EAAE,UAAU,EAAE,gBAAgB,EAAE;KACnF,CAAC;IAEF,OAAO,IAAA,oBAAc,EAAC,eAAe,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;AAEhE,CAAC,CAAA;AA5TY,QAAA,aAAa,iBA4TzB","sourcesContent":["import {\n UserModel,\n ModelCountry,\n CountryModel,\n ModelUserFields,\n ModelAdministratorFields,\n ModelCountryFields\n} from \"@/models\";\n\nimport { z } from \"zod\";\n\nimport { UserPropService, UserPropReplaceProps } from \"./UserPropService\";\n// import { CustomerGetProps, CustomerCreateProps, CustomerListProps, CustomerUpdateProps, CustomerService } from \"./CustomerService\";\n// import { AdministratorGetProps, AdministratorCreateProps, AdministratorUpdateProps, AdministratorListProps, AdministratorService } from \"./AdministratorService\";\n// import { WorkerCreateProps, WorkerGetProps, WorkerUpdateProps, WorkerListProps, WorkerService } from \"./WorkerService\";\n// import { DriverCreateProps, DriverGetProps, DriverUpdateProps, DriverListProps, DriverService } from \"./DriverService\";\n// import { RetailerCreateProps, RetailerGetProps, RetailerUpdateProps, RetailerListProps, RetailerService } from \"./RetailerService\";\n// import { MemberCreateProps, MemberGetProps, MemberUpdateProps, MemberListProps, MemberService } from \"./MemberService\";\n// import { AgentCreateProps, AgentGetProps, AgentUpdateProps, AgentListProps, AgentService } from \"./AgentService\";\n// import { OperatorCreateProps, OperatorGetProps, OperatorListProps, OperatorService, OperatorUpdateProps } from \"./OperatorService\";\n\nimport { QueryList, QueryGet } from \"@/schema/common\";\n// import { buildSqlRelation, buildSqlRawSelect, buildSqlWhere, buildSqlSelect, buildSqlLimitOffset, buildSqlOrderBy, buildInjectionFieldsSqlSelect } from \"@/lib\";\n\nimport { DefaultServiceProps, throwError } from \"@/utils\";\n\n// import { hashPassword } from \"@/utils\";\n\nimport { ServiceFactory } from \"@/lib\";\n\nimport { UserService } from \"@/services\";\n\nexport const userTypes = {\n operator: \"operator\",\n administrator: \"administrator\",\n worker: \"worker\",\n supplier: \"supplier\",\n customer: \"customer\",\n driver: \"driver\",\n retailer: \"retailer\",\n member: \"member\",\n agent: \"agent\",\n} as const\n\nexport type UserType = typeof userTypes[keyof typeof userTypes]\n\nexport type UserMeServiceProps = DefaultServiceProps & {\n // userType: UserType\n};\n\n// export type UserMeGetProps = {\n// id: number,\n// overrideUserType?: UserType | \"\"\n// };\n\n// export type UserMeRemoveProps = {\n// ids: BigInt[]\n// };\n\n// export type User = {\n// loginUsername: string\n// loginPassword: string\n// address: string\n// // contact: string\n// contact: {\n// countryCode: number; // e.g., 1 for Canada\n// phoneNumber: string; // digits only, mobile or landline\n// }\n// email: string\n// firstname: string\n// lastname: string\n// status: boolean\n// }\n\n// export type UserMeUpdateProps = {\n// id: number,\n// userType?: UserType,\n// data: {\n// user: UserOptionalLoginPassword\n// } & (\n// // operator\n// {\n// operator: Omit<OperatorUpdateProps[\"data\"][\"operator\"], \"userId\">\n// } |\n// // customer\n// {\n// customer: Omit<CustomerUpdateProps[\"data\"][\"customer\"], \"userId\">\n// } |\n// // administrator\n// {\n// administrator: Omit<AdministratorUpdateProps[\"data\"][\"administrator\"], \"userId\">\n// props: {\n// locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n// }\n// } |\n// // worker\n// {\n// worker: Omit<WorkerUpdateProps[\"data\"][\"worker\"], \"userId\">\n// props: {\n// locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n// }\n// } |\n// // driver\n// {\n// driver: Omit<DriverUpdateProps[\"data\"][\"driver\"], \"userId\">\n// props: {\n// locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n// }\n// } |\n// // member\n// {\n// member: Omit<MemberUpdateProps[\"data\"][\"member\"], \"userId\">\n// // props: {\n// // locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n// // }\n// } |\n// // agent\n// {\n// agent: Omit<AgentUpdateProps[\"data\"][\"agent\"], \"userId\">\n// // props: {\n// // locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n// // }\n// } |\n// // retailer\n// {\n// retailer: Omit<RetailerUpdateProps[\"data\"][\"retailer\"], \"userId\">\n// // props: {\n// // locationIds: UserPropReplaceProps[\"data\"][\"userProp\"][\"locationIds\"]\n// // }\n// }\n// )\n// }\n\nexport type UserMeReplacePasswordProps = {\n id: number,\n data: {\n unhashLoginPassword: string\n },\n isOperator: boolean\n}\n\n// const getUpdatePayload = async (\n// userType: UserType,\n// data: UserMeUpdateProps[\"data\"],\n// contact: {\n// countryCode: number,\n// phoneNumber: string\n// }\n// ) => {\n\n// if (\"user\" in data) {\n\n// const newHashPassword = data?.user?.loginPassword ? await hashPassword(data.user.loginPassword) : \"\"\n\n// return {\n// [`${ModelUserFields.login_username}`]: data.user.loginUsername,\n// ...(newHashPassword ? { [`${ModelUserFields.login_password}`]: newHashPassword } : {}),\n// [`${ModelUserFields.address}`]: data.user.address,\n// [`${ModelUserFields.contact_country_code}`]: contact.countryCode,\n// [`${ModelUserFields.contact_phone_number}`]: contact.phoneNumber,\n// [`${ModelUserFields.email}`]: data.user.email,\n// [`${ModelUserFields.firstname}`]: data.user.firstname,\n// [`${ModelUserFields.lastname}`]: data.user.lastname,\n// [`${ModelUserFields.status}`]: Boolean(data.user.status),\n// [`${ModelUserFields.user_type}`]: `${userType}`\n// }\n// }\n\n// return false\n\n// }\n\nexport const UserMeService = (props: UserMeServiceProps) => {\n\n const {\n ...rest\n } = props\n\n const userType = rest.actionUserType as UserType\n const userId = rest.actionUserId\n\n const userService = UserService({ ...rest, userType })\n\n // const userModel = UserModel({ ...rest })\n\n // const userPropService = UserPropService({ ...rest, userPropType: \"LOCATION_ID\" })\n // const customerService = CustomerService({ ...rest })\n // const administratorService = AdministratorService({ ...rest })\n // const operatorService = OperatorService({ ...rest })\n // const workerService = WorkerService({ ...rest })\n // const driverService = DriverService({ ...rest })\n // const retailerService = RetailerService({ ...rest })\n // const memberService = MemberService({ ...rest })\n // const agentService = AgentService({ ...rest })\n\n // const validateAuthToken = (token: string) => {\n\n // // retrive core configuration\n // const coreConfig = getCoreConfiguration()\n\n // // const authSecretKey = config.AUTH_SECRET_KEY\n // const authSecretKey = coreConfig.authSecretKey\n\n // // const jwtData = jwt.verify(token, authSecretKey) as AuthJwtToken; // Verify JWT token\n // const jwtData = verifyAuthToken(token, authSecretKey); // Verify JWT token\n\n // }\n\n // const validateAuthAccessKey = async (accessKey: string) => {\n\n // const accessKeyUtilService = AccessKeyUtilService({\n // accessKeyUserType: \"administrator\",\n // accountId: 0,\n // actionUserId: 0,\n // actionUserType: \"\",\n // authToken: \"\",\n // isOperator: true,\n // })\n\n // const accessKeyData = await accessKeyUtilService.validateAccessKey({ data: { accessKey } });\n // }\n\n // const updateMe = async ({ id, data, userType: overrideUserType }: UserMeUpdateProps) => {\n\n // const _userType = overrideUserType || userType\n\n // // validate the credential contact no\n // const userLoginUsername = data.user.loginUsername\n // const userLoginPassword = data.user?.loginPassword ?? \"\"\n // const userContactCountryCode = data.user.contact.countryCode\n // const userContactPhoneNumber = data.user.contact.phoneNumber\n\n // // validate the contact no only can be digit in text only\n // // validate the country code in prefix\n // // await validateUserContact(userContactCountryCode, userContactPhoneNumber)\n\n // // validate login username\n // // validateLoginUsernameFormat(userLoginUsername)\n\n // // validate login password\n // // if (userLoginPassword) {\n // // validateLoginPasswordFormat(userLoginPassword)\n // // }\n\n // // check the username duplicated?\n // const checkUsername = await userModel.list({\n // limit: 1,\n // offset: 0,\n // orderBy: {\n // [`${ModelUserFields.user_id}`]: \"asc\"\n // },\n // include: [],\n // where: {\n // [`${ModelUserFields.login_username}`]: data.user.loginUsername,\n // [`${ModelUserFields.isdelete}`]: false,\n // [`${ModelUserFields.istrash}`]: false,\n // [`${ModelUserFields.accountid}`]: rest.accountId,\n // },\n // })\n\n // // console.log('ch', checkUsername)\n\n // if (checkUsername.length > 0) {\n // if (Number(checkUsername[0]?.user_id) !== Number(id)) { // if not self user id\n // throwError(`Duplicated username: ${data.user.loginUsername}(${checkUsername[0]?.user_type})`)\n // }\n // }\n\n // // validation before insertion\n // // if (_userType === \"member\" && \"member\" in data) {\n // // }\n\n // const _data = await getUpdatePayload(\n // _userType,\n // data,\n // {\n // countryCode: userContactCountryCode,\n // phoneNumber: userContactPhoneNumber\n // }\n // )\n\n // if (!_data) {\n // throw new Error(`Invalid update payload: ${JSON.stringify(_data)}`);\n // }\n\n // // update user\n // let responseUser = await userModel.update({ id, data: _data })\n\n // let updateUserId = responseUser.user_id\n\n // let response: any = {}\n\n // if (_userType === \"customer\" && \"customer\" in data) {\n\n // let dataCustomer: CustomerUpdateProps[\"data\"] = {\n // customer: {\n // ...data.customer\n // }\n // }\n\n // await customerService.updateCustomer({ userId: Number(updateUserId), data: dataCustomer })\n\n // response = await customerService.getCustomer({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"operator\" && \"operator\" in data) {\n\n // let dataOperator: OperatorUpdateProps[\"data\"] = {\n // operator: {\n // ...data.operator\n // }\n // }\n\n // await operatorService.updateOperator({ userId: Number(updateUserId), data: dataOperator })\n\n // response = await operatorService.getOperator({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"administrator\" && \"administrator\" in data) {\n\n // let dataCustomer: AdministratorUpdateProps[\"data\"] = {\n // administrator: {\n // ...data.administrator\n // }\n // }\n\n // await administratorService.updateAdministrator({ userId: Number(updateUserId), data: dataCustomer })\n\n // // replace user prop\n // await userPropService.replaceUserProp({\n // userPropType: \"LOCATION_ID\",\n // data: {\n // userProp: {\n // userId: Number(updateUserId),\n // locationIds: data.props.locationIds\n // }\n // }\n // })\n\n // response = await administratorService.getAdministrator({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"worker\" && \"worker\" in data) {\n\n // let dataWorker: WorkerUpdateProps[\"data\"] = {\n // worker: {\n // ...data.worker\n // }\n // }\n\n // await workerService.updateWorker({ userId: Number(updateUserId), data: dataWorker })\n\n // // replace user prop\n // await userPropService.replaceUserProp({\n // userPropType: \"LOCATION_ID\",\n // data: {\n // userProp: {\n // userId: Number(updateUserId),\n // locationIds: data.props.locationIds\n // }\n // }\n // })\n\n // response = await workerService.getWorker({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"driver\" && \"driver\" in data) {\n\n // let dataDriver: DriverUpdateProps[\"data\"] = {\n // driver: {\n // ...data.driver\n // }\n // }\n\n // await driverService.updateDriver({ userId: Number(updateUserId), data: dataDriver })\n\n // // replace user prop\n // await userPropService.replaceUserProp({\n // userPropType: \"LOCATION_ID\",\n // data: {\n // userProp: {\n // userId: Number(updateUserId),\n // locationIds: data.props.locationIds\n // }\n // }\n // })\n\n // response = await driverService.getDriver({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"member\" && \"member\" in data) {\n\n // let dataMember: MemberUpdateProps[\"data\"] = {\n // member: {\n // ...data.member\n // }\n // }\n\n // await memberService.updateMember({ userId: Number(updateUserId), data: dataMember })\n\n // // replace user prop\n // // await userPropService.replaceUserProp({\n // // userPropType: \"LOCATION_ID\",\n // // data: {\n // // userProp: {\n // // userId: Number(updateUserId),\n // // locationIds: data.props.locationIds\n // // }\n // // }\n // // })\n\n // response = await memberService.getUserMember({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"agent\" && \"agent\" in data) {\n\n // let dataAgent: AgentUpdateProps[\"data\"] = {\n // agent: {\n // ...data.agent\n // }\n // }\n\n // await agentService.updateAgent({ userId: Number(updateUserId), data: dataAgent })\n\n // // replace user prop\n // // await userPropService.replaceUserProp({\n // // userPropType: \"LOCATION_ID\",\n // // data: {\n // // userProp: {\n // // userId: Number(updateUserId),\n // // locationIds: data.props.locationIds\n // // }\n // // }\n // // })\n\n // response = await agentService.getAgent({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"retailer\" && \"retailer\" in data) {\n\n // let dataRetailer: RetailerUpdateProps[\"data\"] = {\n // retailer: {\n // ...data.retailer\n // }\n // }\n\n // await retailerService.updateRetailer({ userId: Number(updateUserId), data: dataRetailer })\n\n // response = await retailerService.getRetailer({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // return response\n // }\n\n const getUserMe = async () => {\n\n const id = userId\n\n const data = await userService.getUser({ id: userId, datatypes: [] })\n\n return data\n };\n\n const removeUserMe = async () => {\n\n const response = await userService.removeUsers({ ids: [BigInt(userId)] })\n\n return response.length > 0 ? response[0] : {}\n };\n\n const allowUserTypes = [\"any\"] as const\n\n const methodConfigs = {\n getUserMe: { fn: getUserMe, allowUserTypes, actionName: \"get user/me\" },\n // updateMe: { fn: updateMe, allowUserTypes, actionName: \"update user/me\" },\n removeUserMe: { fn: removeUserMe, allowUserTypes, actionName: \"remove user/me\" },\n };\n\n return ServiceFactory(\"UserMeService\", rest, methodConfigs);\n\n}\n\n"]}
1
+ {"version":3,"file":"UserMeService.js","sourceRoot":"","sources":["../../../src/services/user/UserMeService.ts"],"names":[],"mappings":";;;AAAA,qCAOkB;AAelB,mKAAmK;AAEnK,mCAAuG;AAEvG,0CAA0C;AAE1C,+BAAuC;AAEvC,yCAA0E;AAE7D,QAAA,SAAS,GAAG;IACrB,QAAQ,EAAE,UAAU;IACpB,aAAa,EAAE,eAAe;IAC9B,MAAM,EAAE,QAAQ;IAChB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE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;IAEF,OAAO,IAAA,oBAAc,EAAC,eAAe,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC;AAEhE,CAAC,CAAA;AA1ZY,QAAA,aAAa,iBA0ZzB","sourcesContent":["import {\n UserModel,\n ModelCountry,\n CountryModel,\n ModelUserFields,\n ModelAdministratorFields,\n ModelCountryFields\n} from \"@/models\";\n\nimport { z } from \"zod\";\n\nimport { UserPropService, UserPropReplaceProps } from \"./UserPropService\";\n// import { CustomerGetProps, CustomerCreateProps, CustomerListProps, CustomerUpdateProps, CustomerService } from \"./CustomerService\";\n// import { AdministratorGetProps, AdministratorCreateProps, AdministratorUpdateProps, AdministratorListProps, AdministratorService } from \"./AdministratorService\";\n// import { WorkerCreateProps, WorkerGetProps, WorkerUpdateProps, WorkerListProps, WorkerService } from \"./WorkerService\";\n// import { DriverCreateProps, DriverGetProps, DriverUpdateProps, DriverListProps, DriverService } from \"./DriverService\";\n// import { RetailerCreateProps, RetailerGetProps, RetailerUpdateProps, RetailerListProps, RetailerService } from \"./RetailerService\";\n// import { MemberCreateProps, MemberGetProps, MemberUpdateProps, MemberListProps, MemberService } from \"./MemberService\";\n// import { AgentCreateProps, AgentGetProps, AgentUpdateProps, AgentListProps, AgentService } from \"./AgentService\";\n// import { OperatorCreateProps, OperatorGetProps, OperatorListProps, OperatorService, OperatorUpdateProps } from \"./OperatorService\";\n\nimport { QueryList, QueryGet } from \"@/schema/common\";\n// import { buildSqlRelation, buildSqlRawSelect, buildSqlWhere, buildSqlSelect, buildSqlLimitOffset, buildSqlOrderBy, buildInjectionFieldsSqlSelect } from \"@/lib\";\n\nimport { verifyPassword, validateLoginPasswordFormat, DefaultServiceProps, throwError } from \"@/utils\";\n\n// import { hashPassword } from \"@/utils\";\n\nimport { ServiceFactory } from \"@/lib\";\n\nimport { UserService, AccountService, UserUpdateProps } from \"@/services\";\n\nexport const userTypes = {\n operator: \"operator\",\n administrator: \"administrator\",\n worker: \"worker\",\n supplier: \"supplier\",\n customer: \"customer\",\n driver: \"driver\",\n retailer: \"retailer\",\n member: \"member\",\n agent: \"agent\",\n} as const\n\nexport type UserType = typeof userTypes[keyof typeof userTypes]\n\nexport type UserMeServiceProps = DefaultServiceProps & {\n // userType: UserType\n};\n\nexport type UserMeChangePasswordProps = {\n currentPassword: string\n newPassword: string\n confirmPassword: string\n};\n\nexport type UserMeUpdateProps = {\n firstName: string\n lastName: string\n address: string\n};\n\n// const getUpdatePayload = async (\n// userType: UserType,\n// data: UserMeUpdateProps[\"data\"],\n// contact: {\n// countryCode: number,\n// phoneNumber: string\n// }\n// ) => {\n\n// if (\"user\" in data) {\n\n// const newHashPassword = data?.user?.loginPassword ? await hashPassword(data.user.loginPassword) : \"\"\n\n// return {\n// [`${ModelUserFields.login_username}`]: data.user.loginUsername,\n// ...(newHashPassword ? { [`${ModelUserFields.login_password}`]: newHashPassword } : {}),\n// [`${ModelUserFields.address}`]: data.user.address,\n// [`${ModelUserFields.contact_country_code}`]: contact.countryCode,\n// [`${ModelUserFields.contact_phone_number}`]: contact.phoneNumber,\n// [`${ModelUserFields.email}`]: data.user.email,\n// [`${ModelUserFields.firstname}`]: data.user.firstname,\n// [`${ModelUserFields.lastname}`]: data.user.lastname,\n// [`${ModelUserFields.status}`]: Boolean(data.user.status),\n// [`${ModelUserFields.user_type}`]: `${userType}`\n// }\n// }\n\n// return false\n\n// }\n\nexport const UserMeService = (props: UserMeServiceProps) => {\n\n const {\n ...rest\n } = props\n\n const userType = rest.actionUserType as UserType\n const userId = rest.actionUserId\n\n const userService = UserService({ ...rest, userType })\n const userModel = UserModel({ ...rest })\n\n // const userModel = UserModel({ ...rest })\n\n // const userPropService = UserPropService({ ...rest, userPropType: \"LOCATION_ID\" })\n // const customerService = CustomerService({ ...rest })\n // const administratorService = AdministratorService({ ...rest })\n // const operatorService = OperatorService({ ...rest })\n // const workerService = WorkerService({ ...rest })\n // const driverService = DriverService({ ...rest })\n // const retailerService = RetailerService({ ...rest })\n // const memberService = MemberService({ ...rest })\n // const agentService = AgentService({ ...rest })\n\n // const validateAuthToken = (token: string) => {\n\n // // retrive core configuration\n // const coreConfig = getCoreConfiguration()\n\n // // const authSecretKey = config.AUTH_SECRET_KEY\n // const authSecretKey = coreConfig.authSecretKey\n\n // // const jwtData = jwt.verify(token, authSecretKey) as AuthJwtToken; // Verify JWT token\n // const jwtData = verifyAuthToken(token, authSecretKey); // Verify JWT token\n\n // }\n\n // const validateAuthAccessKey = async (accessKey: string) => {\n\n // const accessKeyUtilService = AccessKeyUtilService({\n // accessKeyUserType: \"administrator\",\n // accountId: 0,\n // actionUserId: 0,\n // actionUserType: \"\",\n // authToken: \"\",\n // isOperator: true,\n // })\n\n // const accessKeyData = await accessKeyUtilService.validateAccessKey({ data: { accessKey } });\n // }\n\n // const updateMe = async ({ id, data, userType: overrideUserType }: UserMeUpdateProps) => {\n\n // const _userType = overrideUserType || userType\n\n // // validate the credential contact no\n // const userLoginUsername = data.user.loginUsername\n // const userLoginPassword = data.user?.loginPassword ?? \"\"\n // const userContactCountryCode = data.user.contact.countryCode\n // const userContactPhoneNumber = data.user.contact.phoneNumber\n\n // // validate the contact no only can be digit in text only\n // // validate the country code in prefix\n // // await validateUserContact(userContactCountryCode, userContactPhoneNumber)\n\n // // validate login username\n // // validateLoginUsernameFormat(userLoginUsername)\n\n // // validate login password\n // // if (userLoginPassword) {\n // // validateLoginPasswordFormat(userLoginPassword)\n // // }\n\n // // check the username duplicated?\n // const checkUsername = await userModel.list({\n // limit: 1,\n // offset: 0,\n // orderBy: {\n // [`${ModelUserFields.user_id}`]: \"asc\"\n // },\n // include: [],\n // where: {\n // [`${ModelUserFields.login_username}`]: data.user.loginUsername,\n // [`${ModelUserFields.isdelete}`]: false,\n // [`${ModelUserFields.istrash}`]: false,\n // [`${ModelUserFields.accountid}`]: rest.accountId,\n // },\n // })\n\n // // console.log('ch', checkUsername)\n\n // if (checkUsername.length > 0) {\n // if (Number(checkUsername[0]?.user_id) !== Number(id)) { // if not self user id\n // throwError(`Duplicated username: ${data.user.loginUsername}(${checkUsername[0]?.user_type})`)\n // }\n // }\n\n // // validation before insertion\n // // if (_userType === \"member\" && \"member\" in data) {\n // // }\n\n // const _data = await getUpdatePayload(\n // _userType,\n // data,\n // {\n // countryCode: userContactCountryCode,\n // phoneNumber: userContactPhoneNumber\n // }\n // )\n\n // if (!_data) {\n // throw new Error(`Invalid update payload: ${JSON.stringify(_data)}`);\n // }\n\n // // update user\n // let responseUser = await userModel.update({ id, data: _data })\n\n // let updateUserId = responseUser.user_id\n\n // let response: any = {}\n\n // if (_userType === \"customer\" && \"customer\" in data) {\n\n // let dataCustomer: CustomerUpdateProps[\"data\"] = {\n // customer: {\n // ...data.customer\n // }\n // }\n\n // await customerService.updateCustomer({ userId: Number(updateUserId), data: dataCustomer })\n\n // response = await customerService.getCustomer({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"operator\" && \"operator\" in data) {\n\n // let dataOperator: OperatorUpdateProps[\"data\"] = {\n // operator: {\n // ...data.operator\n // }\n // }\n\n // await operatorService.updateOperator({ userId: Number(updateUserId), data: dataOperator })\n\n // response = await operatorService.getOperator({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"administrator\" && \"administrator\" in data) {\n\n // let dataCustomer: AdministratorUpdateProps[\"data\"] = {\n // administrator: {\n // ...data.administrator\n // }\n // }\n\n // await administratorService.updateAdministrator({ userId: Number(updateUserId), data: dataCustomer })\n\n // // replace user prop\n // await userPropService.replaceUserProp({\n // userPropType: \"LOCATION_ID\",\n // data: {\n // userProp: {\n // userId: Number(updateUserId),\n // locationIds: data.props.locationIds\n // }\n // }\n // })\n\n // response = await administratorService.getAdministrator({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"worker\" && \"worker\" in data) {\n\n // let dataWorker: WorkerUpdateProps[\"data\"] = {\n // worker: {\n // ...data.worker\n // }\n // }\n\n // await workerService.updateWorker({ userId: Number(updateUserId), data: dataWorker })\n\n // // replace user prop\n // await userPropService.replaceUserProp({\n // userPropType: \"LOCATION_ID\",\n // data: {\n // userProp: {\n // userId: Number(updateUserId),\n // locationIds: data.props.locationIds\n // }\n // }\n // })\n\n // response = await workerService.getWorker({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"driver\" && \"driver\" in data) {\n\n // let dataDriver: DriverUpdateProps[\"data\"] = {\n // driver: {\n // ...data.driver\n // }\n // }\n\n // await driverService.updateDriver({ userId: Number(updateUserId), data: dataDriver })\n\n // // replace user prop\n // await userPropService.replaceUserProp({\n // userPropType: \"LOCATION_ID\",\n // data: {\n // userProp: {\n // userId: Number(updateUserId),\n // locationIds: data.props.locationIds\n // }\n // }\n // })\n\n // response = await driverService.getDriver({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"member\" && \"member\" in data) {\n\n // let dataMember: MemberUpdateProps[\"data\"] = {\n // member: {\n // ...data.member\n // }\n // }\n\n // await memberService.updateMember({ userId: Number(updateUserId), data: dataMember })\n\n // // replace user prop\n // // await userPropService.replaceUserProp({\n // // userPropType: \"LOCATION_ID\",\n // // data: {\n // // userProp: {\n // // userId: Number(updateUserId),\n // // locationIds: data.props.locationIds\n // // }\n // // }\n // // })\n\n // response = await memberService.getUserMember({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"agent\" && \"agent\" in data) {\n\n // let dataAgent: AgentUpdateProps[\"data\"] = {\n // agent: {\n // ...data.agent\n // }\n // }\n\n // await agentService.updateAgent({ userId: Number(updateUserId), data: dataAgent })\n\n // // replace user prop\n // // await userPropService.replaceUserProp({\n // // userPropType: \"LOCATION_ID\",\n // // data: {\n // // userProp: {\n // // userId: Number(updateUserId),\n // // locationIds: data.props.locationIds\n // // }\n // // }\n // // })\n\n // response = await agentService.getAgent({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // if (_userType === \"retailer\" && \"retailer\" in data) {\n\n // let dataRetailer: RetailerUpdateProps[\"data\"] = {\n // retailer: {\n // ...data.retailer\n // }\n // }\n\n // await retailerService.updateRetailer({ userId: Number(updateUserId), data: dataRetailer })\n\n // response = await retailerService.getRetailer({ id: Number(updateUserId), datatypes: [] })\n\n // }\n\n // return response\n // }\n\n const getUserMe = async () => {\n\n const id = userId\n\n const data = await userService.getUser({ id: userId, datatypes: [] })\n\n return data\n };\n\n const updateUserMe = async ({\n firstName = \"\",\n lastName = \"\",\n address = \"\"\n }: UserMeUpdateProps) => {\n\n const user = await userService.getUser({ id: Number(userId), datatypes: [] })\n\n // console.log('user', user)\n\n // check the userId is valid\n if (!user?.user_id) {\n throwError(`Invalid user id in auth token`)\n }\n\n // change user information\n await userModel.update({\n id: Number(userId),\n data: {\n [`${ModelUserFields.firstname}`]: firstName,\n [`${ModelUserFields.lastname}`]: lastName,\n [`${ModelUserFields.address}`]: address,\n }\n })\n\n return await userService.getUser({ id: Number(userId), datatypes: [] })\n\n }\n\n const removeUserMe = async () => {\n\n const response = await userService.suspendUsers({ ids: [BigInt(userId)] })\n\n return response\n };\n\n const changePasswordUserMe = async ({\n currentPassword,\n confirmPassword,\n newPassword\n }: UserMeChangePasswordProps) => {\n\n const accountId = rest?.accountId ?? 0\n const accountService = AccountService({ ...rest, isOperator: true })\n\n const user = await userService.getUser({ id: Number(userId), datatypes: [], includePassword: true })\n const account = await accountService.getAccount({ id: Number(accountId), datatypes: [] })\n\n // console.log('user', user)\n // console.log('account', account)\n\n // check the accountId / userId is valid\n if (!user?.user_id) {\n throwError(`Invalid user id in auth token`)\n }\n\n if (Object.keys(account).length <= 0) { // must have account id record\n throwError(`Invalid account id in auth token`)\n }\n\n // new password cannot same with current password\n if (newPassword === currentPassword) {\n throwError(`New and current password cannot be same`)\n }\n\n // new password must same with confirm\n if (newPassword !== confirmPassword) {\n throwError(`New and confirm password not matched`)\n }\n\n // validate the login password new format\n validateLoginPasswordFormat(newPassword);\n\n // check the current password\n try {\n const decryptedPass = await verifyPassword(currentPassword, user?.password)\n // console.log('decryptedPass', decryptedPass)\n\n if (!decryptedPass) {\n throw Error(`Invalid current password`)\n }\n\n } catch (error: any) {\n throwError(`Auth Token: ${error?.message}`)\n }\n\n // perform update credential\n const responseUser = await userService.replacePassword({\n id: Number(userId),\n data: {\n unhashLoginPassword: newPassword\n },\n isOperator: Boolean(userType === \"operator\")\n })\n\n return responseUser\n\n }\n\n const allowUserTypes = [\"any\"] as const\n\n const methodConfigs = {\n getUserMe: { fn: getUserMe, allowUserTypes, actionName: \"get user/me\" },\n updateUserMe: { fn: updateUserMe, allowUserTypes, actionName: \"update user/me\" },\n changePasswordUserMe: { fn: changePasswordUserMe, allowUserTypes, actionName: \"change password user/me\" },\n removeUserMe: { fn: removeUserMe, allowUserTypes, actionName: \"remove user/me\" },\n };\n\n return ServiceFactory(\"UserMeService\", rest, methodConfigs);\n\n}\n\n"]}
@@ -46,6 +46,9 @@ export type UserListProps = QueryList & {
46
46
  export type UserRemoveProps = {
47
47
  ids: BigInt[];
48
48
  };
49
+ export type UserSuspendProps = {
50
+ ids: BigInt[];
51
+ };
49
52
  export type User = {
50
53
  loginUsername: string;
51
54
  loginPassword: string;
@@ -134,7 +137,6 @@ export type UserReplacePasswordProps = {
134
137
  };
135
138
  export declare const loginUsernameReservedWords: string[];
136
139
  export declare const loginUsernameSchema: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
137
- export declare const loginPasswordSchema: z.ZodString;
138
140
  export declare const UserService: (props: UserServiceProps) => {
139
141
  getUser: (args_0: UserGetProps) => Promise<any>;
140
142
  getUserByUsername: (args_0: UserGetByUsernameProps) => Promise<any>;
@@ -146,6 +148,25 @@ export declare const UserService: (props: UserServiceProps) => {
146
148
  updateUser: (args_0: UserUpdateProps) => Promise<any>;
147
149
  replacePassword: (args_0: UserReplacePasswordProps) => Promise<any>;
148
150
  removeUsers: (args_0: UserRemoveProps) => Promise<any[]>;
151
+ suspendUsers: (args_0: UserSuspendProps) => Promise<{
152
+ createdatetime: Date | null;
153
+ createuserid: bigint;
154
+ updatedatetime: Date | null;
155
+ updateuserid: bigint;
156
+ isdelete: boolean | null;
157
+ istrash: boolean | null;
158
+ accountid: bigint;
159
+ status: boolean | null;
160
+ user_id: bigint;
161
+ login_username: string | null;
162
+ user_type: string | null;
163
+ firstname: string | null;
164
+ lastname: string | null;
165
+ email: string | null;
166
+ address: string | null;
167
+ contact_country_code: number;
168
+ contact_phone_number: string | null;
169
+ }>;
149
170
  getDataTypes: () => any[];
150
171
  validateUserContact: (countryCode: number, phoneNumber: string) => Promise<boolean>;
151
172
  };