storemw-core-api 1.0.163 → 1.0.165
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.
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +5 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/model_factory/ModelFactory.d.ts +7 -6
- package/dist/lib/model_factory/ModelFactory.js +595 -197
- package/dist/lib/model_factory/ModelFactory.js.map +1 -1
- package/dist/lib/query_builder/queryBuilder.d.ts +1 -1
- package/dist/lib/query_builder/queryBuilder.js +66 -15
- package/dist/lib/query_builder/queryBuilder.js.map +1 -1
- package/dist/lib/query_builder/queryDocumentProfile.d.ts +7 -0
- package/dist/lib/query_builder/queryDocumentProfile.js +87 -0
- package/dist/lib/query_builder/queryDocumentProfile.js.map +1 -0
- package/dist/lib/query_builder/queryUserBranch.d.ts +10 -0
- package/dist/lib/query_builder/queryUserBranch.js +31 -0
- package/dist/lib/query_builder/queryUserBranch.js.map +1 -0
- package/dist/models/access_control/AccessControlRoleModel.d.ts +4 -5
- package/dist/models/access_control/AccessControlRolePolicyModel.d.ts +4 -5
- package/dist/models/access_control/AccessControlUserRoleModel.d.ts +4 -5
- package/dist/models/account/AccountModel.d.ts +4 -5
- package/dist/models/auth/AccessKeyModel.d.ts +4 -5
- package/dist/models/branch/UserBranchModel.d.ts +4 -5
- package/dist/models/branch_user/BranchUserModel.d.ts +4 -5
- package/dist/models/business/BusinessModel.d.ts +4 -5
- package/dist/models/document/DocumentAmountModel.d.ts +4 -5
- package/dist/models/document/DocumentDocumentModel.d.ts +4 -5
- package/dist/models/document/DocumentItemModel.d.ts +4 -5
- package/dist/models/document/DocumentLocationModel.d.ts +4 -5
- package/dist/models/document/DocumentModel.d.ts +4 -5
- package/dist/models/document/DocumentPaymentModel.d.ts +4 -5
- package/dist/models/document/DocumentProfileModel.d.ts +4 -5
- package/dist/models/document/DocumentTotalModel.d.ts +4 -5
- package/dist/models/file/FileModel.d.ts +4 -5
- package/dist/models/group/GroupModel.d.ts +4 -5
- package/dist/models/group/GroupOwnerModel.d.ts +4 -5
- package/dist/models/injection_field/DocumentInjectionFieldModel.d.ts +4 -5
- package/dist/models/injection_field/InjectionFieldModel.d.ts +4 -5
- package/dist/models/injection_field/ItemInjectionFieldModel.d.ts +4 -5
- package/dist/models/injection_field/LogisticInjectionFieldModel.d.ts +4 -5
- package/dist/models/injection_field/RepositoryInjectionFieldModel.d.ts +4 -5
- package/dist/models/injection_field/UserInjectionFieldModel.d.ts +4 -5
- package/dist/models/item/BrandModel.d.ts +4 -5
- package/dist/models/item/CategoryModel.d.ts +4 -5
- package/dist/models/item/ItemModel.d.ts +4 -5
- package/dist/models/item/ProductModel.d.ts +4 -5
- package/dist/models/item/UomModel.d.ts +4 -5
- package/dist/models/location/LocationModel.d.ts +4 -5
- package/dist/models/location/LocationRackModel.d.ts +4 -5
- package/dist/models/location/LocationSlotModel.d.ts +4 -5
- package/dist/models/others/NumberDateSequenceModel.d.ts +4 -5
- package/dist/models/others/OneTimeCodeModel.d.ts +4 -5
- package/dist/models/region/AreaModel.d.ts +4 -5
- package/dist/models/region/CountryModel.d.ts +4 -5
- package/dist/models/region/StateModel.d.ts +4 -5
- package/dist/models/repository/RepositoryCartonModel.d.ts +4 -5
- package/dist/models/repository/RepositoryContainerModel.d.ts +4 -5
- package/dist/models/repository/RepositoryModel.d.ts +4 -5
- package/dist/models/repository/RepositoryPackageItemModel.d.ts +4 -5
- package/dist/models/repository/RepositoryPackageModel.d.ts +4 -5
- package/dist/models/repository/RepositoryPalletModel.d.ts +4 -5
- package/dist/models/scheduler/SchedulerLogModel.d.ts +4 -5
- package/dist/models/scheduler/SchedulerRequestModel.d.ts +4 -5
- package/dist/models/subscription/account/AccountSubscribeModel.d.ts +4 -5
- package/dist/models/subscription/plan/SubscribePlanModel.d.ts +4 -5
- package/dist/models/user/AdministratorModel.d.ts +4 -5
- package/dist/models/user/AgentModel.d.ts +4 -5
- package/dist/models/user/CustomerModel.d.ts +4 -5
- package/dist/models/user/DriverModel.d.ts +4 -5
- package/dist/models/user/MemberModel.d.ts +4 -5
- package/dist/models/user/OperatorModel.d.ts +4 -5
- package/dist/models/user/RetailerModel.d.ts +4 -5
- package/dist/models/user/UserModel.d.ts +4 -5
- package/dist/models/user/UserPropModel.d.ts +4 -5
- package/dist/models/user/WorkerModel.d.ts +4 -5
- package/dist/schema/payload/document/schemaDocumentCashSales.d.ts +64 -64
- package/dist/schema/payload/document/schemaDocumentDeliveryOrder.d.ts +64 -64
- package/dist/schema/payload/document/schemaDocumentProformaSales.d.ts +64 -64
- package/dist/schema/payload/document/schemaDocumentReplacementDeliveryOrder.d.ts +64 -64
- package/dist/schema/payload/document/schemaDocumentSalesOrder.d.ts +64 -64
- package/dist/services/branch/UserBranchService.d.ts +2 -2
- package/dist/services/branch/UserBranchService.js +53 -22
- package/dist/services/branch/UserBranchService.js.map +1 -1
- package/dist/services/document/DocumentProfileService.js +47 -19
- package/dist/services/document/DocumentProfileService.js.map +1 -1
- package/dist/utils/serviceUtils.d.ts +2 -0
- package/dist/utils/serviceUtils.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DocumentProfileService.js","sourceRoot":"","sources":["../../../src/services/document/DocumentProfileService.ts"],"names":[],"mappings":";;;AAAA,qCAKkB;AAElB,mCAAiE;AAEjE,yCAA8C;AAM9C,+BAAwL;AAE3K,QAAA,oBAAoB,GAAG;IAChC,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;CACZ,CAAA;AAsEV,MAAM,gBAAgB,GAAG,CAAC,UAAkB,EAAE,YAA0B,EAAE,IAAwC,EAAE,EAAE;IAElH,OAAO;QACH,CAAC,GAAG,mCAA0B,CAAC,WAAW,EAAE,CAAC,EAAE,UAAU;QACzD,CAAC,GAAG,mCAA0B,CAAC,aAAa,EAAE,CAAC,EAAE,YAAY;QAC7D,CAAC,GAAG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M,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;SAC3D,CAAA;QAED,OAAO,QAAQ,CAAA;IAEnB,CAAC,CAAC;IAEF,MAAM,sBAAsB,GAAG,KAAK,EAAE,EAAE,WAAW,EAA8B,EAAE,EAAE;QAEjF,IAAI,CAAC,WAAW,CAAC,MAAM;YAAE,IAAA,kBAAU,EAAC,yBAAyB,CAAC,CAAC;QAE/D,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,mCAA0B,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;QAEtI,OAAO,QAAQ,CAAA;IACnB,CAAC,CAAC;IAEF,OAAO;QACH,wBAAwB;QACxB,2BAA2B;QAC3B,sBAAsB;QACtB,4DAA4D;QAC5D,4DAA4D;KAC/D,CAAA;AAEL,CAAC,CAAA;AAhVY,QAAA,sBAAsB,0BAgVlC","sourcesContent":["import {\n DocumentModel,\n DocumentProfileModel,\n ModelDocumentProfileFields,\n ModelUserFields\n} from \"@/models\";\n\nimport { dayjs, DefaultServiceProps, throwError } from \"@/utils\";\n\nimport { UserBranchService } from \"@/services\"\n\nimport { QueryList, QueryGet } from \"@/schema/common\";\n\nimport { DocumentType } from \"./DocumentService\"\n\nimport { buildSqlRelation, buildSqlRawSelect, buildSqlRawSelectCount, buildSqlWhere, buildSqlSelect, buildSqlLimitOffset, buildSqlOrderBy, buildInjectionFieldsSqlSelect } from \"@/lib\";\n\nexport const documentProfileTypes = {\n profile: \"profile\",\n shipping: \"shipping\",\n billing: \"billing\"\n} as const\n\nexport type DocumentProfileType = typeof documentProfileTypes[keyof typeof documentProfileTypes]\n\nexport type DocumentProfileServiceProps = DefaultServiceProps & {\n documentType: DocumentType\n};\n\nexport type DocumentProfile = {\n userId: number,\n userBranchId: number,\n // documentId: number,\n profileType: DocumentProfileType,\n code?: string,\n profileName?: string,\n personName?: string,\n contactNo?: string,\n email?: string,\n address1?: string,\n address2?: string,\n postcode?: string,\n stateId?: number,\n areaId?: number,\n countryId?: number\n}\n\nexport type DocumentProfileGetProps = Omit<QueryGet, \"datatypes\"> & {\n documentId?: number | \"\",\n documentType?: DocumentType | \"\",\n profileType?: DocumentProfileType | \"\"\n};\n\nexport type DocumentProfileListProps = Omit<QueryList, \"datatypes\"> & {\n // profileType: DocumentProfileType\n};\n\nexport type DocumentProfileCreateProps = {\n documentId: number,\n documentType?: DocumentType,\n data: DocumentProfile\n}\n\nexport type DocumentProfileUpdateProps = {\n // documentId: number,\n documentProfileId: number,\n documentType?: DocumentType,\n data: DocumentProfile\n}\n\nexport type DocumentProfileReplaceHQProps = {\n documentId: number,\n documentType?: DocumentType,\n data: Pick<DocumentProfile, \"userId\"> & {\n // userType: \"customer\" | \"supplier\"\n }\n}\n\nexport type DocumentProfileReplaceOtherProps = {\n documentId: number,\n documentType?: DocumentType,\n documentProfileType: DocumentProfileType,\n data: Omit<DocumentProfile, \"userId\" | \"profileType\"> & {\n // userType: \"customer\" | \"supplier\"\n }\n}\n\nexport type DocumentProfileRemoveProps = {\n documentIds: BigInt[]\n};\n\nconst getCreatePayload = (documentId: number, documentType: DocumentType, data: DocumentProfileCreateProps[\"data\"]) => {\n\n return {\n [`${ModelDocumentProfileFields.document_id}`]: documentId,\n [`${ModelDocumentProfileFields.document_type}`]: documentType,\n [`${ModelDocumentProfileFields.user_branch_id}`]: data.userBranchId,\n [`${ModelDocumentProfileFields.user_id}`]: data.userId,\n [`${ModelDocumentProfileFields.code}`]: data.code,\n [`${ModelDocumentProfileFields.type}`]: data.profileType.toUpperCase(),\n [`${ModelDocumentProfileFields.profile_name}`]: data.profileName,\n [`${ModelDocumentProfileFields.address_1}`]: data.address1,\n [`${ModelDocumentProfileFields.address_2}`]: data.address2,\n [`${ModelDocumentProfileFields.contact}`]: data.contactNo,\n [`${ModelDocumentProfileFields.email}`]: data.email,\n [`${ModelDocumentProfileFields.name}`]: data.personName,\n [`${ModelDocumentProfileFields.postcode}`]: data.postcode,\n [`${ModelDocumentProfileFields.area_id}`]: data.areaId,\n [`${ModelDocumentProfileFields.state_id}`]: data.stateId,\n [`${ModelDocumentProfileFields.country_id}`]: data.countryId,\n }\n\n}\n\nconst getUpdatePayload = (documentType: DocumentType, data: DocumentProfileUpdateProps[\"data\"]) => {\n\n return {\n // [`${ModelDocumentProfileFields.document_id}`]: documentId,\n // [`${ModelDocumentProfileFields.document_type}`]: documentType,\n [`${ModelDocumentProfileFields.user_branch_id}`]: data.userBranchId,\n [`${ModelDocumentProfileFields.user_id}`]: data.userId,\n [`${ModelDocumentProfileFields.code}`]: data.code,\n [`${ModelDocumentProfileFields.type}`]: data.profileType.toUpperCase(),\n [`${ModelDocumentProfileFields.profile_name}`]: data.profileName,\n [`${ModelDocumentProfileFields.address_1}`]: data.address1,\n [`${ModelDocumentProfileFields.address_2}`]: data.address2,\n [`${ModelDocumentProfileFields.contact}`]: data.contactNo,\n [`${ModelDocumentProfileFields.email}`]: data.email,\n [`${ModelDocumentProfileFields.name}`]: data.personName,\n [`${ModelDocumentProfileFields.postcode}`]: data.postcode,\n [`${ModelDocumentProfileFields.area_id}`]: data.areaId,\n [`${ModelDocumentProfileFields.state_id}`]: data.stateId,\n [`${ModelDocumentProfileFields.country_id}`]: data.countryId,\n }\n\n}\n\nlet mainSqlSelect = {\n [`docpro.${ModelDocumentProfileFields.document_profile_id}`]: `document_profile_id`,\n [`docpro.${ModelDocumentProfileFields.code}`]: `code`,\n [`docpro.${ModelDocumentProfileFields.name}`]: `name`,\n [`docpro.${ModelDocumentProfileFields.type}`]: `type`,\n [`docpro.${ModelDocumentProfileFields.document_id}`]: `document_id`,\n [`docpro.${ModelDocumentProfileFields.document_type}`]: `document_type`,\n [`docpro.${ModelDocumentProfileFields.profile_name}`]: `profile_name`,\n [`docpro.${ModelDocumentProfileFields.address_1}`]: `address_1`,\n [`docpro.${ModelDocumentProfileFields.address_2}`]: `address_2`,\n [`docpro.${ModelDocumentProfileFields.contact}`]: `contact`,\n [`docpro.${ModelDocumentProfileFields.email}`]: `email`,\n [`docpro.${ModelDocumentProfileFields.postcode}`]: `postcode`,\n // [`docpro.${ModelDocumentProfileFields.area}`]: `area`,\n [`docpro.${ModelDocumentProfileFields.area_id}`]: `area_id`,\n // [`${aliasArea}.${ModelAreaFields.area_name}`]: `area_name`,\n // [`${aliasCountry}.${ModelCountryFields.country_name}`]: `country_name`,\n [`docpro.${ModelDocumentProfileFields.country_id}`]: `country_id`,\n // [`${aliasState}.${ModelStateFields.state_name}`]: `state_name`,\n [`docpro.${ModelDocumentProfileFields.state_id}`]: `state_id`,\n [`docpro.${ModelDocumentProfileFields.user_id}`]: `user_id`,\n [`docpro.${ModelDocumentProfileFields.user_branch_id}`]: `user_branch_id`\n}\nlet defaultSqlSelect = {\n [`docpro.${ModelDocumentProfileFields.createdatetime}`]: \"createdatetime\",\n [`creator.${ModelUserFields.login_username}`]: \"createusername\",\n [`docpro.${ModelDocumentProfileFields.updatedatetime}`]: \"updatedatetime\",\n [`updater.${ModelUserFields.login_username}`]: \"updateusername\",\n [`docpro.${ModelDocumentProfileFields.isdelete}`]: \"isdelete\",\n [`docpro.${ModelDocumentProfileFields.istrash}`]: \"istrash\",\n [`docpro.${ModelDocumentProfileFields.accountid}`]: \"accountid\",\n}\n\nexport const DocumentProfileService = (props: DocumentProfileServiceProps) => {\n\n const {\n documentType = \"sales\",\n ...rest\n } = props\n\n const documentProfileModel = DocumentProfileModel({ ...rest })\n const documentModel = DocumentModel({ ...rest })\n\n const userBranchService = UserBranchService({ ...rest, userBranchUserType: \"customer\", userBranchType: \"branch\" })\n\n // override existing - if not found create new\n const replaceDocumentProfileHQ = async ({ data, documentId, documentType: overrideDocumentType }: DocumentProfileReplaceHQProps) => {\n\n const _documentType = overrideDocumentType || documentType\n\n const userId = data.userId\n // const documentId = data.documentId\n\n let _userHQBranches = await userBranchService.getUserBranchByUserId({ userId, onlyHQ: true, datatypes: [] })\n\n if (_userHQBranches.length <= 0) {\n throwError(`Unset main branch user id: ${userId}`)\n }\n\n let userHQBranches = _userHQBranches[0]\n\n // console.log('userHQBranches', userHQBranches)\n\n // check the profile HQ already exists - for type profile\n const existProfile = await getDocumentProfile({ documentId, documentType: _documentType, profileType: \"profile\" })\n\n let response: any = {}\n\n if (existProfile) {\n\n let payload: DocumentProfileUpdateProps = {\n documentProfileId: Number(existProfile?.document_profile_id),\n documentType: _documentType,\n data: {\n profileType: \"profile\",\n userBranchId: Number(userHQBranches.branch_id),\n userId: Number(userHQBranches.user_id),\n code: userHQBranches.branch_code ?? \"\",\n contactNo: userHQBranches.branch_contact ?? \"\",\n email: userHQBranches.branch_email ?? \"\",\n personName: `${userHQBranches?.pic_name ?? \"\"}`,\n postcode: userHQBranches.postcode ?? \"\",\n profileName: userHQBranches.branch_name ?? \"\",\n stateId: Number(userHQBranches.state_id),\n areaId: Number(userHQBranches.area_id),\n countryId: Number(userHQBranches.country_id),\n address1: userHQBranches.address_1 ?? \"\",\n address2: userHQBranches.address_2 ?? \"\",\n }\n }\n\n // update document profile for profile\n response = await updateDocumentProfile(payload)\n\n } else { // create new\n let payload: DocumentProfileCreateProps = {\n documentId,\n documentType: _documentType,\n data: {\n profileType: \"profile\",\n userBranchId: Number(userHQBranches.branch_id),\n userId: Number(userHQBranches.user_id),\n code: userHQBranches.branch_code ?? \"\",\n contactNo: userHQBranches.branch_contact ?? \"\",\n email: userHQBranches.branch_email ?? \"\",\n personName: `${userHQBranches?.pic_name ?? \"\"}`,\n postcode: userHQBranches.postcode ?? \"\",\n profileName: userHQBranches.branch_name ?? \"\",\n stateId: Number(userHQBranches.state_id),\n areaId: Number(userHQBranches.area_id),\n countryId: Number(userHQBranches.country_id),\n address1: userHQBranches.address_1 ?? \"\",\n address2: userHQBranches.address_2 ?? \"\",\n }\n }\n\n // create document profile for profile\n response = await createDocumentProfile(payload)\n\n }\n\n return response\n\n }\n\n // override existing - if not found create new\n const replaceDocumentProfileOther = async ({ data, documentId, documentProfileType = \"shipping\", documentType: overrideDocumentType }: DocumentProfileReplaceOtherProps) => {\n\n const _documentType = overrideDocumentType || documentType\n\n const userBranchId = data.userBranchId\n // const userType = data.userType\n // const documentId = data.documentId\n\n let userBranch = await userBranchService.getUserBranch({ userBranchId, datatypes: [] })\n\n // console.log('userBranch', userBranch)\n\n if (!userBranch?.user_id) {\n throwError(`Invalid user id in user branch: ${userBranchId}`)\n }\n\n // check the profile other already exists - for other type than profile\n const existProfile = await getDocumentProfile({ documentId, documentType: _documentType, profileType: documentProfileType })\n\n let response: any = {}\n\n if (existProfile) {\n\n let payload: DocumentProfileUpdateProps = {\n documentProfileId: Number(existProfile?.document_profile_id),\n documentType: _documentType,\n data: {\n profileType: documentProfileType,\n userBranchId: Number(userBranch.branch_id),\n userId: Number(userBranch.user_id),\n\n code: data?.code ? data.code : String(userBranch.branch_code ?? \"\"),\n contactNo: data?.code ? data.code : String(userBranch.branch_contact ?? \"\"),\n email: data?.email ? data.email : String(userBranch.branch_email ?? \"\"),\n personName: data?.personName ? data.personName : String(`${userBranch?.pic_name ?? \"\"}`),\n postcode: data?.postcode ? data.postcode : String(userBranch.postcode ?? \"\"),\n profileName: data?.profileName ? data.profileName : String(userBranch.branch_name ?? \"\"),\n stateId: data?.stateId ? Number(data.stateId) : Number(userBranch.state_id),\n areaId: data?.areaId ? Number(data.areaId) : Number(userBranch.area_id),\n countryId: data?.countryId ? Number(data.countryId) : Number(userBranch.country_id),\n address1: data?.address1 ? data.address1 : String(userBranch.address_1 ?? \"\"),\n address2: data?.address2 ? data.address2 : String(userBranch.address_2 ?? \"\"),\n }\n }\n\n // update document profile for (shipping or billing)\n response = await updateDocumentProfile(payload)\n\n } else {\n\n let payload: DocumentProfileCreateProps = {\n documentId,\n documentType: _documentType,\n data: {\n profileType: documentProfileType,\n userBranchId: Number(userBranch.branch_id),\n userId: Number(userBranch.user_id),\n\n code: data?.code ? data.code : String(userBranch.branch_code ?? \"\"),\n contactNo: data?.code ? data.code : String(userBranch.branch_contact ?? \"\"),\n email: data?.email ? data.email : String(userBranch.branch_email ?? \"\"),\n personName: data?.personName ? data.personName : String(`${userBranch?.pic_name ?? \"\"}`),\n postcode: data?.postcode ? data.postcode : String(userBranch.postcode ?? \"\"),\n profileName: data?.profileName ? data.profileName : String(userBranch.branch_name ?? \"\"),\n stateId: data?.stateId ? Number(data.stateId) : Number(userBranch.state_id),\n areaId: data?.areaId ? Number(data.areaId) : Number(userBranch.area_id),\n countryId: data?.countryId ? Number(data.countryId) : Number(userBranch.country_id),\n address1: data?.address1 ? data.address1 : String(userBranch.address_1 ?? \"\"),\n address2: data?.address2 ? data.address2 : String(userBranch.address_2 ?? \"\"),\n }\n }\n\n // create document profile for (shipping or billing)\n response = await createDocumentProfile(payload)\n }\n\n return response\n\n }\n\n // private\n const createDocumentProfile = async ({ data, documentId, documentType: overrideDocumentType }: DocumentProfileCreateProps) => {\n\n const _documentType = overrideDocumentType || documentType\n\n const _data = getCreatePayload(documentId, _documentType, data)\n\n if (!_data) {\n throw new Error(`Invalid create document(profile) payload: ${JSON.stringify(_data)}`);\n }\n\n // create document profile\n return await documentProfileModel.create({ data: _data })\n\n }\n\n // private\n const updateDocumentProfile = async ({ documentProfileId, data, documentType: overrideDocumentType }: DocumentProfileUpdateProps) => {\n\n const _documentType = overrideDocumentType || documentType\n\n const _data = getUpdatePayload(_documentType, data)\n\n if (!_data) {\n throw new Error(`Invalid update document(profile) payload: ${JSON.stringify(_data)}`);\n }\n\n // update document profile\n return await documentProfileModel.update({ id: documentProfileId, data: _data })\n\n }\n\n const getDocumentProfile = async ({ documentId = \"\", documentType = \"\", profileType = \"\" }: DocumentProfileGetProps) => {\n\n let filters = []\n\n if (documentType) {\n filters.push({ field: `${ModelDocumentProfileFields.document_type}`, operator: \"=\", value: documentType })\n }\n if (documentId) {\n filters.push({ field: `${ModelDocumentProfileFields.document_id}`, operator: \"=\", value: Number(documentId) })\n }\n if (profileType) {\n filters.push({ field: `${ModelDocumentProfileFields.type}`, operator: \"=\", value: profileType.toUpperCase() })\n }\n\n let { data } = await listDocumentProfiles({\n limit: 1,\n offset: 0,\n filters: filters as QueryList[\"filters\"],\n sortfield: `${ModelDocumentProfileFields.document_id}`,\n sortorder: \"ASC\",\n // datatypes: []\n })\n\n return data[0] ?? null;\n\n };\n\n const listDocumentProfiles = async ({\n limit,\n offset,\n filters,\n sortfield,\n sortorder,\n // datatypes = []\n }: DocumentProfileListProps) => {\n\n let sqlSelect: string[] = []\n let sqlRelation: string[] = []\n let sqlGroupBy: string[] = []\n\n let sqlSelectAgg: string[] = []\n let sqlRelationAgg: string[] = []\n\n sqlSelect = [\n buildSqlSelect(``, mainSqlSelect),\n buildSqlSelect(``, defaultSqlSelect)\n ]\n\n sqlRelation = [\n buildSqlRelation(\"left\", \"docpro\", \"users\", \"creator\", [\"docpro.createuserid = creator.user_id\", \"creator.isdelete = false\", \"creator.istrash = false\"]),\n buildSqlRelation(\"left\", \"docpro\", \"users\", \"updater\", [\"docpro.updateuserid = updater.user_id\", \"updater.isdelete = false\", \"updater.istrash = false\"])\n ]\n\n // sqlRelationAgg = [\n // buildSqlRelation(\"left\", \"docpro\", \"document_items\", \"docitm\", [\"docpro.document_id = docitm.document_id\", \"docitm.isdelete = false\", \"docitm.istrash = false\"]),\n // ]\n\n sqlGroupBy = [\n ...Object.keys(mainSqlSelect),\n ...Object.keys(defaultSqlSelect)\n ]\n\n let filterColumns = {\n ...mainSqlSelect,\n ...defaultSqlSelect\n }\n\n let sqlWhere = [\n `docpro.isdelete = false`,\n `docpro.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 // get the data (pagination)\n const sqlRaw = buildSqlRawSelect({\n tableName: \"document_profiles\",\n mainAlias: \"docpro\",\n accountId: rest.accountId,\n sqlSelect: [...sqlSelect, ...sqlSelectAgg],\n sqlRelation: [...sqlRelation, ...sqlRelationAgg],\n sqlWhere,\n sqlGroupBy,\n sqlOrderby,\n sqlLimitOffset\n })\n\n let data = await documentModel.raw(sqlRaw)\n\n // get the count\n const sqlRawCount = buildSqlRawSelectCount({\n tableName: \"document_profiles\",\n mainAlias: \"docpro\",\n accountId: rest.accountId,\n sqlSelect,\n sqlRelation,\n sqlWhere,\n sqlGroupBy,\n sqlOrderby\n })\n\n let count = await documentModel.raw(sqlRawCount)\n\n const response = {\n data,\n total: data.length ? Number(count[0].filtered_count) : 0\n }\n\n return response\n\n };\n\n const removeDocumentProfiles = async ({ documentIds }: DocumentProfileRemoveProps) => {\n\n if (!documentIds.length) throwError('documentIds is required');\n\n const response = await documentProfileModel.remove({ where: { [`${ModelDocumentProfileFields.document_id}`]: { in: documentIds } } });\n\n return response\n };\n\n return {\n replaceDocumentProfileHQ,\n replaceDocumentProfileOther,\n removeDocumentProfiles,\n // createDocumentProfile // no need export internal use only\n // updateDocumentProfile // no need export internal use only\n }\n\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"DocumentProfileService.js","sourceRoot":"","sources":["../../../src/services/document/DocumentProfileService.ts"],"names":[],"mappings":";;;AAAA,qCAKkB;AAElB,mCAAiE;AAEjE,yCAA8C;AAM9C,+BAA6K;AAEhK,QAAA,oBAAoB,GAAG;IAChC,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,UAAU;IACpB,OAAO,EAAE,SAAS;CACZ,CAAA;AAsEV,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,IAAA,oCAA8B,GAAE,CAAA;AAE1E,MAAM,gBAAgB,GAAG,CAAC,UAAkB,EAAE,YAA0B,EAAE,IAAwC,EAAE,EAAE;IAElH,OAAO;QACH,CAAC,GAAG,mCAA0B,CAAC,WAAW,EAAE,CAAC,EAAE,UAAU;QACzD,CAAC,GAAG,mCAA0B,CAAC,aAAa,EAAE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AC;IAEF,MAAM,sBAAsB,GAAG,KAAK,EAAE,EAAE,WAAW,EAA8B,EAAE,EAAE;QAEjF,IAAI,CAAC,WAAW,CAAC,MAAM;YAAE,IAAA,kBAAU,EAAC,yBAAyB,CAAC,CAAC;QAE/D,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,mCAA0B,CAAC,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;QAEtI,OAAO,QAAQ,CAAA;IACnB,CAAC,CAAC;IAEF,OAAO;QACH,wBAAwB;QACxB,2BAA2B;QAC3B,sBAAsB;QACtB,4DAA4D;QAC5D,4DAA4D;KAC/D,CAAA;AAEL,CAAC,CAAA;AA9WY,QAAA,sBAAsB,0BA8WlC","sourcesContent":["import {\n DocumentModel,\n DocumentProfileModel,\n ModelDocumentProfileFields,\n ModelUserFields\n} from \"@/models\";\n\nimport { dayjs, DefaultServiceProps, throwError } from \"@/utils\";\n\nimport { UserBranchService } from \"@/services\"\n\nimport { QueryList, QueryGet } from \"@/schema/common\";\n\nimport { DocumentType } from \"./DocumentService\"\n\nimport { buildSqlWhere, buildSqlSelect, buildSqlLimitOffset, buildSqlOrderBy, buildInjectionFieldsSqlSelect, getDocumentProfileRelationMaps, getListWithCount } from \"@/lib\";\n\nexport const documentProfileTypes = {\n profile: \"profile\",\n shipping: \"shipping\",\n billing: \"billing\"\n} as const\n\nexport type DocumentProfileType = typeof documentProfileTypes[keyof typeof documentProfileTypes]\n\nexport type DocumentProfileServiceProps = DefaultServiceProps & {\n documentType: DocumentType\n};\n\nexport type DocumentProfile = {\n userId: number,\n userBranchId: number,\n // documentId: number,\n profileType: DocumentProfileType,\n code?: string,\n profileName?: string,\n personName?: string,\n contactNo?: string,\n email?: string,\n address1?: string,\n address2?: string,\n postcode?: string,\n stateId?: number,\n areaId?: number,\n countryId?: number\n}\n\nexport type DocumentProfileGetProps = Omit<QueryGet, \"datatypes\"> & {\n documentId?: number | \"\",\n documentType?: DocumentType | \"\",\n profileType?: DocumentProfileType | \"\"\n};\n\nexport type DocumentProfileListProps = Omit<QueryList, \"datatypes\"> & {\n // profileType: DocumentProfileType\n};\n\nexport type DocumentProfileCreateProps = {\n documentId: number,\n documentType?: DocumentType,\n data: DocumentProfile\n}\n\nexport type DocumentProfileUpdateProps = {\n // documentId: number,\n documentProfileId: number,\n documentType?: DocumentType,\n data: DocumentProfile\n}\n\nexport type DocumentProfileReplaceHQProps = {\n documentId: number,\n documentType?: DocumentType,\n data: Pick<DocumentProfile, \"userId\"> & {\n // userType: \"customer\" | \"supplier\"\n }\n}\n\nexport type DocumentProfileReplaceOtherProps = {\n documentId: number,\n documentType?: DocumentType,\n documentProfileType: DocumentProfileType,\n data: Omit<DocumentProfile, \"userId\" | \"profileType\"> & {\n // userType: \"customer\" | \"supplier\"\n }\n}\n\nexport type DocumentProfileRemoveProps = {\n documentIds: BigInt[]\n};\n\nconst { relationKeys, sqlRelationMaps } = getDocumentProfileRelationMaps()\n\nconst getCreatePayload = (documentId: number, documentType: DocumentType, data: DocumentProfileCreateProps[\"data\"]) => {\n\n return {\n [`${ModelDocumentProfileFields.document_id}`]: documentId,\n [`${ModelDocumentProfileFields.document_type}`]: documentType,\n [`${ModelDocumentProfileFields.user_branch_id}`]: data.userBranchId,\n [`${ModelDocumentProfileFields.user_id}`]: data.userId,\n [`${ModelDocumentProfileFields.code}`]: data.code,\n [`${ModelDocumentProfileFields.type}`]: data.profileType.toUpperCase(),\n [`${ModelDocumentProfileFields.profile_name}`]: data.profileName,\n [`${ModelDocumentProfileFields.address_1}`]: data.address1,\n [`${ModelDocumentProfileFields.address_2}`]: data.address2,\n [`${ModelDocumentProfileFields.contact}`]: data.contactNo,\n [`${ModelDocumentProfileFields.email}`]: data.email,\n [`${ModelDocumentProfileFields.name}`]: data.personName,\n [`${ModelDocumentProfileFields.postcode}`]: data.postcode,\n [`${ModelDocumentProfileFields.area_id}`]: data.areaId,\n [`${ModelDocumentProfileFields.state_id}`]: data.stateId,\n [`${ModelDocumentProfileFields.country_id}`]: data.countryId,\n }\n\n}\n\nconst getUpdatePayload = (documentType: DocumentType, data: DocumentProfileUpdateProps[\"data\"]) => {\n\n return {\n // [`${ModelDocumentProfileFields.document_id}`]: documentId,\n // [`${ModelDocumentProfileFields.document_type}`]: documentType,\n [`${ModelDocumentProfileFields.user_branch_id}`]: data.userBranchId,\n [`${ModelDocumentProfileFields.user_id}`]: data.userId,\n [`${ModelDocumentProfileFields.code}`]: data.code,\n [`${ModelDocumentProfileFields.type}`]: data.profileType.toUpperCase(),\n [`${ModelDocumentProfileFields.profile_name}`]: data.profileName,\n [`${ModelDocumentProfileFields.address_1}`]: data.address1,\n [`${ModelDocumentProfileFields.address_2}`]: data.address2,\n [`${ModelDocumentProfileFields.contact}`]: data.contactNo,\n [`${ModelDocumentProfileFields.email}`]: data.email,\n [`${ModelDocumentProfileFields.name}`]: data.personName,\n [`${ModelDocumentProfileFields.postcode}`]: data.postcode,\n [`${ModelDocumentProfileFields.area_id}`]: data.areaId,\n [`${ModelDocumentProfileFields.state_id}`]: data.stateId,\n [`${ModelDocumentProfileFields.country_id}`]: data.countryId,\n }\n\n}\n\nlet mainSqlSelect = {\n [`docpro.${ModelDocumentProfileFields.document_profile_id}`]: `document_profile_id`,\n [`docpro.${ModelDocumentProfileFields.code}`]: `code`,\n [`docpro.${ModelDocumentProfileFields.name}`]: `name`,\n [`docpro.${ModelDocumentProfileFields.type}`]: `type`,\n [`docpro.${ModelDocumentProfileFields.document_id}`]: `document_id`,\n [`docpro.${ModelDocumentProfileFields.document_type}`]: `document_type`,\n [`docpro.${ModelDocumentProfileFields.profile_name}`]: `profile_name`,\n [`docpro.${ModelDocumentProfileFields.address_1}`]: `address_1`,\n [`docpro.${ModelDocumentProfileFields.address_2}`]: `address_2`,\n [`docpro.${ModelDocumentProfileFields.contact}`]: `contact`,\n [`docpro.${ModelDocumentProfileFields.email}`]: `email`,\n [`docpro.${ModelDocumentProfileFields.postcode}`]: `postcode`,\n // [`docpro.${ModelDocumentProfileFields.area}`]: `area`,\n [`docpro.${ModelDocumentProfileFields.area_id}`]: `area_id`,\n // [`${aliasArea}.${ModelAreaFields.area_name}`]: `area_name`,\n // [`${aliasCountry}.${ModelCountryFields.country_name}`]: `country_name`,\n [`docpro.${ModelDocumentProfileFields.country_id}`]: `country_id`,\n // [`${aliasState}.${ModelStateFields.state_name}`]: `state_name`,\n [`docpro.${ModelDocumentProfileFields.state_id}`]: `state_id`,\n [`docpro.${ModelDocumentProfileFields.user_id}`]: `user_id`,\n [`docpro.${ModelDocumentProfileFields.user_branch_id}`]: `user_branch_id`\n}\nlet defaultSqlSelect = {\n [`docpro.${ModelDocumentProfileFields.createdatetime}`]: \"createdatetime\",\n [`creator.${ModelUserFields.login_username}`]: \"createusername\",\n [`docpro.${ModelDocumentProfileFields.updatedatetime}`]: \"updatedatetime\",\n [`updater.${ModelUserFields.login_username}`]: \"updateusername\",\n [`docpro.${ModelDocumentProfileFields.isdelete}`]: \"isdelete\",\n [`docpro.${ModelDocumentProfileFields.istrash}`]: \"istrash\",\n [`docpro.${ModelDocumentProfileFields.accountid}`]: \"accountid\",\n}\n\nexport const DocumentProfileService = (props: DocumentProfileServiceProps) => {\n\n const {\n documentType = \"sales\",\n ...rest\n } = props\n\n const documentProfileModel = DocumentProfileModel({ ...rest })\n const documentModel = DocumentModel({ ...rest })\n\n const userBranchService = UserBranchService({ ...rest, userBranchUserType: \"customer\", userBranchType: \"branch\" })\n\n // override existing - if not found create new\n const replaceDocumentProfileHQ = async ({ data, documentId, documentType: overrideDocumentType }: DocumentProfileReplaceHQProps) => {\n\n const _documentType = overrideDocumentType || documentType\n\n const userId = data.userId\n // const documentId = data.documentId\n\n let _userHQBranches = await userBranchService.getUserBranchByUserId({ userId, onlyHQ: true, datatypes: [] })\n\n if (_userHQBranches.length <= 0) {\n throwError(`Unset main branch user id: ${userId}`)\n }\n\n let userHQBranches = _userHQBranches[0]\n\n // console.log('userHQBranches', userHQBranches)\n\n // check the profile HQ already exists - for type profile\n const existProfile = await getDocumentProfile({ documentId, documentType: _documentType, profileType: \"profile\" })\n\n let response: any = {}\n\n if (existProfile) {\n\n let payload: DocumentProfileUpdateProps = {\n documentProfileId: Number(existProfile?.document_profile_id),\n documentType: _documentType,\n data: {\n profileType: \"profile\",\n userBranchId: Number(userHQBranches.branch_id),\n userId: Number(userHQBranches.user_id),\n code: userHQBranches.branch_code ?? \"\",\n contactNo: userHQBranches.branch_contact ?? \"\",\n email: userHQBranches.branch_email ?? \"\",\n personName: `${userHQBranches?.pic_name ?? \"\"}`,\n postcode: userHQBranches.postcode ?? \"\",\n profileName: userHQBranches.branch_name ?? \"\",\n stateId: Number(userHQBranches.state_id),\n areaId: Number(userHQBranches.area_id),\n countryId: Number(userHQBranches.country_id),\n address1: userHQBranches.address_1 ?? \"\",\n address2: userHQBranches.address_2 ?? \"\",\n }\n }\n\n // update document profile for profile\n response = await updateDocumentProfile(payload)\n\n } else { // create new\n let payload: DocumentProfileCreateProps = {\n documentId,\n documentType: _documentType,\n data: {\n profileType: \"profile\",\n userBranchId: Number(userHQBranches.branch_id),\n userId: Number(userHQBranches.user_id),\n code: userHQBranches.branch_code ?? \"\",\n contactNo: userHQBranches.branch_contact ?? \"\",\n email: userHQBranches.branch_email ?? \"\",\n personName: `${userHQBranches?.pic_name ?? \"\"}`,\n postcode: userHQBranches.postcode ?? \"\",\n profileName: userHQBranches.branch_name ?? \"\",\n stateId: Number(userHQBranches.state_id),\n areaId: Number(userHQBranches.area_id),\n countryId: Number(userHQBranches.country_id),\n address1: userHQBranches.address_1 ?? \"\",\n address2: userHQBranches.address_2 ?? \"\",\n }\n }\n\n // create document profile for profile\n response = await createDocumentProfile(payload)\n\n }\n\n return response\n\n }\n\n // override existing - if not found create new\n const replaceDocumentProfileOther = async ({ data, documentId, documentProfileType = \"shipping\", documentType: overrideDocumentType }: DocumentProfileReplaceOtherProps) => {\n\n const _documentType = overrideDocumentType || documentType\n\n const userBranchId = data.userBranchId\n // const userType = data.userType\n // const documentId = data.documentId\n\n let userBranch = await userBranchService.getUserBranch({ userBranchId, datatypes: [] })\n\n // console.log('userBranch', userBranch)\n\n if (!userBranch?.user_id) {\n throwError(`Invalid user id in user branch: ${userBranchId}`)\n }\n\n // check the profile other already exists - for other type than profile\n const existProfile = await getDocumentProfile({ documentId, documentType: _documentType, profileType: documentProfileType })\n\n let response: any = {}\n\n if (existProfile) {\n\n let payload: DocumentProfileUpdateProps = {\n documentProfileId: Number(existProfile?.document_profile_id),\n documentType: _documentType,\n data: {\n profileType: documentProfileType,\n userBranchId: Number(userBranch.branch_id),\n userId: Number(userBranch.user_id),\n\n code: data?.code ? data.code : String(userBranch.branch_code ?? \"\"),\n contactNo: data?.code ? data.code : String(userBranch.branch_contact ?? \"\"),\n email: data?.email ? data.email : String(userBranch.branch_email ?? \"\"),\n personName: data?.personName ? data.personName : String(`${userBranch?.pic_name ?? \"\"}`),\n postcode: data?.postcode ? data.postcode : String(userBranch.postcode ?? \"\"),\n profileName: data?.profileName ? data.profileName : String(userBranch.branch_name ?? \"\"),\n stateId: data?.stateId ? Number(data.stateId) : Number(userBranch.state_id),\n areaId: data?.areaId ? Number(data.areaId) : Number(userBranch.area_id),\n countryId: data?.countryId ? Number(data.countryId) : Number(userBranch.country_id),\n address1: data?.address1 ? data.address1 : String(userBranch.address_1 ?? \"\"),\n address2: data?.address2 ? data.address2 : String(userBranch.address_2 ?? \"\"),\n }\n }\n\n // update document profile for (shipping or billing)\n response = await updateDocumentProfile(payload)\n\n } else {\n\n let payload: DocumentProfileCreateProps = {\n documentId,\n documentType: _documentType,\n data: {\n profileType: documentProfileType,\n userBranchId: Number(userBranch.branch_id),\n userId: Number(userBranch.user_id),\n\n code: data?.code ? data.code : String(userBranch.branch_code ?? \"\"),\n contactNo: data?.code ? data.code : String(userBranch.branch_contact ?? \"\"),\n email: data?.email ? data.email : String(userBranch.branch_email ?? \"\"),\n personName: data?.personName ? data.personName : String(`${userBranch?.pic_name ?? \"\"}`),\n postcode: data?.postcode ? data.postcode : String(userBranch.postcode ?? \"\"),\n profileName: data?.profileName ? data.profileName : String(userBranch.branch_name ?? \"\"),\n stateId: data?.stateId ? Number(data.stateId) : Number(userBranch.state_id),\n areaId: data?.areaId ? Number(data.areaId) : Number(userBranch.area_id),\n countryId: data?.countryId ? Number(data.countryId) : Number(userBranch.country_id),\n address1: data?.address1 ? data.address1 : String(userBranch.address_1 ?? \"\"),\n address2: data?.address2 ? data.address2 : String(userBranch.address_2 ?? \"\"),\n }\n }\n\n // create document profile for (shipping or billing)\n response = await createDocumentProfile(payload)\n }\n\n return response\n\n }\n\n // private\n const createDocumentProfile = async ({ data, documentId, documentType: overrideDocumentType }: DocumentProfileCreateProps) => {\n\n const _documentType = overrideDocumentType || documentType\n\n const _data = getCreatePayload(documentId, _documentType, data)\n\n if (!_data) {\n throw new Error(`Invalid create document(profile) payload: ${JSON.stringify(_data)}`);\n }\n\n // create document profile\n return await documentProfileModel.create({ data: _data })\n\n }\n\n // private\n const updateDocumentProfile = async ({ documentProfileId, data, documentType: overrideDocumentType }: DocumentProfileUpdateProps) => {\n\n const _documentType = overrideDocumentType || documentType\n\n const _data = getUpdatePayload(_documentType, data)\n\n if (!_data) {\n throw new Error(`Invalid update document(profile) payload: ${JSON.stringify(_data)}`);\n }\n\n // update document profile\n return await documentProfileModel.update({ id: documentProfileId, data: _data })\n\n }\n\n const getDocumentProfile = async ({ documentId = \"\", documentType = \"\", profileType = \"\" }: DocumentProfileGetProps) => {\n\n let filters = []\n\n if (documentType) {\n filters.push({ field: `${ModelDocumentProfileFields.document_type}`, operator: \"=\", value: documentType })\n }\n if (documentId) {\n filters.push({ field: `${ModelDocumentProfileFields.document_id}`, operator: \"=\", value: Number(documentId) })\n }\n if (profileType) {\n filters.push({ field: `${ModelDocumentProfileFields.type}`, operator: \"=\", value: profileType.toUpperCase() })\n }\n\n let { data } = await listDocumentProfiles({\n limit: 1,\n offset: 0,\n filters: filters as QueryList[\"filters\"],\n sortfield: `${ModelDocumentProfileFields.document_id}`,\n sortorder: \"ASC\",\n // datatypes: []\n })\n\n return data[0] ?? null;\n\n };\n\n const listDocumentProfiles = async ({\n limit,\n offset,\n filters,\n sortfield,\n sortorder,\n // datatypes = []\n }: DocumentProfileListProps) => {\n\n let sqlSelect: string[] = []\n let sqlRelation: string[] = []\n let sqlGroupBy: string[] = []\n\n let sqlSelectAgg: string[] = []\n let sqlRelationAgg: string[] = []\n\n sqlSelect = [\n buildSqlSelect(``, mainSqlSelect),\n buildSqlSelect(``, defaultSqlSelect)\n ]\n\n // sqlRelation = [\n // buildSqlRelation(\"left\", \"docpro\", \"users\", \"creator\", [\"docpro.createuserid = creator.user_id\", \"creator.isdelete = false\", \"creator.istrash = false\"]),\n // buildSqlRelation(\"left\", \"docpro\", \"users\", \"updater\", [\"docpro.updateuserid = updater.user_id\", \"updater.isdelete = false\", \"updater.istrash = false\"])\n // ]\n\n sqlRelation = [\n sqlRelationMaps.creator,\n sqlRelationMaps.updater\n ]\n\n // sqlRelationAgg = [\n // buildSqlRelation(\"left\", \"docpro\", \"document_items\", \"docitm\", [\"docpro.document_id = docitm.document_id\", \"docitm.isdelete = false\", \"docitm.istrash = false\"]),\n // ]\n\n sqlGroupBy = [\n ...Object.keys(mainSqlSelect),\n ...Object.keys(defaultSqlSelect)\n ]\n\n let filterColumns = {\n ...mainSqlSelect,\n ...defaultSqlSelect\n }\n\n let sqlWhere = [\n `docpro.isdelete = false`,\n `docpro.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 // get the data (pagination)\n // const sqlRaw = buildSqlRawSelect({\n // tableName: \"document_profiles\",\n // mainAlias: \"docpro\",\n // accountId: rest.accountId,\n // sqlSelect: [...sqlSelect, ...sqlSelectAgg],\n // sqlRelation: [...sqlRelation, ...sqlRelationAgg],\n // sqlWhere,\n // sqlGroupBy,\n // sqlOrderby,\n // sqlLimitOffset\n // })\n\n // let data = await documentModel.raw(sqlRaw)\n\n // // get the count\n // const sqlRawCount = buildSqlRawSelectCount({\n // tableName: \"document_profiles\",\n // mainAlias: \"docpro\",\n // accountId: rest.accountId,\n // sqlSelect,\n // sqlRelation,\n // sqlWhere,\n // sqlGroupBy,\n // sqlOrderby\n // })\n\n // let count = await documentModel.raw(sqlRawCount)\n\n // get the listing data & count\n const { data, total } = await getListWithCount({\n model: documentModel,\n tableName: \"document_profiles\",\n mainAlias: \"docpro\",\n countKey: `${ModelDocumentProfileFields.document_profile_id}`,\n accountId: rest.accountId,\n sqlRelationMaps,\n filters,\n filterColumns,\n sqlSelect,\n sqlSelectAgg,\n sqlRelation,\n sqlRelationAgg,\n sqlWhere,\n sqlGroupBy,\n sqlOrderby,\n sqlLimitOffset\n })\n\n const response = {\n data,\n total\n }\n\n // const response = {\n // data,\n // total: data.length ? Number(count[0].filtered_count) : 0\n // }\n\n return response\n\n };\n\n const removeDocumentProfiles = async ({ documentIds }: DocumentProfileRemoveProps) => {\n\n if (!documentIds.length) throwError('documentIds is required');\n\n const response = await documentProfileModel.remove({ where: { [`${ModelDocumentProfileFields.document_id}`]: { in: documentIds } } });\n\n return response\n };\n\n return {\n replaceDocumentProfileHQ,\n replaceDocumentProfileOther,\n removeDocumentProfiles,\n // createDocumentProfile // no need export internal use only\n // updateDocumentProfile // no need export internal use only\n }\n\n}\n\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Request } from "express";
|
|
2
|
+
import type { Prisma } from "@prisma/client";
|
|
2
3
|
export type DefaultServiceProps = {
|
|
3
4
|
accountId: number;
|
|
4
5
|
actionUserId: number;
|
|
@@ -8,6 +9,7 @@ export type DefaultServiceProps = {
|
|
|
8
9
|
accessKey?: string;
|
|
9
10
|
accessKeyId?: string;
|
|
10
11
|
req?: Request;
|
|
12
|
+
tx?: Prisma.TransactionClient;
|
|
11
13
|
};
|
|
12
14
|
export declare const getDefaultServiceProps: (req: Request) => DefaultServiceProps;
|
|
13
15
|
export declare const generateServiceProps: ({ buildType, accessKey }: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serviceUtils.js","sourceRoot":"","sources":["../../src/utils/serviceUtils.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"serviceUtils.js","sourceRoot":"","sources":["../../src/utils/serviceUtils.ts"],"names":[],"mappings":";;;AAIA,yCAA6D;AAC7D,qDAA8C;AAE9C,uDAAyD;AAelD,MAAM,sBAAsB,GAAG,CAAC,GAAY,EAAuB,EAAE;IAExE,MAAM,kBAAkB,GAAI,GAAW,EAAE,IAAI,IAAI,EAAE,CAAA;IACnD,MAAM,SAAS,GAAI,GAAW,EAAE,SAAS,IAAI,EAAE,CAAA;IAC/C,MAAM,YAAY,GAAI,GAAW,EAAE,YAAY,IAAI,EAAE,CAAA;IACrD,MAAM,cAAc,GAAI,GAAW,EAAE,cAAc,IAAI,EAAE,CAAA;IAEzD,MAAM,EACF,SAAS,GAAG,EAAE,EACd,UAAU,GAAG,KAAK,EAClB,SAAS,GAAG,EAAE,EACd,WAAW,GAAG,EAAE,EACnB,GAAG,kBAAkB,CAAA;IAEtB,OAAO;QACH,SAAS;QACT,YAAY;QACZ,cAAc;QACd,SAAS;QACT,UAAU;QACV,SAAS;QACT,WAAW;QACX,GAAG;KACN,CAAA;AACL,CAAC,CAAA;AAxBY,QAAA,sBAAsB,0BAwBlC;AAEM,MAAM,oBAAoB,GAAG,KAAK,EAAE,EACvC,SAAS,GAAG,YAAY,EACxB,SAAS,EAIZ,EAAgC,EAAE;IAE/B,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,sCAAoB,GAAE,CAAA;IAEzC,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,IAAA,2BAAU,EAAC,kEAAkE,CAAC,CAAA;IAClF,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACV,IAAA,2BAAU,EAAC,8DAA8D,CAAC,CAAA;IAC9E,CAAC;IAED,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,IAAA,2BAAU,EAAC,kEAAkE,CAAC,CAAA;IAClF,CAAC;IAED,MAAM,oBAAoB,GAAG,IAAA,+BAAoB,EAAC;QAC9C,SAAS,EAAE,CAAC;QACZ,YAAY,EAAE,CAAC;QACf,cAAc,EAAE,EAAE;QAClB,SAAS,EAAE,EAAE;QACb,UAAU,EAAE,IAAI;QAChB,SAAS,EAAE,EAAE;QACb,WAAW,EAAE,EAAE;QACf,iBAAiB,EAAE,UAAU;KAChC,CAAC,CAAA;IAEF,MAAM,kBAAkB,GAAG,MAAM,oBAAoB,CAAC,iBAAiB,CAAC;QACpE,IAAI,EAAE;YACF,SAAS;SACZ;KACJ,CAAC,CAAA;IAEF,8EAA8E;IAE9E,OAAO;QACH,SAAS,EAAE,MAAM,CAAC,kBAAkB,EAAE,SAAS,CAAC;QAChD,YAAY,EAAE,MAAM,CAAC,kBAAkB,EAAE,OAAO,CAAC;QACjD,cAAc,EAAE,kBAAkB,EAAE,SAAS,IAAI,EAAE;QACnD,SAAS,EAAE,EAAE;QACb,SAAS;QACT,WAAW,EAAE,kBAAkB,EAAE,aAAa,IAAI,EAAE;QACpD,UAAU,EAAE,kBAAkB,EAAE,SAAS,KAAK,oBAAS,CAAC,QAAQ;KACnE,CAAA;AAEL,CAAC,CAAA;AAnDY,QAAA,oBAAoB,wBAmDhC","sourcesContent":["import { Request } from \"express\";\n\nimport type { Prisma } from \"@prisma/client\";\n\nimport { AccessKeyUtilService, userTypes } from \"@/services\";\nimport { throwError } from \"./exceptionUtils\";\n\nimport { getCoreConfiguration } from \"./coreConfigUtils\";\n\nexport type DefaultServiceProps = {\n accountId: number,\n actionUserId: number,\n actionUserType: string,\n authToken: string,\n isOperator: boolean,\n accessKey?: string,\n accessKeyId?: string\n req?: Request,\n // ✅ ADD THIS\n tx?: Prisma.TransactionClient\n}\n\nexport const getDefaultServiceProps = (req: Request): DefaultServiceProps => {\n\n const requestAuthContext = (req as any)?.auth ?? {}\n const accountId = (req as any)?.accountId ?? \"\"\n const actionUserId = (req as any)?.actionUserId ?? \"\"\n const actionUserType = (req as any)?.actionUserType ?? \"\"\n\n const {\n authToken = '',\n isOperator = false,\n accessKey = '',\n accessKeyId = ''\n } = requestAuthContext\n\n return {\n accountId,\n actionUserId,\n actionUserType,\n authToken,\n isOperator,\n accessKey,\n accessKeyId,\n req\n }\n}\n\nexport const generateServiceProps = async ({\n buildType = \"access_key\",\n accessKey\n}: {\n buildType?: \"access_key\",\n accessKey: string,\n}): Promise<DefaultServiceProps> => {\n\n const { prisma } = getCoreConfiguration()\n\n if (!buildType) {\n throwError(`Build Type is required in generate service props from access key`)\n }\n\n if (!prisma) {\n throwError(`Prisma is required in generate service props from access key`)\n }\n\n if (!accessKey) {\n throwError(`Access Key is required in generate service props from access key`)\n }\n\n const accessKeyUtilService = AccessKeyUtilService({\n accountId: 0,\n actionUserId: 0,\n actionUserType: \"\",\n authToken: '',\n isOperator: true,\n accessKey: '',\n accessKeyId: '',\n accessKeyUserType: \"operator\"\n })\n\n const validatedAccessKey = await accessKeyUtilService.validateAccessKey({\n data: {\n accessKey\n }\n })\n\n // console.log('defaultServiceProps', defaultServiceProps, validatedAccessKey)\n\n return {\n accountId: Number(validatedAccessKey?.accountid),\n actionUserId: Number(validatedAccessKey?.user_id),\n actionUserType: validatedAccessKey?.user_type ?? \"\",\n authToken: \"\",\n accessKey,\n accessKeyId: validatedAccessKey?.access_key_id ?? \"\",\n isOperator: validatedAccessKey?.user_type === userTypes.operator,\n }\n\n}"]}
|