storemw-core-api 1.0.143 → 1.0.144

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 (92) hide show
  1. package/dist/app.js +1 -0
  2. package/dist/app.js.map +1 -1
  3. package/dist/controllers/index.d.ts +2 -0
  4. package/dist/controllers/index.js +13 -2
  5. package/dist/controllers/index.js.map +1 -1
  6. package/dist/controllers/subscription/account/accountSubscribeController.d.ts +9 -0
  7. package/dist/controllers/subscription/account/accountSubscribeController.js +105 -0
  8. package/dist/controllers/subscription/account/accountSubscribeController.js.map +1 -0
  9. package/dist/controllers/subscription/plan/subscribePlanController.d.ts +11 -0
  10. package/dist/controllers/subscription/plan/subscribePlanController.js +163 -0
  11. package/dist/controllers/subscription/plan/subscribePlanController.js.map +1 -0
  12. package/dist/features/auth_token/authTokenRegister.d.ts +5 -0
  13. package/dist/features/auth_token/authTokenRegister.js +11 -0
  14. package/dist/features/auth_token/authTokenRegister.js.map +1 -0
  15. package/dist/features/auth_token/authTokenRegistry.d.ts +2 -0
  16. package/dist/features/auth_token/authTokenRegistry.js +16 -0
  17. package/dist/features/auth_token/authTokenRegistry.js.map +1 -0
  18. package/dist/features/auth_token/authTokenType.d.ts +5 -0
  19. package/dist/features/auth_token/authTokenType.js +3 -0
  20. package/dist/features/auth_token/authTokenType.js.map +1 -0
  21. package/dist/features/index.d.ts +3 -0
  22. package/dist/features/index.js +5 -1
  23. package/dist/features/index.js.map +1 -1
  24. package/dist/middlewares/route/index.d.ts +2 -0
  25. package/dist/middlewares/route/index.js +13 -2
  26. package/dist/middlewares/route/index.js.map +1 -1
  27. package/dist/middlewares/route/validateSubscriptionAccount.d.ts +5 -0
  28. package/dist/middlewares/route/validateSubscriptionAccount.js +20 -0
  29. package/dist/middlewares/route/validateSubscriptionAccount.js.map +1 -0
  30. package/dist/middlewares/route/validateSubscriptionPlan.d.ts +6 -0
  31. package/dist/middlewares/route/validateSubscriptionPlan.js +24 -0
  32. package/dist/middlewares/route/validateSubscriptionPlan.js.map +1 -0
  33. package/dist/models/index.d.ts +5 -1
  34. package/dist/models/index.js +8 -2
  35. package/dist/models/index.js.map +1 -1
  36. package/dist/models/subscription/account/AccountSubscribeModel.d.ts +257 -0
  37. package/dist/models/subscription/account/AccountSubscribeModel.js +13 -0
  38. package/dist/models/subscription/account/AccountSubscribeModel.js.map +1 -0
  39. package/dist/models/subscription/plan/SubscribePlanModel.d.ts +257 -0
  40. package/dist/models/subscription/plan/SubscribePlanModel.js +13 -0
  41. package/dist/models/subscription/plan/SubscribePlanModel.js.map +1 -0
  42. package/dist/routes/index.d.ts +1 -0
  43. package/dist/routes/index.js +3 -1
  44. package/dist/routes/index.js.map +1 -1
  45. package/dist/routes/subscription/subscriptionsAccountRoutes.d.ts +2 -0
  46. package/dist/routes/subscription/subscriptionsAccountRoutes.js +15 -0
  47. package/dist/routes/subscription/subscriptionsAccountRoutes.js.map +1 -0
  48. package/dist/routes/subscription/subscriptionsAccountsRoutes.d.ts +2 -0
  49. package/dist/routes/subscription/subscriptionsAccountsRoutes.js +11 -0
  50. package/dist/routes/subscription/subscriptionsAccountsRoutes.js.map +1 -0
  51. package/dist/routes/subscription/subscriptionsPlanRoutes.d.ts +2 -0
  52. package/dist/routes/subscription/subscriptionsPlanRoutes.js +15 -0
  53. package/dist/routes/subscription/subscriptionsPlanRoutes.js.map +1 -0
  54. package/dist/routes/subscription/subscriptionsPlansRoutes.d.ts +2 -0
  55. package/dist/routes/subscription/subscriptionsPlansRoutes.js +13 -0
  56. package/dist/routes/subscription/subscriptionsPlansRoutes.js.map +1 -0
  57. package/dist/routes/subscription/subscriptionsRoutes.d.ts +2 -0
  58. package/dist/routes/subscription/subscriptionsRoutes.js +17 -0
  59. package/dist/routes/subscription/subscriptionsRoutes.js.map +1 -0
  60. package/dist/schema/middleware/route/index.d.ts +4 -0
  61. package/dist/schema/middleware/route/index.js +5 -1
  62. package/dist/schema/middleware/route/index.js.map +1 -1
  63. package/dist/schema/middleware/route/schemaSubscriptionAccount.d.ts +4 -0
  64. package/dist/schema/middleware/route/schemaSubscriptionAccount.js +10 -0
  65. package/dist/schema/middleware/route/schemaSubscriptionAccount.js.map +1 -0
  66. package/dist/schema/middleware/route/schemaSubscriptionPlan.d.ts +4 -0
  67. package/dist/schema/middleware/route/schemaSubscriptionPlan.js +10 -0
  68. package/dist/schema/middleware/route/schemaSubscriptionPlan.js.map +1 -0
  69. package/dist/schema/payload/index.d.ts +4 -0
  70. package/dist/schema/payload/index.js +9 -2
  71. package/dist/schema/payload/index.js.map +1 -1
  72. package/dist/schema/payload/subscription/schemaAccountSubscribe.d.ts +126 -0
  73. package/dist/schema/payload/subscription/schemaAccountSubscribe.js +31 -0
  74. package/dist/schema/payload/subscription/schemaAccountSubscribe.js.map +1 -0
  75. package/dist/schema/payload/subscription/schemaSubscribePlan.d.ts +259 -0
  76. package/dist/schema/payload/subscription/schemaSubscribePlan.js +41 -0
  77. package/dist/schema/payload/subscription/schemaSubscribePlan.js.map +1 -0
  78. package/dist/services/auth/AuthService.d.ts +8 -7
  79. package/dist/services/auth/AuthService.js +6 -1
  80. package/dist/services/auth/AuthService.js.map +1 -1
  81. package/dist/services/index.d.ts +5 -1
  82. package/dist/services/index.js +7 -1
  83. package/dist/services/index.js.map +1 -1
  84. package/dist/services/others/NumberDateSequenceService.d.ts +1 -1
  85. package/dist/services/subscription/account/AccountSubscribeService.d.ts +43 -0
  86. package/dist/services/subscription/account/AccountSubscribeService.js +193 -0
  87. package/dist/services/subscription/account/AccountSubscribeService.js.map +1 -0
  88. package/dist/services/subscription/plan/SubscribePlanService.d.ts +63 -0
  89. package/dist/services/subscription/plan/SubscribePlanService.js +175 -0
  90. package/dist/services/subscription/plan/SubscribePlanService.js.map +1 -0
  91. package/package.json +11 -11
  92. package/prisma/schema.prisma +40 -0
@@ -1 +1 @@
1
- {"version":3,"file":"AuthService.js","sourceRoot":"","sources":["../../../src/services/auth/AuthService.ts"],"names":[],"mappings":";;;AAAA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AI;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"]}
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;AAE1E,yCAAoF;AAEvE,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;AAkCH,MAAM,WAAW,GAAG,CAAC,KAAuB,EAAE,EAAE;IAEnD,MAAM,EACF,SAAS,EACT,QAAQ,GAAG,eAAe,EAC1B,GAAG,IAAI,EACV,GAAG,KAAK,CAAA;IAET,IAAI,SAAS,GAAoD,IAAI,CAAA;IAErE,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,yB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AAG,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,MAAM,MAAM,GAAoB;YAC5B,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;QAED,wCAAwC;QACxC,MAAM,SAAS,GAAG,MAAM,wBAAa,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAA;QAEnE,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAA;IACzC,CAAC,CAAC;IAEF,OAAO;QACH,YAAY;QACZ,eAAe,EAAf,uBAAe;KAClB,CAAA;AAEL,CAAC,CAAA;AA9PY,QAAA,WAAW,eA8PvB","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\nimport { AuthTokenHook, FeatureAuthTokenSuccessAuthenticateProps } from \"@/features\"\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 AuthTokenResult = {\n token: string\n account: any\n user: any\n user_locations: any[]\n is_owner: boolean\n}\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 let hookSetup: FeatureAuthTokenSuccessAuthenticateProps | null = null\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 const result: AuthTokenResult = {\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 // Call the consumer hook, if registered\n const newResult = await AuthTokenHook.onSuccessAuthenticate(result)\n\n return newResult ? newResult : result\n };\n\n return {\n getAuthToken,\n verifyAuthToken,\n }\n\n}\n\n"]}
@@ -1,5 +1,5 @@
1
1
  export { AuthService, authTypes } from "../services/auth/AuthService";
2
- export type { AuthServiceProps, AuthType, AuthJwtToken, AuthGetTokenProps } from "../services/auth/AuthService";
2
+ export type { AuthServiceProps, AuthType, AuthTokenResult, AuthJwtToken, AuthGetTokenProps } from "../services/auth/AuthService";
3
3
  export { AccessKeyService, accessKeyUserTypes, accessKeyStatus } from "../services/access_key/AccessKeyService";
4
4
  export type { AccessKeyServiceProps, AccessKeyStatus, AccessKeyUserType, AccessKeyCreateProps, AccessKeyRevokeProps } from "../services/access_key/AccessKeyService";
5
5
  export { AccessControlService } from "../services/access_control/AccessControlService";
@@ -10,6 +10,10 @@ export { AccountService } from "../services/account/AccountService";
10
10
  export type { AccountServiceProps, Account, AccountGetProps, AccountListProps, AccountCreateProps, AccountUpdateProps } from "../services/account/AccountService";
11
11
  export { BusinessService } from "../services/business/BusinessService";
12
12
  export type { BusinessServiceProps, Business, BusinessGetProps, BusinessListProps, BusinessCreateProps, BusinessUpdateProps } from "../services/business/BusinessService";
13
+ export { SubscribePlanService, subscribeCurrencies, subscribePlanBillingCycles } from "../services/subscription/plan/SubscribePlanService";
14
+ export type { SubscribePlanServiceProps, SubscribePlan, SubscribePlanBillingCycle, SubscribePlanCurrency, SubscribePlanGetProps, SubscribePlanListProps, SubscribePlanCreateProps, SubscribePlanUpdateProps } from "../services/subscription/plan/SubscribePlanService";
15
+ export { AccountSubscribeService } from "../services/subscription/account/AccountSubscribeService";
16
+ export type { AccountSubscribeServiceProps, AccountSubscribe, AccountSubscribeGetProps, AccountSubscribeListProps, AccountSubscribeCreateProps, AccountSubscribeCancelProps } from "../services/subscription/account/AccountSubscribeService";
13
17
  export { UserService, userTypes, userParentSqlSelect } from "../services/user/UserService";
14
18
  export type { UserServiceProps, UserType, UserGetProps, UserListProps, UserCreateProps, UserUpdateProps, UserRemoveProps, UserReplacePasswordProps } from "../services/user/UserService";
15
19
  export { UserMeService } from "../services/user/UserMeService";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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.userParentSqlSelect = 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.userParentSqlSelect = exports.userTypes = exports.UserService = exports.AccountSubscribeService = exports.subscribePlanBillingCycles = exports.subscribeCurrencies = exports.SubscribePlanService = 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; } });
@@ -17,6 +17,12 @@ var AccountService_1 = require("../services/account/AccountService");
17
17
  Object.defineProperty(exports, "AccountService", { enumerable: true, get: function () { return AccountService_1.AccountService; } });
18
18
  var BusinessService_1 = require("../services/business/BusinessService");
19
19
  Object.defineProperty(exports, "BusinessService", { enumerable: true, get: function () { return BusinessService_1.BusinessService; } });
20
+ var SubscribePlanService_1 = require("../services/subscription/plan/SubscribePlanService");
21
+ Object.defineProperty(exports, "SubscribePlanService", { enumerable: true, get: function () { return SubscribePlanService_1.SubscribePlanService; } });
22
+ Object.defineProperty(exports, "subscribeCurrencies", { enumerable: true, get: function () { return SubscribePlanService_1.subscribeCurrencies; } });
23
+ Object.defineProperty(exports, "subscribePlanBillingCycles", { enumerable: true, get: function () { return SubscribePlanService_1.subscribePlanBillingCycles; } });
24
+ var AccountSubscribeService_1 = require("../services/subscription/account/AccountSubscribeService");
25
+ Object.defineProperty(exports, "AccountSubscribeService", { enumerable: true, get: function () { return AccountSubscribeService_1.AccountSubscribeService; } });
20
26
  var UserService_1 = require("../services/user/UserService");
21
27
  Object.defineProperty(exports, "UserService", { enumerable: true, get: function () { return UserService_1.UserService; } });
22
28
  Object.defineProperty(exports, "userTypes", { enumerable: true, get: function () { return UserService_1.userTypes; } });
@@ -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,2DAAyF;AAAhF,0GAAA,WAAW,OAAA;AAAE,wGAAA,SAAS,OAAA;AAAE,kHAAA,mBAAmB,OAAA;AAGpD,+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,+FAA+F;AAC/F,wIAAwI;AACxI,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, userParentSqlSelect } 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\""]}
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,0FAAyI;AAAhI,4HAAA,oBAAoB,OAAA;AAAE,2HAAA,mBAAmB,OAAA;AAAE,kIAAA,0BAA0B,OAAA;AAE9E,mGAAiG;AAAxF,kIAAA,uBAAuB,OAAA;AAGhC,2DAAyF;AAAhF,0GAAA,WAAW,OAAA;AAAE,wGAAA,SAAS,OAAA;AAAE,kHAAA,mBAAmB,OAAA;AAGpD,+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,+FAA+F;AAC/F,wIAAwI;AACxI,8EAA4E;AAAnE,4HAAA,oBAAoB,OAAA","sourcesContent":["export { AuthService, authTypes } from \"@/services/auth/AuthService\"\nexport type { AuthServiceProps, AuthType, AuthTokenResult, 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 { SubscribePlanService, subscribeCurrencies, subscribePlanBillingCycles } from \"@/services/subscription/plan/SubscribePlanService\"\nexport type { SubscribePlanServiceProps, SubscribePlan, SubscribePlanBillingCycle, SubscribePlanCurrency, SubscribePlanGetProps, SubscribePlanListProps, SubscribePlanCreateProps, SubscribePlanUpdateProps } from \"@/services/subscription/plan/SubscribePlanService\"\nexport { AccountSubscribeService } from \"@/services/subscription/account/AccountSubscribeService\"\nexport type { AccountSubscribeServiceProps, AccountSubscribe, AccountSubscribeGetProps, AccountSubscribeListProps, AccountSubscribeCreateProps, AccountSubscribeCancelProps } from \"@/services/subscription/account/AccountSubscribeService\"\n\nexport { UserService, userTypes, userParentSqlSelect } 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\""]}
@@ -17,7 +17,7 @@ export type NumberDateSequenceInitProps = InjectionFieldModuleRef & {
17
17
  };
18
18
  export declare const NumberDateSequenceService: (props: NumberDateSequenceServiceProps) => {
19
19
  initNumberDateSequence: ({ resetMethod, formatOutputLength, sequenceDate, ...rest }: NumberDateSequenceInitProps) => Promise<{
20
- resetMethod: "yearly" | "monthly" | "daily";
20
+ resetMethod: "monthly" | "yearly" | "daily";
21
21
  sequenceNumber: {
22
22
  current: number;
23
23
  next: number;
@@ -0,0 +1,43 @@
1
+ import { QueryList, QueryGet } from "../../../schema/common";
2
+ import { DefaultServiceProps } from "../../../utils";
3
+ export type AccountSubscribeServiceProps = DefaultServiceProps & {};
4
+ export type AccountSubscribeGetProps = QueryGet & {
5
+ accountSubscriptionId: number;
6
+ };
7
+ export type AccountSubscribeListProps = QueryList & {};
8
+ export type AccountSubscribeCancelProps = {
9
+ accountSubscriptionId: BigInt;
10
+ };
11
+ export type AccountSubscribe = {
12
+ accountId: number;
13
+ subscribePlanId: number;
14
+ subscribeStartDate?: Date;
15
+ };
16
+ export type AccountSubscribeCreateProps = {
17
+ data: AccountSubscribe;
18
+ };
19
+ export declare const AccountSubscribeService: (props: AccountSubscribeServiceProps) => {
20
+ getAccountSubscribe: ({ accountSubscriptionId, datatypes }: AccountSubscribeGetProps) => Promise<any>;
21
+ createAccountSubscribe: ({ data }: AccountSubscribeCreateProps) => Promise<any>;
22
+ cancelAccountSubscribe: ({ accountSubscriptionId }: AccountSubscribeCancelProps) => Promise<{
23
+ createdatetime: Date | null;
24
+ createuserid: bigint;
25
+ updatedatetime: Date | null;
26
+ updateuserid: bigint;
27
+ isdelete: boolean | null;
28
+ istrash: boolean | null;
29
+ accountid: bigint;
30
+ status: boolean | null;
31
+ account_id: bigint;
32
+ subscribe_plan_id: bigint;
33
+ account_subscription_id: bigint;
34
+ subscription_start_date: Date | null;
35
+ subscription_end_date: Date | null;
36
+ is_cancel: boolean | null;
37
+ cancel_datetime: Date | null;
38
+ }>;
39
+ listAccountSubscribes: ({ limit, offset, filters, sortfield, sortorder, datatypes }: AccountSubscribeListProps) => Promise<{
40
+ data: any[];
41
+ total: number;
42
+ }>;
43
+ };
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AccountSubscribeService = void 0;
4
+ const utils_1 = require("../../../utils");
5
+ const models_1 = require("../../../models");
6
+ const lib_1 = require("../../../lib");
7
+ const services_1 = require("../../../services");
8
+ const models_2 = require("../../../models");
9
+ // export type AccountSubscribeUpdateProps = {
10
+ // subscribePlanId: number,
11
+ // data: AccountSubscribe
12
+ // }
13
+ const getCreatePayload = (data, startDate, endDate) => {
14
+ return {
15
+ [`${models_1.ModelAccountSubscribeFields.account_id}`]: data.accountId,
16
+ [`${models_1.ModelAccountSubscribeFields.subscribe_plan_id}`]: data.subscribePlanId,
17
+ [`${models_1.ModelAccountSubscribeFields.subscription_start_date}`]: startDate,
18
+ [`${models_1.ModelAccountSubscribeFields.subscription_end_date}`]: endDate,
19
+ [`${models_1.ModelAccountSubscribeFields.status}`]: true // must active
20
+ };
21
+ };
22
+ // const getUpdatePayload = (data: AccountSubscribeUpdateProps["data"]) => {
23
+ // return {
24
+ // [`${ModelAccountSubscribeFields.name}`]: data.name,
25
+ // [`${ModelAccountSubscribeFields.short_description}`]: data.shortDescription,
26
+ // [`${ModelAccountSubscribeFields.full_description}`]: data.fullDescription,
27
+ // [`${ModelAccountSubscribeFields.price}`]: Number(data.price),
28
+ // [`${ModelAccountSubscribeFields.currency}`]: data.currency,
29
+ // [`${ModelAccountSubscribeFields.billing_cycle}`]: data.billingCycle,
30
+ // [`${ModelAccountSubscribeFields.status}`]: Boolean(data.status)
31
+ // }
32
+ // }
33
+ let mainSqlSelect = {
34
+ [`accsub.${models_1.ModelAccountSubscribeFields.account_subscription_id}`]: "account_subscription_id",
35
+ [`accsub.${models_1.ModelAccountSubscribeFields.account_id}`]: "account_id",
36
+ [`accsub.${models_1.ModelAccountSubscribeFields.subscribe_plan_id}`]: "subscribe_plan_id",
37
+ [`accsub.${models_1.ModelAccountSubscribeFields.subscription_start_date}`]: "subscription_start_date",
38
+ [`accsub.${models_1.ModelAccountSubscribeFields.subscription_end_date}`]: "subscription_end_date",
39
+ [`accsub.${models_1.ModelAccountSubscribeFields.status}`]: "status",
40
+ [`accsub.${models_1.ModelAccountSubscribeFields.is_cancel}`]: "is_cancel",
41
+ [`accsub.${models_1.ModelAccountSubscribeFields.cancel_datetime}`]: "cancel_datetime",
42
+ };
43
+ let subscribePlanSqlSelect = {
44
+ [`subplan.${models_1.ModelSubscribePlanFields.name}`]: "subscribe_plan_name",
45
+ [`subplan.${models_1.ModelSubscribePlanFields.billing_cycle}`]: "subscribe_plan_billing_cycle",
46
+ [`subplan.${models_1.ModelSubscribePlanFields.currency}`]: "subscribe_plan_currency",
47
+ [`subplan.${models_1.ModelSubscribePlanFields.short_description}`]: "subscribe_plan_short_description",
48
+ [`subplan.${models_1.ModelSubscribePlanFields.full_description}`]: "subscribe_plan_full_description",
49
+ [`subplan.${models_1.ModelSubscribePlanFields.price}::float`]: "subscribe_plan_price",
50
+ [`subplan.${models_1.ModelSubscribePlanFields.status}`]: "subscribe_plan_status",
51
+ };
52
+ let defaultSqlSelect = {
53
+ [`accsub.${models_1.ModelAccountSubscribeFields.createdatetime}`]: "createdatetime",
54
+ [`creator.${models_1.ModelUserFields.login_username}`]: "createusername",
55
+ [`accsub.${models_1.ModelAccountSubscribeFields.updatedatetime}`]: "updatedatetime",
56
+ [`updater.${models_1.ModelUserFields.login_username}`]: "updateusername",
57
+ [`accsub.${models_1.ModelAccountSubscribeFields.isdelete}`]: "isdelete",
58
+ [`accsub.${models_1.ModelAccountSubscribeFields.istrash}`]: "istrash",
59
+ [`accsub.${models_1.ModelAccountSubscribeFields.accountid}`]: "accountid",
60
+ };
61
+ const AccountSubscribeService = (props) => {
62
+ const { ...rest } = props;
63
+ const accountModel = (0, models_2.AccountModel)({ ...rest, isOperator: true });
64
+ const accountSubscribeModel = (0, models_1.AccountSubscribeModel)({ ...rest, isOperator: true });
65
+ const subscribePlanService = (0, services_1.SubscribePlanService)({ ...rest, isOperator: true });
66
+ const createAccountSubscribe = async ({ data }) => {
67
+ const accountId = data.accountId ?? 0;
68
+ const subscribePlanId = data.subscribePlanId ?? 0;
69
+ const subscribeStartDate = data.subscribeStartDate ?? new Date();
70
+ // validate account
71
+ const account = await accountModel.get({ id: Number(accountId) });
72
+ if (!account?.account_id) {
73
+ throw new Error(`Invalid account id: ${accountId}`);
74
+ }
75
+ if (account?.status !== true) {
76
+ throw new Error(`Account is inactive: ${accountId}`);
77
+ }
78
+ // get the subscribe plan information
79
+ const subscribePlan = await subscribePlanService.getSubscribePlan({ id: Number(subscribePlanId), datatypes: [] });
80
+ if (!subscribePlan?.subscribe_plan_id) {
81
+ throw new Error(`Invalid subscribe plan id: ${subscribePlanId}`);
82
+ }
83
+ const subscribePlanBillingCycle = subscribePlan?.billing_cycle;
84
+ if (!subscribePlanBillingCycle) {
85
+ throw new Error(`Invalid subscribe plan billing cycle: ${subscribePlanId}`);
86
+ }
87
+ // get end of subscription date
88
+ const subscribeEndDate = subscribePlanService.getNextBillingEndDate(subscribeStartDate, subscribePlanBillingCycle);
89
+ const _data = getCreatePayload(data, subscribeStartDate, subscribeEndDate);
90
+ if (!_data) {
91
+ throw new Error(`Invalid create account subscribe payload: ${JSON.stringify(_data)}`);
92
+ }
93
+ let response = await accountSubscribeModel.create({ data: _data });
94
+ return await getAccountSubscribe({ accountSubscriptionId: Number(response?.account_subscription_id ?? 0), datatypes: [] });
95
+ };
96
+ const getAccountSubscribe = async ({ accountSubscriptionId, datatypes = [] }) => {
97
+ let { data } = await listAccountSubscribes({
98
+ limit: 1,
99
+ offset: 0,
100
+ filters: [{ field: `${models_1.ModelAccountSubscribeFields.account_subscription_id}`, operator: "=", value: accountSubscriptionId }],
101
+ sortfield: `${models_1.ModelAccountSubscribeFields.account_subscription_id}`,
102
+ sortorder: "ASC",
103
+ datatypes
104
+ });
105
+ return data[0] ?? null;
106
+ };
107
+ const listAccountSubscribes = async ({ limit, offset, filters = [], sortfield, sortorder, datatypes = [] }) => {
108
+ let data = [];
109
+ let sqlSelect = [
110
+ `COUNT(accsub.*) OVER() as filtered_count`,
111
+ (0, lib_1.buildSqlSelect)(``, mainSqlSelect),
112
+ (0, lib_1.buildSqlSelect)(``, subscribePlanSqlSelect),
113
+ (0, lib_1.buildSqlSelect)(``, defaultSqlSelect)
114
+ ];
115
+ let sqlRelation = [
116
+ (0, lib_1.buildSqlRelation)("left", "subplan", "subscribe_plans", "subplan", ["accsub.subscribe_plan_id = subplan.subscribe_plan_id", "subplan.isdelete = false", "subplan.istrash = false"]),
117
+ (0, lib_1.buildSqlRelation)("left", "subplan", "users", "creator", ["accsub.createuserid = creator.user_id", "creator.isdelete = false", "creator.istrash = false"]),
118
+ (0, lib_1.buildSqlRelation)("left", "subplan", "users", "updater", ["accsub.updateuserid = updater.user_id", "updater.isdelete = false", "updater.istrash = false"])
119
+ ];
120
+ let sqlGroupBy = [
121
+ ...Object.keys(mainSqlSelect),
122
+ ...Object.keys(subscribePlanSqlSelect),
123
+ ...Object.keys(defaultSqlSelect)
124
+ ];
125
+ let filterColumns = {
126
+ ...mainSqlSelect,
127
+ ...subscribePlanSqlSelect,
128
+ ...defaultSqlSelect
129
+ };
130
+ let sqlWhere = [
131
+ `accsub.isdelete = false`,
132
+ `accsub.istrash = false`,
133
+ ...(filters.length ? [(0, lib_1.buildSqlWhere)(filters, filterColumns)?.where] : []),
134
+ ];
135
+ let sqlOrderby = (0, lib_1.buildSqlOrderBy)(sortfield, sortorder);
136
+ let sqlLimitOffset = (0, lib_1.buildSqlLimitOffset)(limit, offset);
137
+ const sqlRaw = (0, lib_1.buildSqlRawSelect)({
138
+ tableName: "account_subscriptions",
139
+ mainAlias: "accsub",
140
+ accountId: rest.accountId,
141
+ sqlSelect,
142
+ sqlRelation,
143
+ sqlWhere,
144
+ sqlGroupBy,
145
+ sqlOrderby,
146
+ sqlLimitOffset
147
+ });
148
+ data = await accountSubscribeModel.raw(sqlRaw);
149
+ const response = {
150
+ data: data.map(({ filtered_count, ...rest }) => rest),
151
+ total: data.length ? Number(data[0].filtered_count) : 0
152
+ };
153
+ return response;
154
+ };
155
+ const cancelAccountSubscribe = async ({ accountSubscriptionId }) => {
156
+ if (!accountSubscriptionId)
157
+ (0, utils_1.throwError)('accountSubscriptionId is required');
158
+ const { total } = await listAccountSubscribes({
159
+ limit: 1,
160
+ offset: 0,
161
+ filters: [
162
+ { field: `${models_1.ModelAccountSubscribeFields.account_subscription_id}`, operator: "=", value: `${accountSubscriptionId}` },
163
+ { field: `${models_1.ModelAccountSubscribeFields.status}`, operator: "=", value: true }
164
+ ],
165
+ sortfield: `${models_1.ModelAccountSubscribeFields.account_subscription_id}`,
166
+ sortorder: "ASC",
167
+ datatypes: []
168
+ });
169
+ if (total <= 0) {
170
+ throw new Error(`Invalid subscription id : ${accountSubscriptionId}`);
171
+ }
172
+ const response = await accountSubscribeModel.update({
173
+ id: Number(accountSubscriptionId),
174
+ data: {
175
+ [`${models_1.ModelAccountSubscribeFields.status}`]: false,
176
+ [`${models_1.ModelAccountSubscribeFields.is_cancel}`]: true,
177
+ [`${models_1.ModelAccountSubscribeFields.cancel_datetime}`]: new Date()
178
+ },
179
+ where: {
180
+ [`${models_1.ModelAccountSubscribeFields.status}`]: true
181
+ }
182
+ });
183
+ return response;
184
+ };
185
+ return {
186
+ getAccountSubscribe,
187
+ createAccountSubscribe,
188
+ cancelAccountSubscribe,
189
+ listAccountSubscribes
190
+ };
191
+ };
192
+ exports.AccountSubscribeService = AccountSubscribeService;
193
+ //# sourceMappingURL=AccountSubscribeService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountSubscribeService.js","sourceRoot":"","sources":["../../../../src/services/subscription/account/AccountSubscribeService.ts"],"names":[],"mappings":";;;AAAA,mCAA+C;AAE/C,qCAQkB;AAMlB,+BAAiI;AAEjI,yCAA4E;AAC5E,qCAAuC;AAyBvC,8CAA8C;AAC9C,+BAA+B;AAC/B,6BAA6B;AAC7B,IAAI;AAEJ,MAAM,gBAAgB,GAAG,CACrB,IAAyC,EACzC,SAAe,EACf,OAAa,EACf,EAAE;IAEA,OAAO;QACH,CAAC,GAAG,oCAA2B,CAAC,UAAU,EAAE,CAAC,EAAE,IAAI,CAAC,SAAS;QAC7D,CAAC,GAAG,oCAA2B,CAAC,iBAAiB,EAAE,CAAC,EAAE,IAAI,CAAC,eAAe;QAC1E,CAAC,GAAG,oCAA2B,CAAC,uBAAuB,EAAE,CAAC,EAAE,SAAS;QACrE,CAAC,GAAG,oCAA2B,CAAC,qBAAqB,EAAE,CAAC,EAAE,OAAO;Q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AAC;YACjC,IAAI,EAAE;gBACF,CAAC,GAAG,oCAA2B,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK;gBAChD,CAAC,GAAG,oCAA2B,CAAC,SAAS,EAAE,CAAC,EAAE,IAAI;gBAClD,CAAC,GAAG,oCAA2B,CAAC,eAAe,EAAE,CAAC,EAAE,IAAI,IAAI,EAAE;aACjE;YACD,KAAK,EAAE;gBACH,CAAC,GAAG,oCAA2B,CAAC,MAAM,EAAE,CAAC,EAAE,IAAI;aAClD;SACJ,CAAC,CAAC;QAEH,OAAO,QAAQ,CAAA;IACnB,CAAC,CAAC;IAEF,OAAO;QACH,mBAAmB;QACnB,sBAAsB;QACtB,sBAAsB;QACtB,qBAAqB;KACxB,CAAA;AAEL,CAAC,CAAA;AA5KY,QAAA,uBAAuB,2BA4KnC","sourcesContent":["import { logError, throwError } from \"@/utils\";\n\nimport {\n ModelUserFields,\n AccountSubscribeModel,\n ModelAccountSubscribeFields,\n ModelAreaFields,\n ModelStateFields,\n ModelCountryFields,\n ModelSubscribePlanFields,\n} from \"@/models\";\n\nimport { QueryList, QueryGet } from \"@/schema/common\";\n\nimport { DefaultServiceProps } from \"@/utils\";\n\nimport { buildSqlRelation, buildSqlRawSelect, buildSqlWhere, buildSqlSelect, buildSqlLimitOffset, buildSqlOrderBy } from \"@/lib\";\n\nimport { SubscribePlanBillingCycle, SubscribePlanService } from \"@/services\"\nimport { AccountModel } from \"@/models\"\n\nexport type AccountSubscribeServiceProps = DefaultServiceProps & {};\n\nexport type AccountSubscribeGetProps = QueryGet & {\n accountSubscriptionId: number,\n};\n\nexport type AccountSubscribeListProps = QueryList & {\n};\n\nexport type AccountSubscribeCancelProps = {\n accountSubscriptionId: BigInt\n};\n\nexport type AccountSubscribe = {\n accountId: number\n subscribePlanId: number\n subscribeStartDate?: Date // optional - if no specify will get current\n}\n\nexport type AccountSubscribeCreateProps = {\n data: AccountSubscribe\n}\n\n// export type AccountSubscribeUpdateProps = {\n// subscribePlanId: number,\n// data: AccountSubscribe\n// }\n\nconst getCreatePayload = (\n data: AccountSubscribeCreateProps[\"data\"],\n startDate: Date,\n endDate: Date\n) => {\n\n return {\n [`${ModelAccountSubscribeFields.account_id}`]: data.accountId,\n [`${ModelAccountSubscribeFields.subscribe_plan_id}`]: data.subscribePlanId,\n [`${ModelAccountSubscribeFields.subscription_start_date}`]: startDate,\n [`${ModelAccountSubscribeFields.subscription_end_date}`]: endDate,\n [`${ModelAccountSubscribeFields.status}`]: true // must active\n }\n\n}\n\n// const getUpdatePayload = (data: AccountSubscribeUpdateProps[\"data\"]) => {\n\n// return {\n// [`${ModelAccountSubscribeFields.name}`]: data.name,\n// [`${ModelAccountSubscribeFields.short_description}`]: data.shortDescription,\n// [`${ModelAccountSubscribeFields.full_description}`]: data.fullDescription,\n// [`${ModelAccountSubscribeFields.price}`]: Number(data.price),\n// [`${ModelAccountSubscribeFields.currency}`]: data.currency,\n\n// [`${ModelAccountSubscribeFields.billing_cycle}`]: data.billingCycle,\n// [`${ModelAccountSubscribeFields.status}`]: Boolean(data.status)\n// }\n\n// }\n\nlet mainSqlSelect = {\n [`accsub.${ModelAccountSubscribeFields.account_subscription_id}`]: \"account_subscription_id\",\n [`accsub.${ModelAccountSubscribeFields.account_id}`]: \"account_id\",\n [`accsub.${ModelAccountSubscribeFields.subscribe_plan_id}`]: \"subscribe_plan_id\",\n [`accsub.${ModelAccountSubscribeFields.subscription_start_date}`]: \"subscription_start_date\",\n [`accsub.${ModelAccountSubscribeFields.subscription_end_date}`]: \"subscription_end_date\",\n [`accsub.${ModelAccountSubscribeFields.status}`]: \"status\",\n [`accsub.${ModelAccountSubscribeFields.is_cancel}`]: \"is_cancel\",\n [`accsub.${ModelAccountSubscribeFields.cancel_datetime}`]: \"cancel_datetime\",\n}\n\nlet subscribePlanSqlSelect = {\n [`subplan.${ModelSubscribePlanFields.name}`]: \"subscribe_plan_name\",\n [`subplan.${ModelSubscribePlanFields.billing_cycle}`]: \"subscribe_plan_billing_cycle\",\n [`subplan.${ModelSubscribePlanFields.currency}`]: \"subscribe_plan_currency\",\n [`subplan.${ModelSubscribePlanFields.short_description}`]: \"subscribe_plan_short_description\",\n [`subplan.${ModelSubscribePlanFields.full_description}`]: \"subscribe_plan_full_description\",\n [`subplan.${ModelSubscribePlanFields.price}::float`]: \"subscribe_plan_price\",\n [`subplan.${ModelSubscribePlanFields.status}`]: \"subscribe_plan_status\",\n}\n\nlet defaultSqlSelect = {\n [`accsub.${ModelAccountSubscribeFields.createdatetime}`]: \"createdatetime\",\n [`creator.${ModelUserFields.login_username}`]: \"createusername\",\n [`accsub.${ModelAccountSubscribeFields.updatedatetime}`]: \"updatedatetime\",\n [`updater.${ModelUserFields.login_username}`]: \"updateusername\",\n [`accsub.${ModelAccountSubscribeFields.isdelete}`]: \"isdelete\",\n [`accsub.${ModelAccountSubscribeFields.istrash}`]: \"istrash\",\n [`accsub.${ModelAccountSubscribeFields.accountid}`]: \"accountid\",\n}\n\nexport const AccountSubscribeService = (props: AccountSubscribeServiceProps) => {\n\n const {\n ...rest\n } = props\n\n const accountModel = AccountModel({ ...rest, isOperator: true })\n const accountSubscribeModel = AccountSubscribeModel({ ...rest, isOperator: true })\n const subscribePlanService = SubscribePlanService({ ...rest, isOperator: true })\n\n const createAccountSubscribe = async ({ data }: AccountSubscribeCreateProps) => {\n\n const accountId = data.accountId ?? 0\n const subscribePlanId = data.subscribePlanId ?? 0\n const subscribeStartDate = data.subscribeStartDate ?? new Date()\n\n // validate account\n const account = await accountModel.get({ id: Number(accountId) })\n\n if (!account?.account_id) {\n throw new Error(`Invalid account id: ${accountId}`)\n }\n\n if (account?.status !== true) {\n throw new Error(`Account is inactive: ${accountId}`)\n }\n\n // get the subscribe plan information\n const subscribePlan = await subscribePlanService.getSubscribePlan({ id: Number(subscribePlanId), datatypes: [] })\n\n if (!subscribePlan?.subscribe_plan_id) {\n throw new Error(`Invalid subscribe plan id: ${subscribePlanId}`)\n }\n\n const subscribePlanBillingCycle: SubscribePlanBillingCycle = subscribePlan?.billing_cycle\n\n if (!subscribePlanBillingCycle) {\n throw new Error(`Invalid subscribe plan billing cycle: ${subscribePlanId}`)\n }\n\n // get end of subscription date\n const subscribeEndDate = subscribePlanService.getNextBillingEndDate(subscribeStartDate, subscribePlanBillingCycle)\n\n const _data = getCreatePayload(data, subscribeStartDate, subscribeEndDate)\n\n if (!_data) {\n throw new Error(`Invalid create account subscribe payload: ${JSON.stringify(_data)}`);\n }\n\n let response = await accountSubscribeModel.create({ data: _data })\n\n return await getAccountSubscribe({ accountSubscriptionId: Number(response?.account_subscription_id ?? 0), datatypes: [] })\n }\n\n const getAccountSubscribe = async ({ accountSubscriptionId, datatypes = [] }: AccountSubscribeGetProps) => {\n\n let { data } = await listAccountSubscribes({\n limit: 1,\n offset: 0,\n filters: [{ field: `${ModelAccountSubscribeFields.account_subscription_id}`, operator: \"=\", value: accountSubscriptionId }],\n sortfield: `${ModelAccountSubscribeFields.account_subscription_id}`,\n sortorder: \"ASC\",\n datatypes\n })\n\n return data[0] ?? null;\n\n };\n\n const listAccountSubscribes = async ({ limit, offset, filters = [], sortfield, sortorder, datatypes = [] }: AccountSubscribeListProps) => {\n\n let data = []\n\n let sqlSelect = [\n `COUNT(accsub.*) OVER() as filtered_count`,\n buildSqlSelect(``, mainSqlSelect),\n buildSqlSelect(``, subscribePlanSqlSelect),\n buildSqlSelect(``, defaultSqlSelect)\n ]\n\n let sqlRelation = [\n buildSqlRelation(\"left\", \"subplan\", \"subscribe_plans\", \"subplan\", [\"accsub.subscribe_plan_id = subplan.subscribe_plan_id\", \"subplan.isdelete = false\", \"subplan.istrash = false\"]),\n buildSqlRelation(\"left\", \"subplan\", \"users\", \"creator\", [\"accsub.createuserid = creator.user_id\", \"creator.isdelete = false\", \"creator.istrash = false\"]),\n buildSqlRelation(\"left\", \"subplan\", \"users\", \"updater\", [\"accsub.updateuserid = updater.user_id\", \"updater.isdelete = false\", \"updater.istrash = false\"])\n ]\n\n let sqlGroupBy: string[] = [\n ...Object.keys(mainSqlSelect),\n ...Object.keys(subscribePlanSqlSelect),\n ...Object.keys(defaultSqlSelect)\n ]\n\n let filterColumns = {\n ...mainSqlSelect,\n ...subscribePlanSqlSelect,\n ...defaultSqlSelect\n }\n\n let sqlWhere = [\n `accsub.isdelete = false`,\n `accsub.istrash = false`,\n ...(filters.length ? [buildSqlWhere(filters, filterColumns)?.where] : []),\n ]\n\n let sqlOrderby = buildSqlOrderBy(sortfield, sortorder)\n let sqlLimitOffset = buildSqlLimitOffset(limit, offset)\n\n const sqlRaw = buildSqlRawSelect({\n tableName: \"account_subscriptions\",\n mainAlias: \"accsub\",\n accountId: rest.accountId,\n sqlSelect,\n sqlRelation,\n sqlWhere,\n sqlGroupBy,\n sqlOrderby,\n sqlLimitOffset\n })\n\n data = await accountSubscribeModel.raw(sqlRaw)\n\n const response = {\n data: data.map(({ filtered_count, ...rest }) => rest),\n total: data.length ? Number(data[0].filtered_count) : 0\n }\n\n return response\n\n };\n\n const cancelAccountSubscribe = async ({ accountSubscriptionId }: AccountSubscribeCancelProps) => {\n\n if (!accountSubscriptionId) throwError('accountSubscriptionId is required');\n\n const { total } = await listAccountSubscribes({\n limit: 1,\n offset: 0,\n filters: [\n { field: `${ModelAccountSubscribeFields.account_subscription_id}`, operator: \"=\", value: `${accountSubscriptionId}` },\n { field: `${ModelAccountSubscribeFields.status}`, operator: \"=\", value: true }\n ],\n sortfield: `${ModelAccountSubscribeFields.account_subscription_id}`,\n sortorder: \"ASC\",\n datatypes: []\n })\n\n if (total <= 0) {\n throw new Error(`Invalid subscription id : ${accountSubscriptionId}`)\n }\n\n const response = await accountSubscribeModel.update({\n id: Number(accountSubscriptionId),\n data: {\n [`${ModelAccountSubscribeFields.status}`]: false,\n [`${ModelAccountSubscribeFields.is_cancel}`]: true,\n [`${ModelAccountSubscribeFields.cancel_datetime}`]: new Date()\n },\n where: {\n [`${ModelAccountSubscribeFields.status}`]: true\n }\n });\n\n return response\n };\n\n return {\n getAccountSubscribe,\n createAccountSubscribe,\n cancelAccountSubscribe,\n listAccountSubscribes\n }\n\n}\n\n"]}
@@ -0,0 +1,63 @@
1
+ import { QueryList, QueryGet } from "../../../schema/common";
2
+ import { DefaultServiceProps } from "../../../utils";
3
+ export type SubscribePlanServiceProps = DefaultServiceProps & {};
4
+ export declare const subscribePlanBillingCycles: {
5
+ monthly: string;
6
+ yearly: string;
7
+ };
8
+ export type SubscribePlanBillingCycle = keyof typeof subscribePlanBillingCycles;
9
+ export declare const subscribeCurrencies: {
10
+ myr: string;
11
+ usd: string;
12
+ };
13
+ export type SubscribePlanCurrency = keyof typeof subscribeCurrencies;
14
+ export type SubscribePlanGetProps = QueryGet & {
15
+ id: number;
16
+ };
17
+ export type SubscribePlanListProps = QueryList & {};
18
+ export type SubscribePlanRemoveProps = {
19
+ subscribePlanIds: BigInt[];
20
+ };
21
+ export type SubscribePlan = {
22
+ name: string;
23
+ shortDescription: string;
24
+ fullDescription: string;
25
+ price: number;
26
+ billingCycle: SubscribePlanBillingCycle;
27
+ currency: SubscribePlanCurrency;
28
+ status: boolean;
29
+ };
30
+ export type SubscribePlanCreateProps = {
31
+ data: SubscribePlan;
32
+ };
33
+ export type SubscribePlanUpdateProps = {
34
+ subscribePlanId: number;
35
+ data: SubscribePlan;
36
+ };
37
+ export declare const SubscribePlanService: (props: SubscribePlanServiceProps) => {
38
+ getSubscribePlan: ({ id, datatypes }: SubscribePlanGetProps) => Promise<any>;
39
+ createSubscribePlan: ({ data }: SubscribePlanCreateProps) => Promise<any>;
40
+ updateSubscribePlan: ({ subscribePlanId, data }: SubscribePlanUpdateProps) => Promise<any>;
41
+ removeSubscribePlans: ({ subscribePlanIds }: SubscribePlanRemoveProps) => Promise<{
42
+ createdatetime: Date | null;
43
+ createuserid: bigint;
44
+ updatedatetime: Date | null;
45
+ updateuserid: bigint;
46
+ isdelete: boolean | null;
47
+ istrash: boolean | null;
48
+ accountid: bigint;
49
+ status: boolean | null;
50
+ name: string;
51
+ subscribe_plan_id: bigint;
52
+ short_description: string | null;
53
+ full_description: string | null;
54
+ price: import("@prisma/client/runtime/library").Decimal;
55
+ currency: string;
56
+ billing_cycle: string;
57
+ }[]>;
58
+ listSubscribePlans: ({ limit, offset, filters, sortfield, sortorder, datatypes }: SubscribePlanListProps) => Promise<{
59
+ data: any[];
60
+ total: number;
61
+ }>;
62
+ getNextBillingEndDate: (startDate: Date, cycle: SubscribePlanBillingCycle) => Date;
63
+ };