@lyxa.ai/marketing 1.0.38 → 1.0.41
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 +89 -9
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts +4 -0
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.d.ts +3 -0
- package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.js +111 -6
- package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/custom-coupon.service.d.ts +28 -2
- package/dist/lib/modules/coupon/services/custom-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/custom-coupon.service.js +13 -33
- package/dist/lib/modules/coupon/services/custom-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/helper.service.d.ts +30 -2
- package/dist/lib/modules/coupon/services/helper.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/helper.service.js +112 -4
- package/dist/lib/modules/coupon/services/helper.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/individual-store-coupon.service.d.ts +29 -3
- package/dist/lib/modules/coupon/services/individual-store-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/individual-store-coupon.service.js +10 -62
- package/dist/lib/modules/coupon/services/individual-store-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js +16 -6
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js.map +1 -1
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.d.ts +9 -0
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.js +96 -29
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/shops-categories-coupon.service.d.ts +29 -3
- package/dist/lib/modules/coupon/services/shops-categories-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/shops-categories-coupon.service.js +10 -63
- package/dist/lib/modules/coupon/services/shops-categories-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts +13 -0
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.js +6 -14
- package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
- package/dist/lib/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
- package/dist/lib/modules/deal-setting/services/deal-setting.service.js +4 -4
- package/dist/lib/modules/deal-setting/services/deal-setting.service.js.map +1 -1
- package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts +39 -0
- package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts.map +1 -0
- package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.js +539 -0
- package/dist/lib/modules/marketing/patterns/repository/MarketingMetricsRepository.js.map +1 -0
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts +85 -9
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.js +26 -8
- package/dist/lib/modules/marketing/routers/marketing.router.js.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.d.ts +2 -8
- package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.js +35 -354
- package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts +1 -0
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.js +4 -0
- package/dist/lib/modules/marketing/services/product-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js +28 -7
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +12 -12
- package/dist/lib/modules/marketing/validations/discount-marketing.validation.d.ts +12 -12
- package/dist/lib/modules/marketing/validations/marketing.validation.d.ts +106 -1
- package/dist/lib/modules/marketing/validations/marketing.validation.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/marketing.validation.js +31 -1
- package/dist/lib/modules/marketing/validations/marketing.validation.js.map +1 -1
- package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts.map +1 -1
- package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js +19 -1
- package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js.map +1 -1
- package/dist/lib/utility/utils.d.ts +3 -0
- package/dist/lib/utility/utils.d.ts.map +1 -0
- package/dist/lib/utility/utils.js +31 -0
- package/dist/lib/utility/utils.js.map +1 -0
- package/dist/types/index.d.ts +89 -9
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/coupon/routers/coupon.router.d.ts +4 -0
- package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/coupon.service.d.ts +3 -0
- package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/custom-coupon.service.d.ts +28 -2
- package/dist/types/modules/coupon/services/custom-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/helper.service.d.ts +30 -2
- package/dist/types/modules/coupon/services/helper.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/individual-store-coupon.service.d.ts +29 -3
- package/dist/types/modules/coupon/services/individual-store-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/referral-code-coupon.service.d.ts +57 -0
- package/dist/types/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/shops-categories-coupon.service.d.ts +29 -3
- package/dist/types/modules/coupon/services/shops-categories-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts +13 -0
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts +39 -0
- package/dist/types/modules/marketing/patterns/repository/MarketingMetricsRepository.d.ts.map +1 -0
- package/dist/types/modules/marketing/routers/marketing.router.d.ts +85 -9
- package/dist/types/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/marketing.service.d.ts +2 -8
- package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts +1 -0
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/buy1-get1-marketing.validation.d.ts +12 -12
- package/dist/types/modules/marketing/validations/discount-marketing.validation.d.ts +12 -12
- package/dist/types/modules/marketing/validations/marketing.validation.d.ts +106 -1
- package/dist/types/modules/marketing/validations/marketing.validation.d.ts.map +1 -1
- package/dist/types/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts.map +1 -1
- package/dist/types/utility/utils.d.ts +15 -0
- package/dist/types/utility/utils.d.ts.map +1 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/product-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC/E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GACjB,OAAO,CAAC,MAAM,CAAC;IAgBL,iCAAiC,CAAC,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IA+BxF,cAAc,CAAC,MAAM,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;CAI9D;AAED,eAAO,MAAM,uBAAuB,yBAAyC,CAAC"}
|
|
@@ -165,6 +165,10 @@ let ProductMarketingService = class ProductMarketingService {
|
|
|
165
165
|
const anyExist = result.length > 0;
|
|
166
166
|
return !anyExist;
|
|
167
167
|
}
|
|
168
|
+
async countDocuments(filter) {
|
|
169
|
+
const count = await this.model.countDocuments({ ...filter, deletedAt: null });
|
|
170
|
+
return count ?? 0;
|
|
171
|
+
}
|
|
168
172
|
};
|
|
169
173
|
exports.ProductMarketingService = ProductMarketingService;
|
|
170
174
|
exports.ProductMarketingService = ProductMarketingService = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/product-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AACzC,oDAA+E;AAC/E,uEAA8G;AAS9G,wEAA6G;AAE7G,4DAAoE;AACpE,mGAGiD;AACjD,4EAA4E;AAGrE,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAC3B,KAAK,CAAwD;IAE7D,gCAAgC,CAAqC;IAE7E;QACC,IAAI,CAAC,KAAK,GAAG,8BAA8E,CAAC;QAE5F,IAAI,CAAC,gCAAgC,GAAG,0EAAkC,CAAC;IAC5E,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe;QAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,CAAC,MAAM;YAAE,IAAA,8BAAe,EAAC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,EAAE,YAAY;oBAClB,UAAU,EAAE,WAAW;oBACvB,YAAY,EAAE,KAAK;oBACnB,EAAE,EAAE,cAAc;iBAClB;aACD;YACD,EAAE,OAAO,EAAE,eAAe,EAAE;YAC5B;gBACC,MAAM,EAAE;oBACP,qBAAqB,EAAE,sBAAe,CAAC,MAAM;oBAC7C,6BAA6B,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE;oBAC3C,2BAA2B,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE;iBACzC;aACD;YACD,EAAE,MAAM,EAAE,CAAC,EAAE;SACb,CAAC,CAAC;QAEH,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;QAEnC,OAAO,CAAC,QAAQ,CAAC;IAClB,CAAC;CACD,CAAA;AA1KY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,gBAAO,GAAE;;GACG,uBAAuB,CA0KnC;AAEY,QAAA,uBAAuB,GAAG,gBAAS,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport { ProductMarketingModel, ProductMarketing as Model } from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateProductMarketingDTO as CreateDTO,\n\tQueryProductMarketingDTO as QueryDTO,\n\tQueryMultipleProductMarketingDTO,\n\tUpdateProductMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { FilterDTO, PaginatedResponse } from '@lyxa.ai/core/dist/utilities/validation';\nimport { createRawDocumentPaginatorObject, PaginatorOptions } from '@lyxa.ai/core/dist/utilities/pagination';\nimport { ModelType } from '@typegoose/typegoose/lib/types';\nimport { MarketingStatus } from '@lyxa.ai/core/dist/utilities/enum';\nimport {\n\tSynchronizeProductMarketingService,\n\tsynchronizeProductMarketingService,\n} from './synchronize-product-marketing.service';\nimport { badRequestError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class ProductMarketingService {\n\tprivate model: typeof ProductMarketingModel & SoftDeleteModel<Model>;\n\n\tprivate syncProductsMarketingInfoService: SynchronizeProductMarketingService;\n\n\tconstructor() {\n\t\tthis.model = ProductMarketingModel as typeof ProductMarketingModel & SoftDeleteModel<Model>;\n\n\t\tthis.syncProductsMarketingInfoService = synchronizeProductMarketingService;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.create(data);\n\t\tif (!result) badRequestError('Product marketing creation failed');\n\t\tawait this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductId(data.product);\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get record by ID\n\t * @param id ID of the record\n\t */\n\tpublic async findById(id: string | mongoose.Types.ObjectId): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.findOne({\n\t\t\t_id: id,\n\t\t\tdeletedAt: null,\n\t\t});\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get records\n\t * @param query Query to find records\n\t */\n\tpublic async find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>> {\n\t\ttry {\n\t\t\tconst paginate = createRawDocumentPaginatorObject(this.model as ReturnModelType<typeof this.model>);\n\t\t\tconst options: PaginatorOptions<typeof Model> = {\n\t\t\t\tpage: data?.page,\n\t\t\t\tsize: data?.size,\n\t\t\t\tsort: data?.sort,\n\t\t\t\tquery: data?.query,\n\t\t\t\tselect: data?.select,\n\t\t\t\tpopulate: data?.populate,\n\t\t\t};\n\t\t\tconst paginatedResult = await paginate(options);\n\t\t\treturn paginatedResult;\n\t\t} catch (err) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: `err: ${err}`,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Update single record based on query\n\t * @param query Query to find the record\n\t * @param data Data to update\n\t */\n\tpublic async updateOne(query: QueryDTO, data: UpdateDTO): Promise<string> {\n\t\tconst record = await this.model.findOneAndUpdate(query, data, {\n\t\t\tnew: true,\n\t\t\trunValidators: true,\n\t\t});\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Record not found`,\n\t\t\t});\n\t\t}\n\n\t\treturn 'Records updated successfully';\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteMany(filter: QueryDTO, softDelete: boolean): Promise<string> {\n\t\tconst productMarketings = await this.model.find(filter);\n\n\t\tawait this.model.deleteRecords(filter, softDelete);\n\n\t\tconst productIds: mongoose.Types.ObjectId[] = productMarketings\n\t\t\t.map((r: any) => r.product)\n\t\t\t.filter((p: any): p is mongoose.Types.ObjectId | string => !!p) // filter out null/undefined\n\t\t\t.map((p: any) => (p instanceof mongoose.Types.ObjectId ? p : new mongoose.Types.ObjectId(p))); // convert to ObjectId\n\n\t\tconst uniqueProductIds = [...new Set(productIds.map((id: any) => new mongoose.Types.ObjectId(id)))];\n\t\tawait this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductIds(uniqueProductIds);\n\n\t\treturn 'Record deleted successfully';\n\t}\n\n\tpublic async syncProductMarketingInfo(marketingId: mongoose.Types.ObjectId) {\n\t\tconst productMarketings = await this.model.find({ marketing: marketingId });\n\n\t\tconst productIds: mongoose.Types.ObjectId[] = productMarketings\n\t\t\t.map((r: any) => r.product)\n\t\t\t.filter((p: any): p is mongoose.Types.ObjectId | string => !!p) // filter out null/undefined\n\t\t\t.map((p: any) => (p instanceof mongoose.Types.ObjectId ? p : new mongoose.Types.ObjectId(p))); // convert to ObjectId\n\n\t\tawait this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductIds(productIds);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteMultipleProducts(\n\t\tfilter: QueryMultipleProductMarketingDTO,\n\t\tsoftDelete: boolean\n\t): Promise<string> {\n\t\tconst result = await this.model.deleteRecords(\n\t\t\t{\n\t\t\t\tmarketing: filter.marketing,\n\t\t\t\tproduct: { $in: filter.products },\n\t\t\t},\n\t\t\tsoftDelete\n\t\t);\n\t\t// sync\n\t\treturn 'Record deleted successfully';\n\t}\n\n\t/**\n\t * Check if products are available for marketing\n\t * @param products Array of product IDs\n\t */\n\tpublic async checkProductMarketingAvailability(products: mongoose.Types.ObjectId[]): Promise<boolean> {\n\t\tconst now = new Date();\n\n\t\tconst result = await this.model.aggregate([\n\t\t\t{\n\t\t\t\t$match: { product: { $in: products }, deletedAt: null },\n\t\t\t},\n\t\t\t{\n\t\t\t\t$lookup: {\n\t\t\t\t\tfrom: 'marketings',\n\t\t\t\t\tlocalField: 'marketing',\n\t\t\t\t\tforeignField: '_id',\n\t\t\t\t\tas: 'marketingDoc',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ $unwind: '$marketingDoc' },\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\t'marketingDoc.status': MarketingStatus.ACTIVE,\n\t\t\t\t\t'marketingDoc.duration.start': { $lt: now },\n\t\t\t\t\t'marketingDoc.duration.end': { $gt: now },\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ $limit: 1 }, // stop as soon as one match is found\n\t\t]);\n\n\t\tconst anyExist = result.length > 0;\n\n\t\treturn !anyExist;\n\t}\n}\n\nexport const productMarketingService = Container.get(ProductMarketingService);\n"]}
|
|
1
|
+
{"version":3,"file":"product-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/product-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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BAAuB;IADnC,IAAA,gBAAO,GAAE;;GACG,uBAAuB,CA+KnC;AAEY,QAAA,uBAAuB,GAAG,gBAAS,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport { ProductMarketingModel, ProductMarketing as Model } from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateProductMarketingDTO as CreateDTO,\n\tQueryProductMarketingDTO as QueryDTO,\n\tQueryMultipleProductMarketingDTO,\n\tUpdateProductMarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { FilterDTO, PaginatedResponse } from '@lyxa.ai/core/dist/utilities/validation';\nimport { createRawDocumentPaginatorObject, PaginatorOptions } from '@lyxa.ai/core/dist/utilities/pagination';\nimport { ModelType } from '@typegoose/typegoose/lib/types';\nimport { MarketingStatus } from '@lyxa.ai/core/dist/utilities/enum';\nimport {\n\tSynchronizeProductMarketingService,\n\tsynchronizeProductMarketingService,\n} from './synchronize-product-marketing.service';\nimport { badRequestError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class ProductMarketingService {\n\tprivate model: typeof ProductMarketingModel & SoftDeleteModel<Model>;\n\n\tprivate syncProductsMarketingInfoService: SynchronizeProductMarketingService;\n\n\tconstructor() {\n\t\tthis.model = ProductMarketingModel as typeof ProductMarketingModel & SoftDeleteModel<Model>;\n\n\t\tthis.syncProductsMarketingInfoService = synchronizeProductMarketingService;\n\t}\n\n\t/**\n\t * Create a new record\n\t * @param data Data for the new record\n\t */\n\tpublic async create(data: CreateDTO): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.create(data);\n\t\tif (!result) badRequestError('Product marketing creation failed');\n\t\tawait this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductId(data.product);\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get record by ID\n\t * @param id ID of the record\n\t */\n\tpublic async findById(id: string | mongoose.Types.ObjectId): Promise<DocumentType<Model>> {\n\t\tconst result = await this.model.findOne({\n\t\t\t_id: id,\n\t\t\tdeletedAt: null,\n\t\t});\n\t\tif (!result) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Record not found',\n\t\t\t});\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * Get records\n\t * @param query Query to find records\n\t */\n\tpublic async find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>> {\n\t\ttry {\n\t\t\tconst paginate = createRawDocumentPaginatorObject(this.model as ReturnModelType<typeof this.model>);\n\t\t\tconst options: PaginatorOptions<typeof Model> = {\n\t\t\t\tpage: data?.page,\n\t\t\t\tsize: data?.size,\n\t\t\t\tsort: data?.sort,\n\t\t\t\tquery: data?.query,\n\t\t\t\tselect: data?.select,\n\t\t\t\tpopulate: data?.populate,\n\t\t\t};\n\t\t\tconst paginatedResult = await paginate(options);\n\t\t\treturn paginatedResult;\n\t\t} catch (err) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: `err: ${err}`,\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Update single record based on query\n\t * @param query Query to find the record\n\t * @param data Data to update\n\t */\n\tpublic async updateOne(query: QueryDTO, data: UpdateDTO): Promise<string> {\n\t\tconst record = await this.model.findOneAndUpdate(query, data, {\n\t\t\tnew: true,\n\t\t\trunValidators: true,\n\t\t});\n\n\t\tif (!record) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Record not found`,\n\t\t\t});\n\t\t}\n\n\t\treturn 'Records updated successfully';\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteMany(filter: QueryDTO, softDelete: boolean): Promise<string> {\n\t\tconst productMarketings = await this.model.find(filter);\n\n\t\tawait this.model.deleteRecords(filter, softDelete);\n\n\t\tconst productIds: mongoose.Types.ObjectId[] = productMarketings\n\t\t\t.map((r: any) => r.product)\n\t\t\t.filter((p: any): p is mongoose.Types.ObjectId | string => !!p) // filter out null/undefined\n\t\t\t.map((p: any) => (p instanceof mongoose.Types.ObjectId ? p : new mongoose.Types.ObjectId(p))); // convert to ObjectId\n\n\t\tconst uniqueProductIds = [...new Set(productIds.map((id: any) => new mongoose.Types.ObjectId(id)))];\n\t\tawait this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductIds(uniqueProductIds);\n\n\t\treturn 'Record deleted successfully';\n\t}\n\n\tpublic async syncProductMarketingInfo(marketingId: mongoose.Types.ObjectId) {\n\t\tconst productMarketings = await this.model.find({ marketing: marketingId });\n\n\t\tconst productIds: mongoose.Types.ObjectId[] = productMarketings\n\t\t\t.map((r: any) => r.product)\n\t\t\t.filter((p: any): p is mongoose.Types.ObjectId | string => !!p) // filter out null/undefined\n\t\t\t.map((p: any) => (p instanceof mongoose.Types.ObjectId ? p : new mongoose.Types.ObjectId(p))); // convert to ObjectId\n\n\t\tawait this.syncProductsMarketingInfoService.syncProductMarketingInfoByProductIds(productIds);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteMultipleProducts(\n\t\tfilter: QueryMultipleProductMarketingDTO,\n\t\tsoftDelete: boolean\n\t): Promise<string> {\n\t\tconst result = await this.model.deleteRecords(\n\t\t\t{\n\t\t\t\tmarketing: filter.marketing,\n\t\t\t\tproduct: { $in: filter.products },\n\t\t\t},\n\t\t\tsoftDelete\n\t\t);\n\t\t// sync\n\t\treturn 'Record deleted successfully';\n\t}\n\n\t/**\n\t * Check if products are available for marketing\n\t * @param products Array of product IDs\n\t */\n\tpublic async checkProductMarketingAvailability(products: mongoose.Types.ObjectId[]): Promise<boolean> {\n\t\tconst now = new Date();\n\n\t\tconst result = await this.model.aggregate([\n\t\t\t{\n\t\t\t\t$match: { product: { $in: products }, deletedAt: null },\n\t\t\t},\n\t\t\t{\n\t\t\t\t$lookup: {\n\t\t\t\t\tfrom: 'marketings',\n\t\t\t\t\tlocalField: 'marketing',\n\t\t\t\t\tforeignField: '_id',\n\t\t\t\t\tas: 'marketingDoc',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ $unwind: '$marketingDoc' },\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\t'marketingDoc.status': MarketingStatus.ACTIVE,\n\t\t\t\t\t'marketingDoc.duration.start': { $lt: now },\n\t\t\t\t\t'marketingDoc.duration.end': { $gt: now },\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ $limit: 1 }, // stop as soon as one match is found\n\t\t]);\n\n\t\tconst anyExist = result.length > 0;\n\n\t\treturn !anyExist;\n\t}\n\n\tpublic async countDocuments(filter: QueryDTO): Promise<number> {\n\t\tconst count = await this.model.countDocuments({ ...filter, deletedAt: null });\n\t\treturn count ?? 0;\n\t}\n}\n\nexport const productMarketingService = Container.get(ProductMarketingService);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronize-product-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/synchronize-product-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAKhD,OAAO,EAAE,6CAA6C,EAAE,MAAM,0FAA0F,CAAC;AACzJ,qBACa,kCAAkC;IAC9C,OAAO,CAAC,YAAY,CAA+C;;IAMtD,kDAAkD;IAKxD,2CAA2C,CACjD,OAAO,EAAE,6CAA6C,GACpD,MAAM;IAKF,4BAA4B,QAAa,OAAO,CAAC,GAAG,CAAC,CAsD1D;YAEY,oBAAoB;YAsDpB,kCAAkC;IAqCnC,mCAAmC,CAAC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ;IAsCtE,oCAAoC,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"synchronize-product-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/synchronize-product-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAKhD,OAAO,EAAE,6CAA6C,EAAE,MAAM,0FAA0F,CAAC;AACzJ,qBACa,kCAAkC;IAC9C,OAAO,CAAC,YAAY,CAA+C;;IAMtD,kDAAkD;IAKxD,2CAA2C,CACjD,OAAO,EAAE,6CAA6C,GACpD,MAAM;IAKF,4BAA4B,QAAa,OAAO,CAAC,GAAG,CAAC,CAsD1D;YAEY,oBAAoB;YAsDpB,kCAAkC;IAqCnC,mCAAmC,CAAC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ;IAsCtE,oCAAoC,CAAC,UAAU,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE;CAgFvF;AAED,eAAO,MAAM,kCAAkC,oCAAoD,CAAC"}
|
|
@@ -200,19 +200,37 @@ let SynchronizeProductMarketingService = class SynchronizeProductMarketingServic
|
|
|
200
200
|
return 'Synchronized product marketing info';
|
|
201
201
|
}
|
|
202
202
|
async syncProductMarketingInfoByProductIds(productIds) {
|
|
203
|
+
console.time('SYNC_PRODUCT_IDS_TIME');
|
|
204
|
+
console.log(`Starting sync for ${productIds.length} product IDs`);
|
|
203
205
|
if (!productIds.length)
|
|
204
206
|
return 'No products to sync';
|
|
205
207
|
const adminSettings = (await (0, core_1.getLibraries)().getCachedSettingsService().getSettings());
|
|
206
208
|
const exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;
|
|
207
209
|
const secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
210
|
+
const BATCH_SIZE = 500;
|
|
211
|
+
const results = [];
|
|
212
|
+
const totalBatches = Math.ceil(productIds.length / BATCH_SIZE);
|
|
213
|
+
console.time('[ProductAggregate] Total Execution');
|
|
214
|
+
for (let i = 0; i < productIds.length; i += BATCH_SIZE) {
|
|
215
|
+
const batchIndex = i / BATCH_SIZE + 1;
|
|
216
|
+
const batchIds = productIds.slice(i, i + BATCH_SIZE);
|
|
217
|
+
const label = `[ProductAggregate] Batch ${batchIndex}/${totalBatches}`;
|
|
218
|
+
console.log(`${label} → starting (${batchIds.length} ids)`);
|
|
219
|
+
console.time(label);
|
|
220
|
+
const batchResults = await this.productModel.aggregate([
|
|
221
|
+
{
|
|
222
|
+
$match: {
|
|
223
|
+
_id: { $in: batchIds },
|
|
224
|
+
},
|
|
212
225
|
},
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
226
|
+
...(0, product_pipeline_stages_1.addProductMarketingInfo)(exchangeRate, secondaryCurrencyName),
|
|
227
|
+
]);
|
|
228
|
+
console.timeEnd(label);
|
|
229
|
+
console.log(`${label} → completed (${batchResults.length} docs)`);
|
|
230
|
+
results.push(...batchResults);
|
|
231
|
+
}
|
|
232
|
+
console.timeEnd('[ProductAggregate] Total Execution');
|
|
233
|
+
console.log(`[ProductAggregate] Total results: ${results.length}`);
|
|
216
234
|
if (!results.length)
|
|
217
235
|
return 'No matching products found';
|
|
218
236
|
const bulkOps = results.map(product => {
|
|
@@ -237,7 +255,10 @@ let SynchronizeProductMarketingService = class SynchronizeProductMarketingServic
|
|
|
237
255
|
},
|
|
238
256
|
};
|
|
239
257
|
});
|
|
258
|
+
console.timeEnd('SYNC_PRODUCT_IDS_TIME');
|
|
259
|
+
console.time('BULK_WRITE_TIME');
|
|
240
260
|
await this.productModel.bulkWrite(bulkOps);
|
|
261
|
+
console.timeEnd('BULK_WRITE_TIME');
|
|
241
262
|
return `Synchronized product marketing info for ${bulkOps.length} products`;
|
|
242
263
|
}
|
|
243
264
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"synchronize-product-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/synchronize-product-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,wCAA6C;AAG7C,sEAAoG;AACpG,4GAAyG;AACzG,8FAAwH;AAGjH,IAAM,kCAAkC,GAAxC,MAAM,kCAAkC;IACtC,YAAY,CAA+C;IAEnE;QACC,IAAI,CAAC,YAAY,GAAG,qBAA4D,CAAC;IAClF,CAAC;IAEM,KAAK,CAAC,kDAAkD;QAC9D,MAAM,IAAA,0EAAkD,EAAC,EAAE,CAAC,CAAC;QAC7D,OAAO,yDAAyD,CAAC;IAClE,CAAC;IAEM,2CAA2C,CACjD,OAAsD;QAEtD,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,OAAO,yDAAyD,CAAC;IAClE,CAAC;IAEM,4BAA4B,GAAG,KAAK,IAAkB,EAAE;QAC9D,MAAM,UAAU,GAAG,GAAG,CAAC;QAEvB,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;QAE3D,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,gCAAgC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;QAEjG,MAAM,aAAa,GAAG,CAAC,MAAM,IAAA,mBAAY,GAAE,CAAC,wBAAwB,EAAE,CAAC,WAAW,EAAE,CAAY,CAAC;QAEjG,MAAM,YAAY,GAAG,aAAa,EAAE,eAAe,EAAE,YAAY,IAAI,CAAC,CAAC;QACvE,MAAM,qBAAqB,GAAG,aAAa,EAAE,eAAe,EAAE,iBAAiB,EAAE,IAAI,IAAI,KAAK,CAAC;QAE/F,IAAI,KAAK,GAAU,EAAE,CAAC;QACtB,IAAI,UAAU,GAAG,CAAC,CAAC;QACnB,IAAI,cAAc,G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ACD,GAAG,IAAA,iDAAuB,EAAC,YAAY,EAAE,qBAAqB,CAAC;SAC/D,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,CAAC,MAAM;YAAE,OAAO,4BAA4B,CAAC;QAEzD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YACrC,MAAM,oBAAoB,GAAG,OAAO,EAAE,gBAAgB;gBACrD,CAAC,CAAC;oBACA;wBACC,SAAS,EAAE,OAAO,CAAC,gBAAgB,CAAC,aAAa;wBACjD,UAAU,EAAE,OAAO,CAAC,gBAAgB,CAAC,UAAU;wBAC/C,SAAS,EAAE,OAAO,CAAC,gBAAgB,CAAC,SAAS;wBAC7C,KAAK,EAAE,OAAO,CAAC,gBAAgB,CAAC,KAAK;wBACrC,sBAAsB,EAAE,OAAO,CAAC,gBAAgB,CAAC,sBAAsB;wBACvE,KAAK,EAAE,OAAO,CAAC,gBAAgB,CAAC,KAAK;qBACrC;iBACD;gBACF,CAAC,CAAC,EAAE,CAAC;YAEN,OAAO;gBACN,SAAS,EAAE;oBACV,MAAM,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;oBAC5B,MAAM,EAAE;wBACP,IAAI,EAAE,EAAE,oBAAoB,EAAE;qBAC9B;iBACD;aACD,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAE3C,OAAO,2CAA2C,OAAO,CAAC,MAAM,WAAW,CAAC;IAC7E,CAAC;CACD,CAAA;AA3PY,gFAAkC;6CAAlC,kCAAkC;IAD9C,IAAA,gBAAO,GAAE;;GACG,kCAAkC,CA2P9C;AAEY,QAAA,kCAAkC,GAAG,gBAAS,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { getLibraries } from '@lyxa.ai/core';\nimport { mongoose } from '@typegoose/typegoose';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { ProductModel, Product as Model, Setting } from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport { addProductMarketingInfo } from '@lyxa.ai/core/dist/utilities/pipelines/product-pipeline-stages';\nimport { publishAllProductsProductMarketingInfoProcessEvent } from '@lyxa.ai/core/dist/utilities/events-common-methods';\nimport { SynchronizeAllProductsProductMarketingInfoDTO } from '@lyxa.ai/core/dist/libraries/event/events/sync-all-products-product-marketing-info-event';\n@Service()\nexport class SynchronizeProductMarketingService {\n\tprivate productModel: typeof ProductModel & SoftDeleteModel<Model>;\n\n\tconstructor() {\n\t\tthis.productModel = ProductModel as typeof ProductModel & SoftDeleteModel<Model>;\n\t}\n\n\tpublic async publishAllProductsProductMarketingInfoProcessEvent() {\n\t\tawait publishAllProductsProductMarketingInfoProcessEvent({});\n\t\treturn 'Processing all products product marketing information! ';\n\t}\n\n\tpublic processAllProductsProductMarketingInfoEvent(\n\t\tpayload: SynchronizeAllProductsProductMarketingInfoDTO\n\t): string {\n\t\tthis.syncAllProductsMarketingInfo();\n\t\treturn 'Processing all products product marketing information! ';\n\t}\n\n\tpublic syncAllProductsMarketingInfo = async (): Promise<any> => {\n\t\tconst CHUNK_SIZE = 500;\n\n\t\tconsole.time('TOTAL_SYNC_TIME');\n\t\tconsole.log('[SYNC] Starting product marketing info sync');\n\n\t\tconst cursor = this.productModel.find().select('_id shop price priceBreakdowns').lean().cursor();\n\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\n\t\tlet batch: any[] = [];\n\t\tlet batchIndex = 0;\n\t\tlet totalProcessed = 0;\n\n\t\tfor await (const product of cursor) {\n\t\t\tbatch.push(product);\n\n\t\t\tif (batch.length === CHUNK_SIZE) {\n\t\t\t\tbatchIndex++;\n\t\t\t\ttotalProcessed += batch.length;\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[SYNC][BATCH ${batchIndex}] Processing ${batch.length} products (Total processed: ${totalProcessed})`\n\t\t\t\t);\n\n\t\t\t\tconsole.time(`[BATCH ${batchIndex}] TIME`);\n\t\t\t\tawait this.processProductsBatch(batch, exchangeRate, secondaryCurrencyName, batchIndex);\n\t\t\t\tconsole.timeEnd(`[BATCH ${batchIndex}] TIME`);\n\n\t\t\t\tbatch = [];\n\t\t\t}\n\t\t}\n\n\t\t// Process remaining products\n\t\tif (batch.length) {\n\t\t\tbatchIndex++;\n\t\t\ttotalProcessed += batch.length;\n\n\t\t\tconsole.log(\n\t\t\t\t`[SYNC][BATCH ${batchIndex}] Processing remaining ${batch.length} products (Total processed: ${totalProcessed})`\n\t\t\t);\n\n\t\t\tconsole.time(`[BATCH ${batchIndex}] TIME`);\n\t\t\tawait this.processProductsBatch(batch, exchangeRate, secondaryCurrencyName, batchIndex);\n\t\t\tconsole.timeEnd(`[BATCH ${batchIndex}] TIME`);\n\t\t}\n\n\t\tconsole.log(`[SYNC] Completed. Total batches: ${batchIndex}, Total products: ${totalProcessed}`);\n\t\tconsole.timeEnd('TOTAL_SYNC_TIME');\n\n\t\treturn 'Bulk product marketing info sync completed';\n\t};\n\n\tprivate async processProductsBatch(\n\t\tproductsBatch: any[],\n\t\texchangeRate: number,\n\t\tsecondaryCurrencyName: string,\n\t\tbatchIndex: number\n\t): Promise<void> {\n\t\tconst productIds = productsBatch.map(p => p._id);\n\n\t\tconsole.log(\n\t\t\t`[BATCH ${batchIndex}] Aggregating marketing info for ${productIds.length} products`,\n\t\t\t`| First ID: ${productIds[0]}`,\n\t\t\t`| Last ID: ${productIds[productIds.length - 1]}`\n\t\t);\n\n\t\tconst results = await this.productModel.aggregate([\n\t\t\t{ $match: { _id: { $in: productIds } } },\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$_id',\n\t\t\t\t\tproductMarketingInfo: { $push: '$productMarketing' },\n\t\t\t\t},\n\t\t\t},\n\t\t]);\n\n\t\tconsole.log(`[BATCH ${batchIndex}] Aggregation completed. Result count: ${results.length}`);\n\n\t\tconst bulkOps = results.map(r => ({\n\t\t\tupdateOne: {\n\t\t\t\tfilter: { _id: r._id },\n\t\t\t\tupdate: {\n\t\t\t\t\t$set: {\n\t\t\t\t\t\tproductMarketingInfo: (r.productMarketingInfo ?? []).filter(Boolean).map((pm: any) => ({\n\t\t\t\t\t\t\tmarketing: pm.marketingInfo,\n\t\t\t\t\t\t\tisBuy1Get1: pm.isBuy1Get1,\n\t\t\t\t\t\t\tvalueType: pm.valueType,\n\t\t\t\t\t\t\tvalue: pm.value,\n\t\t\t\t\t\t\tsecondaryCurrencyValue: pm.secondaryCurrencyValue,\n\t\t\t\t\t\t\tlabel: pm.label,\n\t\t\t\t\t\t})),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}));\n\n\t\tif (bulkOps.length) {\n\t\t\tconsole.log(`[BATCH ${batchIndex}] bulkWrite started (${bulkOps.length} ops)`);\n\t\t\tawait this.productModel.bulkWrite(bulkOps, { ordered: false });\n\t\t\tconsole.log(`[BATCH ${batchIndex}] bulkWrite completed`);\n\t\t} else {\n\t\t\tconsole.log(`[BATCH ${batchIndex}] No bulk operations to write`);\n\t\t}\n\t}\n\n\tprivate async getProductMarketingInfoByProductId(productId: mongoose.Types.ObjectId): Promise<any[]> {\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\n\t\tconst result = await this.productModel.aggregate([\n\t\t\t{\n\t\t\t\t$match: { _id: productId },\n\t\t\t},\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$_id',\n\t\t\t\t\tproductMarketingInfo: {\n\t\t\t\t\t\t$push: '$productMarketing',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t]);\n\n\t\tconst productMarketingInfo = result?.[0]?.productMarketing\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tmarketing: result?.[0].productMarketing.marketingInfo,\n\t\t\t\t\t\tisBuy1Get1: result?.[0].productMarketing.isBuy1Get1,\n\t\t\t\t\t\tvalueType: result?.[0].productMarketing.valueType,\n\t\t\t\t\t\tvalue: result?.[0].productMarketing.value,\n\t\t\t\t\t\tsecondaryCurrencyValue: result?.[0].productMarketing.secondaryCurrencyValue,\n\t\t\t\t\t\tlabel: result?.[0].productMarketing.label,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [];\n\n\t\treturn productMarketingInfo;\n\t}\n\n\tpublic async syncProductMarketingInfoByProductId(productId: mongoose.Types.ObjectId) {\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\t\tconst result = await this.productModel.aggregate([\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\t_id: productId,\n\t\t\t\t},\n\t\t\t},\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t]);\n\n\t\tconst productMarketingInfo = result?.[0]?.productMarketing\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tmarketing: result?.[0].productMarketing.marketingInfo,\n\t\t\t\t\t\tisBuy1Get1: result?.[0].productMarketing.isBuy1Get1,\n\t\t\t\t\t\tvalueType: result?.[0].productMarketing.valueType,\n\t\t\t\t\t\tvalue: result?.[0].productMarketing.value,\n\t\t\t\t\t\tsecondaryCurrencyValue: result?.[0].productMarketing.secondaryCurrencyValue,\n\t\t\t\t\t\tlabel: result?.[0].productMarketing.label,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [];\n\n\t\tawait this.productModel.updateOne(\n\t\t\t{ _id: productId },\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\tproductMarketingInfo,\n\t\t\t\t},\n\t\t\t}\n\t\t);\n\t\treturn 'Synchronized product marketing info';\n\t}\n\n\tpublic async syncProductMarketingInfoByProductIds(productIds: mongoose.Types.ObjectId[]) {\n\t\tif (!productIds.length) return 'No products to sync';\n\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\n\t\tconst results = await this.productModel.aggregate([\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\t_id: { $in: productIds },\n\t\t\t\t},\n\t\t\t},\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t]);\n\n\t\tif (!results.length) return 'No matching products found';\n\n\t\tconst bulkOps = results.map(product => {\n\t\t\tconst productMarketingInfo = product?.productMarketing\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmarketing: product.productMarketing.marketingInfo,\n\t\t\t\t\t\t\tisBuy1Get1: product.productMarketing.isBuy1Get1,\n\t\t\t\t\t\t\tvalueType: product.productMarketing.valueType,\n\t\t\t\t\t\t\tvalue: product.productMarketing.value,\n\t\t\t\t\t\t\tsecondaryCurrencyValue: product.productMarketing.secondaryCurrencyValue,\n\t\t\t\t\t\t\tlabel: product.productMarketing.label,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: [];\n\n\t\t\treturn {\n\t\t\t\tupdateOne: {\n\t\t\t\t\tfilter: { _id: product._id },\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\t$set: { productMarketingInfo },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t});\n\n\t\tawait this.productModel.bulkWrite(bulkOps);\n\n\t\treturn `Synchronized product marketing info for ${bulkOps.length} products`;\n\t}\n}\n\nexport const synchronizeProductMarketingService = Container.get(SynchronizeProductMarketingService);\n"]}
|
|
1
|
+
{"version":3,"file":"synchronize-product-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/synchronize-product-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,wCAA6C;AAG7C,sEAAoG;AACpG,4GAAyG;AACzG,8FAAwH;AAGjH,IAAM,kCAAkC,GAAxC,MAAM,kCAAkC;IACtC,YAAY,CAA+C;IAEnE;QACC,IAAI,CAAC,YAAY,GAAG,qBAA4D,CAAC;IAClF,CAAC;IAEM,KAAK,CAAC,kDAAkD;QAC9D,MAAM,IAAA,0EAAkD,EAAC,EAAE,CAAC,CAAC;QAC7D,OAAO,yDAAyD,CAAC;IAClE,CAAC;IAEM,2CAA2C,CACjD,OAAsD;QAEtD,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,OAAO,yDAAyD,CAAC;IAClE,CAAC;IAEM,4BAA4B,GAAG,KAAK,IAAkB,EAAE;QAC9D,MAAM,UAAU,GAAG,GAAG,CAAC;QAEvB,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;QAE3D,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,gCAAgC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,CAAC;QAEjG,MAAM,aAAa,GAAG,CAAC,MAAM,IAAA,mBAAY,GAAE,CAAC,wBAAwB,EAAE,CAAC,WAAW,EAAE,CAAY,CAAC;QAEjG,MAAM,YAAY,GAAG,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AAW,CAAC;IAC7E,CAAC;CACD,CAAA;AA5RY,gFAAkC;6CAAlC,kCAAkC;IAD9C,IAAA,gBAAO,GAAE;;GACG,kCAAkC,CA4R9C;AAEY,QAAA,kCAAkC,GAAG,gBAAS,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { getLibraries } from '@lyxa.ai/core';\nimport { mongoose } from '@typegoose/typegoose';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { ProductModel, Product as Model, Setting } from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport { addProductMarketingInfo } from '@lyxa.ai/core/dist/utilities/pipelines/product-pipeline-stages';\nimport { publishAllProductsProductMarketingInfoProcessEvent } from '@lyxa.ai/core/dist/utilities/events-common-methods';\nimport { SynchronizeAllProductsProductMarketingInfoDTO } from '@lyxa.ai/core/dist/libraries/event/events/sync-all-products-product-marketing-info-event';\n@Service()\nexport class SynchronizeProductMarketingService {\n\tprivate productModel: typeof ProductModel & SoftDeleteModel<Model>;\n\n\tconstructor() {\n\t\tthis.productModel = ProductModel as typeof ProductModel & SoftDeleteModel<Model>;\n\t}\n\n\tpublic async publishAllProductsProductMarketingInfoProcessEvent() {\n\t\tawait publishAllProductsProductMarketingInfoProcessEvent({});\n\t\treturn 'Processing all products product marketing information! ';\n\t}\n\n\tpublic processAllProductsProductMarketingInfoEvent(\n\t\tpayload: SynchronizeAllProductsProductMarketingInfoDTO\n\t): string {\n\t\tthis.syncAllProductsMarketingInfo();\n\t\treturn 'Processing all products product marketing information! ';\n\t}\n\n\tpublic syncAllProductsMarketingInfo = async (): Promise<any> => {\n\t\tconst CHUNK_SIZE = 500;\n\n\t\tconsole.time('TOTAL_SYNC_TIME');\n\t\tconsole.log('[SYNC] Starting product marketing info sync');\n\n\t\tconst cursor = this.productModel.find().select('_id shop price priceBreakdowns').lean().cursor();\n\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\n\t\tlet batch: any[] = [];\n\t\tlet batchIndex = 0;\n\t\tlet totalProcessed = 0;\n\n\t\tfor await (const product of cursor) {\n\t\t\tbatch.push(product);\n\n\t\t\tif (batch.length === CHUNK_SIZE) {\n\t\t\t\tbatchIndex++;\n\t\t\t\ttotalProcessed += batch.length;\n\n\t\t\t\tconsole.log(\n\t\t\t\t\t`[SYNC][BATCH ${batchIndex}] Processing ${batch.length} products (Total processed: ${totalProcessed})`\n\t\t\t\t);\n\n\t\t\t\tconsole.time(`[BATCH ${batchIndex}] TIME`);\n\t\t\t\tawait this.processProductsBatch(batch, exchangeRate, secondaryCurrencyName, batchIndex);\n\t\t\t\tconsole.timeEnd(`[BATCH ${batchIndex}] TIME`);\n\n\t\t\t\tbatch = [];\n\t\t\t}\n\t\t}\n\n\t\t// Process remaining products\n\t\tif (batch.length) {\n\t\t\tbatchIndex++;\n\t\t\ttotalProcessed += batch.length;\n\n\t\t\tconsole.log(\n\t\t\t\t`[SYNC][BATCH ${batchIndex}] Processing remaining ${batch.length} products (Total processed: ${totalProcessed})`\n\t\t\t);\n\n\t\t\tconsole.time(`[BATCH ${batchIndex}] TIME`);\n\t\t\tawait this.processProductsBatch(batch, exchangeRate, secondaryCurrencyName, batchIndex);\n\t\t\tconsole.timeEnd(`[BATCH ${batchIndex}] TIME`);\n\t\t}\n\n\t\tconsole.log(`[SYNC] Completed. Total batches: ${batchIndex}, Total products: ${totalProcessed}`);\n\t\tconsole.timeEnd('TOTAL_SYNC_TIME');\n\n\t\treturn 'Bulk product marketing info sync completed';\n\t};\n\n\tprivate async processProductsBatch(\n\t\tproductsBatch: any[],\n\t\texchangeRate: number,\n\t\tsecondaryCurrencyName: string,\n\t\tbatchIndex: number\n\t): Promise<void> {\n\t\tconst productIds = productsBatch.map(p => p._id);\n\n\t\tconsole.log(\n\t\t\t`[BATCH ${batchIndex}] Aggregating marketing info for ${productIds.length} products`,\n\t\t\t`| First ID: ${productIds[0]}`,\n\t\t\t`| Last ID: ${productIds[productIds.length - 1]}`\n\t\t);\n\n\t\tconst results = await this.productModel.aggregate([\n\t\t\t{ $match: { _id: { $in: productIds } } },\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$_id',\n\t\t\t\t\tproductMarketingInfo: { $push: '$productMarketing' },\n\t\t\t\t},\n\t\t\t},\n\t\t]);\n\n\t\tconsole.log(`[BATCH ${batchIndex}] Aggregation completed. Result count: ${results.length}`);\n\n\t\tconst bulkOps = results.map(r => ({\n\t\t\tupdateOne: {\n\t\t\t\tfilter: { _id: r._id },\n\t\t\t\tupdate: {\n\t\t\t\t\t$set: {\n\t\t\t\t\t\tproductMarketingInfo: (r.productMarketingInfo ?? []).filter(Boolean).map((pm: any) => ({\n\t\t\t\t\t\t\tmarketing: pm.marketingInfo,\n\t\t\t\t\t\t\tisBuy1Get1: pm.isBuy1Get1,\n\t\t\t\t\t\t\tvalueType: pm.valueType,\n\t\t\t\t\t\t\tvalue: pm.value,\n\t\t\t\t\t\t\tsecondaryCurrencyValue: pm.secondaryCurrencyValue,\n\t\t\t\t\t\t\tlabel: pm.label,\n\t\t\t\t\t\t})),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t}));\n\n\t\tif (bulkOps.length) {\n\t\t\tconsole.log(`[BATCH ${batchIndex}] bulkWrite started (${bulkOps.length} ops)`);\n\t\t\tawait this.productModel.bulkWrite(bulkOps, { ordered: false });\n\t\t\tconsole.log(`[BATCH ${batchIndex}] bulkWrite completed`);\n\t\t} else {\n\t\t\tconsole.log(`[BATCH ${batchIndex}] No bulk operations to write`);\n\t\t}\n\t}\n\n\tprivate async getProductMarketingInfoByProductId(productId: mongoose.Types.ObjectId): Promise<any[]> {\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\n\t\tconst result = await this.productModel.aggregate([\n\t\t\t{\n\t\t\t\t$match: { _id: productId },\n\t\t\t},\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t\t{\n\t\t\t\t$group: {\n\t\t\t\t\t_id: '$_id',\n\t\t\t\t\tproductMarketingInfo: {\n\t\t\t\t\t\t$push: '$productMarketing',\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t]);\n\n\t\tconst productMarketingInfo = result?.[0]?.productMarketing\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tmarketing: result?.[0].productMarketing.marketingInfo,\n\t\t\t\t\t\tisBuy1Get1: result?.[0].productMarketing.isBuy1Get1,\n\t\t\t\t\t\tvalueType: result?.[0].productMarketing.valueType,\n\t\t\t\t\t\tvalue: result?.[0].productMarketing.value,\n\t\t\t\t\t\tsecondaryCurrencyValue: result?.[0].productMarketing.secondaryCurrencyValue,\n\t\t\t\t\t\tlabel: result?.[0].productMarketing.label,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [];\n\n\t\treturn productMarketingInfo;\n\t}\n\n\tpublic async syncProductMarketingInfoByProductId(productId: mongoose.Types.ObjectId) {\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\t\tconst result = await this.productModel.aggregate([\n\t\t\t{\n\t\t\t\t$match: {\n\t\t\t\t\t_id: productId,\n\t\t\t\t},\n\t\t\t},\n\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t]);\n\n\t\tconst productMarketingInfo = result?.[0]?.productMarketing\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tmarketing: result?.[0].productMarketing.marketingInfo,\n\t\t\t\t\t\tisBuy1Get1: result?.[0].productMarketing.isBuy1Get1,\n\t\t\t\t\t\tvalueType: result?.[0].productMarketing.valueType,\n\t\t\t\t\t\tvalue: result?.[0].productMarketing.value,\n\t\t\t\t\t\tsecondaryCurrencyValue: result?.[0].productMarketing.secondaryCurrencyValue,\n\t\t\t\t\t\tlabel: result?.[0].productMarketing.label,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [];\n\n\t\tawait this.productModel.updateOne(\n\t\t\t{ _id: productId },\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\tproductMarketingInfo,\n\t\t\t\t},\n\t\t\t}\n\t\t);\n\t\treturn 'Synchronized product marketing info';\n\t}\n\n\tpublic async syncProductMarketingInfoByProductIds(productIds: mongoose.Types.ObjectId[]) {\n\t\tconsole.time('SYNC_PRODUCT_IDS_TIME');\n\t\tconsole.log(`Starting sync for ${productIds.length} product IDs`); // Debug log\n\t\tif (!productIds.length) return 'No products to sync';\n\n\t\tconst adminSettings = (await getLibraries().getCachedSettingsService().getSettings()) as Setting;\n\n\t\tconst exchangeRate = adminSettings?.currencySetting?.exchangeRate ?? 0;\n\t\tconst secondaryCurrencyName = adminSettings?.currencySetting?.secondaryCurrency?.name ?? 'LBP';\n\n\t\tconst BATCH_SIZE = 500;\n\t\tconst results: any[] = [];\n\n\t\tconst totalBatches = Math.ceil(productIds.length / BATCH_SIZE);\n\n\t\tconsole.time('[ProductAggregate] Total Execution');\n\n\t\tfor (let i = 0; i < productIds.length; i += BATCH_SIZE) {\n\t\t\tconst batchIndex = i / BATCH_SIZE + 1;\n\t\t\tconst batchIds = productIds.slice(i, i + BATCH_SIZE);\n\n\t\t\tconst label = `[ProductAggregate] Batch ${batchIndex}/${totalBatches}`;\n\n\t\t\tconsole.log(`${label} → starting (${batchIds.length} ids)`);\n\t\t\tconsole.time(label);\n\n\t\t\tconst batchResults = await this.productModel.aggregate([\n\t\t\t\t{\n\t\t\t\t\t$match: {\n\t\t\t\t\t\t_id: { $in: batchIds },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...addProductMarketingInfo(exchangeRate, secondaryCurrencyName),\n\t\t\t]);\n\n\t\t\tconsole.timeEnd(label);\n\t\t\tconsole.log(`${label} → completed (${batchResults.length} docs)`);\n\n\t\t\tresults.push(...batchResults);\n\t\t}\n\n\t\tconsole.timeEnd('[ProductAggregate] Total Execution');\n\n\t\tconsole.log(`[ProductAggregate] Total results: ${results.length}`);\n\n\t\tif (!results.length) return 'No matching products found';\n\n\t\tconst bulkOps = results.map(product => {\n\t\t\tconst productMarketingInfo = product?.productMarketing\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tmarketing: product.productMarketing.marketingInfo,\n\t\t\t\t\t\t\tisBuy1Get1: product.productMarketing.isBuy1Get1,\n\t\t\t\t\t\t\tvalueType: product.productMarketing.valueType,\n\t\t\t\t\t\t\tvalue: product.productMarketing.value,\n\t\t\t\t\t\t\tsecondaryCurrencyValue: product.productMarketing.secondaryCurrencyValue,\n\t\t\t\t\t\t\tlabel: product.productMarketing.label,\n\t\t\t\t\t\t},\n\t\t\t\t\t]\n\t\t\t\t: [];\n\n\t\t\treturn {\n\t\t\t\tupdateOne: {\n\t\t\t\t\tfilter: { _id: product._id },\n\t\t\t\t\tupdate: {\n\t\t\t\t\t\t$set: { productMarketingInfo },\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t};\n\t\t});\n\n\t\tconsole.timeEnd('SYNC_PRODUCT_IDS_TIME');\n\n\t\tconsole.time('BULK_WRITE_TIME');\n\t\tawait this.productModel.bulkWrite(bulkOps);\n\n\t\tconsole.timeEnd('BULK_WRITE_TIME');\n\n\t\treturn `Synchronized product marketing info for ${bulkOps.length} products`;\n\t}\n}\n\nexport const synchronizeProductMarketingService = Container.get(SynchronizeProductMarketingService);\n"]}
|
|
@@ -52,9 +52,6 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
52
52
|
spendLimit: number;
|
|
53
53
|
isSpendLimitEnabled: boolean;
|
|
54
54
|
shop: import("mongoose").Types.ObjectId;
|
|
55
|
-
marketingType: MarketingType.BUY1GET1;
|
|
56
|
-
isAppliedByCompany: boolean;
|
|
57
|
-
pausedAt: Date | null;
|
|
58
55
|
products: {
|
|
59
56
|
product: import("mongoose").Types.ObjectId;
|
|
60
57
|
value?: number | undefined;
|
|
@@ -62,6 +59,9 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
62
59
|
marketing?: import("mongoose").Types.ObjectId | undefined;
|
|
63
60
|
isBuy1Get1?: boolean | undefined;
|
|
64
61
|
}[];
|
|
62
|
+
marketingType: MarketingType.BUY1GET1;
|
|
63
|
+
isAppliedByCompany: boolean;
|
|
64
|
+
pausedAt: Date | null;
|
|
65
65
|
categories: import("mongoose").Types.ObjectId[];
|
|
66
66
|
isEntireMenu: boolean;
|
|
67
67
|
excludeProducts: import("mongoose").Types.ObjectId[];
|
|
@@ -79,7 +79,6 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
79
79
|
spendLimit?: number | undefined;
|
|
80
80
|
isSpendLimitEnabled?: boolean | undefined;
|
|
81
81
|
admin?: string | import("mongoose").Types.ObjectId | null | undefined;
|
|
82
|
-
pausedAt?: string | Date | null | undefined;
|
|
83
82
|
products?: {
|
|
84
83
|
product: string | import("mongoose").Types.ObjectId;
|
|
85
84
|
value?: number | undefined;
|
|
@@ -87,6 +86,7 @@ declare const Buy1Get1MarketingValidationSchema: z.ZodObject<{
|
|
|
87
86
|
marketing?: string | import("mongoose").Types.ObjectId | undefined;
|
|
88
87
|
isBuy1Get1?: boolean | undefined;
|
|
89
88
|
}[] | undefined;
|
|
89
|
+
pausedAt?: string | Date | null | undefined;
|
|
90
90
|
categories?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
91
91
|
isEntireMenu?: boolean | undefined;
|
|
92
92
|
excludeProducts?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
@@ -407,9 +407,6 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
407
407
|
spendLimit: number;
|
|
408
408
|
isSpendLimitEnabled: boolean;
|
|
409
409
|
shop: import("mongoose").Types.ObjectId;
|
|
410
|
-
marketingType: MarketingType.BUY1GET1;
|
|
411
|
-
isAppliedByCompany: boolean;
|
|
412
|
-
pausedAt: Date | null;
|
|
413
410
|
products: {
|
|
414
411
|
product: import("mongoose").Types.ObjectId;
|
|
415
412
|
value?: number | undefined;
|
|
@@ -417,6 +414,9 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
417
414
|
marketing?: import("mongoose").Types.ObjectId | undefined;
|
|
418
415
|
isBuy1Get1?: boolean | undefined;
|
|
419
416
|
}[];
|
|
417
|
+
marketingType: MarketingType.BUY1GET1;
|
|
418
|
+
isAppliedByCompany: boolean;
|
|
419
|
+
pausedAt: Date | null;
|
|
420
420
|
categories: import("mongoose").Types.ObjectId[];
|
|
421
421
|
isEntireMenu: boolean;
|
|
422
422
|
excludeProducts: import("mongoose").Types.ObjectId[];
|
|
@@ -434,7 +434,6 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
434
434
|
spendLimit?: number | undefined;
|
|
435
435
|
isSpendLimitEnabled?: boolean | undefined;
|
|
436
436
|
admin?: string | import("mongoose").Types.ObjectId | null | undefined;
|
|
437
|
-
pausedAt?: string | Date | null | undefined;
|
|
438
437
|
products?: {
|
|
439
438
|
product: string | import("mongoose").Types.ObjectId;
|
|
440
439
|
value?: number | undefined;
|
|
@@ -442,6 +441,7 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
442
441
|
marketing?: string | import("mongoose").Types.ObjectId | undefined;
|
|
443
442
|
isBuy1Get1?: boolean | undefined;
|
|
444
443
|
}[] | undefined;
|
|
444
|
+
pausedAt?: string | Date | null | undefined;
|
|
445
445
|
categories?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
446
446
|
isEntireMenu?: boolean | undefined;
|
|
447
447
|
excludeProducts?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
@@ -455,9 +455,6 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
455
455
|
spendLimit: number;
|
|
456
456
|
isSpendLimitEnabled: boolean;
|
|
457
457
|
shop: import("mongoose").Types.ObjectId;
|
|
458
|
-
marketingType: MarketingType.BUY1GET1;
|
|
459
|
-
isAppliedByCompany: boolean;
|
|
460
|
-
pausedAt: Date | null;
|
|
461
458
|
products: {
|
|
462
459
|
product: import("mongoose").Types.ObjectId;
|
|
463
460
|
value?: number | undefined;
|
|
@@ -465,6 +462,9 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
465
462
|
marketing?: import("mongoose").Types.ObjectId | undefined;
|
|
466
463
|
isBuy1Get1?: boolean | undefined;
|
|
467
464
|
}[];
|
|
465
|
+
marketingType: MarketingType.BUY1GET1;
|
|
466
|
+
isAppliedByCompany: boolean;
|
|
467
|
+
pausedAt: Date | null;
|
|
468
468
|
categories: import("mongoose").Types.ObjectId[];
|
|
469
469
|
isEntireMenu: boolean;
|
|
470
470
|
excludeProducts: import("mongoose").Types.ObjectId[];
|
|
@@ -482,7 +482,6 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
482
482
|
spendLimit?: number | undefined;
|
|
483
483
|
isSpendLimitEnabled?: boolean | undefined;
|
|
484
484
|
admin?: string | import("mongoose").Types.ObjectId | null | undefined;
|
|
485
|
-
pausedAt?: string | Date | null | undefined;
|
|
486
485
|
products?: {
|
|
487
486
|
product: string | import("mongoose").Types.ObjectId;
|
|
488
487
|
value?: number | undefined;
|
|
@@ -490,6 +489,7 @@ declare const Buy1Get1MarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
490
489
|
marketing?: string | import("mongoose").Types.ObjectId | undefined;
|
|
491
490
|
isBuy1Get1?: boolean | undefined;
|
|
492
491
|
}[] | undefined;
|
|
492
|
+
pausedAt?: string | Date | null | undefined;
|
|
493
493
|
categories?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
494
494
|
isEntireMenu?: boolean | undefined;
|
|
495
495
|
excludeProducts?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
@@ -58,9 +58,6 @@ declare const DiscountMarketingValidationSchema: z.ZodObject<{
|
|
|
58
58
|
spendLimit: number;
|
|
59
59
|
isSpendLimitEnabled: boolean;
|
|
60
60
|
shop: import("mongoose").Types.ObjectId;
|
|
61
|
-
marketingType: MarketingType.DISCOUNT;
|
|
62
|
-
isAppliedByCompany: boolean;
|
|
63
|
-
pausedAt: Date | null;
|
|
64
61
|
products: {
|
|
65
62
|
product: import("mongoose").Types.ObjectId;
|
|
66
63
|
value?: number | undefined;
|
|
@@ -68,6 +65,9 @@ declare const DiscountMarketingValidationSchema: z.ZodObject<{
|
|
|
68
65
|
marketing?: import("mongoose").Types.ObjectId | undefined;
|
|
69
66
|
isBuy1Get1?: boolean | undefined;
|
|
70
67
|
}[];
|
|
68
|
+
marketingType: MarketingType.DISCOUNT;
|
|
69
|
+
isAppliedByCompany: boolean;
|
|
70
|
+
pausedAt: Date | null;
|
|
71
71
|
categories: import("mongoose").Types.ObjectId[];
|
|
72
72
|
isEntireMenu: boolean;
|
|
73
73
|
excludeProducts: import("mongoose").Types.ObjectId[];
|
|
@@ -93,7 +93,6 @@ declare const DiscountMarketingValidationSchema: z.ZodObject<{
|
|
|
93
93
|
spendLimit?: number | undefined;
|
|
94
94
|
isSpendLimitEnabled?: boolean | undefined;
|
|
95
95
|
admin?: string | import("mongoose").Types.ObjectId | null | undefined;
|
|
96
|
-
pausedAt?: string | Date | null | undefined;
|
|
97
96
|
products?: {
|
|
98
97
|
product: string | import("mongoose").Types.ObjectId;
|
|
99
98
|
value?: number | undefined;
|
|
@@ -101,6 +100,7 @@ declare const DiscountMarketingValidationSchema: z.ZodObject<{
|
|
|
101
100
|
marketing?: string | import("mongoose").Types.ObjectId | undefined;
|
|
102
101
|
isBuy1Get1?: boolean | undefined;
|
|
103
102
|
}[] | undefined;
|
|
103
|
+
pausedAt?: string | Date | null | undefined;
|
|
104
104
|
categories?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
105
105
|
isEntireMenu?: boolean | undefined;
|
|
106
106
|
excludeProducts?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
@@ -314,9 +314,6 @@ declare const DiscountMarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
314
314
|
spendLimit: number;
|
|
315
315
|
isSpendLimitEnabled: boolean;
|
|
316
316
|
shop: import("mongoose").Types.ObjectId;
|
|
317
|
-
marketingType: MarketingType.DISCOUNT;
|
|
318
|
-
isAppliedByCompany: boolean;
|
|
319
|
-
pausedAt: Date | null;
|
|
320
317
|
products: {
|
|
321
318
|
product: import("mongoose").Types.ObjectId;
|
|
322
319
|
value?: number | undefined;
|
|
@@ -324,6 +321,9 @@ declare const DiscountMarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
324
321
|
marketing?: import("mongoose").Types.ObjectId | undefined;
|
|
325
322
|
isBuy1Get1?: boolean | undefined;
|
|
326
323
|
}[];
|
|
324
|
+
marketingType: MarketingType.DISCOUNT;
|
|
325
|
+
isAppliedByCompany: boolean;
|
|
326
|
+
pausedAt: Date | null;
|
|
327
327
|
categories: import("mongoose").Types.ObjectId[];
|
|
328
328
|
isEntireMenu: boolean;
|
|
329
329
|
excludeProducts: import("mongoose").Types.ObjectId[];
|
|
@@ -349,7 +349,6 @@ declare const DiscountMarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
349
349
|
spendLimit?: number | undefined;
|
|
350
350
|
isSpendLimitEnabled?: boolean | undefined;
|
|
351
351
|
admin?: string | import("mongoose").Types.ObjectId | null | undefined;
|
|
352
|
-
pausedAt?: string | Date | null | undefined;
|
|
353
352
|
products?: {
|
|
354
353
|
product: string | import("mongoose").Types.ObjectId;
|
|
355
354
|
value?: number | undefined;
|
|
@@ -357,6 +356,7 @@ declare const DiscountMarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
357
356
|
marketing?: string | import("mongoose").Types.ObjectId | undefined;
|
|
358
357
|
isBuy1Get1?: boolean | undefined;
|
|
359
358
|
}[] | undefined;
|
|
359
|
+
pausedAt?: string | Date | null | undefined;
|
|
360
360
|
categories?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
361
361
|
isEntireMenu?: boolean | undefined;
|
|
362
362
|
excludeProducts?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
@@ -374,9 +374,6 @@ declare const DiscountMarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
374
374
|
spendLimit: number;
|
|
375
375
|
isSpendLimitEnabled: boolean;
|
|
376
376
|
shop: import("mongoose").Types.ObjectId;
|
|
377
|
-
marketingType: MarketingType.DISCOUNT;
|
|
378
|
-
isAppliedByCompany: boolean;
|
|
379
|
-
pausedAt: Date | null;
|
|
380
377
|
products: {
|
|
381
378
|
product: import("mongoose").Types.ObjectId;
|
|
382
379
|
value?: number | undefined;
|
|
@@ -384,6 +381,9 @@ declare const DiscountMarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
384
381
|
marketing?: import("mongoose").Types.ObjectId | undefined;
|
|
385
382
|
isBuy1Get1?: boolean | undefined;
|
|
386
383
|
}[];
|
|
384
|
+
marketingType: MarketingType.DISCOUNT;
|
|
385
|
+
isAppliedByCompany: boolean;
|
|
386
|
+
pausedAt: Date | null;
|
|
387
387
|
categories: import("mongoose").Types.ObjectId[];
|
|
388
388
|
isEntireMenu: boolean;
|
|
389
389
|
excludeProducts: import("mongoose").Types.ObjectId[];
|
|
@@ -409,7 +409,6 @@ declare const DiscountMarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
409
409
|
spendLimit?: number | undefined;
|
|
410
410
|
isSpendLimitEnabled?: boolean | undefined;
|
|
411
411
|
admin?: string | import("mongoose").Types.ObjectId | null | undefined;
|
|
412
|
-
pausedAt?: string | Date | null | undefined;
|
|
413
412
|
products?: {
|
|
414
413
|
product: string | import("mongoose").Types.ObjectId;
|
|
415
414
|
value?: number | undefined;
|
|
@@ -417,6 +416,7 @@ declare const DiscountMarketingValidationSchemaRefined: z.ZodEffects<z.ZodObject
|
|
|
417
416
|
marketing?: string | import("mongoose").Types.ObjectId | undefined;
|
|
418
417
|
isBuy1Get1?: boolean | undefined;
|
|
419
418
|
}[] | undefined;
|
|
419
|
+
pausedAt?: string | Date | null | undefined;
|
|
420
420
|
categories?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
421
421
|
isEntireMenu?: boolean | undefined;
|
|
422
422
|
excludeProducts?: (string | import("mongoose").Types.ObjectId)[] | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { DTO } from '@lyxa.ai/core/dist/utilities/validation/global-validation';
|
|
3
|
-
import { MarketingStatus, MarketingType } from '@lyxa.ai/core/dist/utilities/enum';
|
|
3
|
+
import { GraphType, MarketingStatus, MarketingType } from '@lyxa.ai/core/dist/utilities/enum';
|
|
4
4
|
export declare const baseMarketingFields: {
|
|
5
5
|
shop: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, import("mongoose").Types.ObjectId, string>, z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>]>;
|
|
6
6
|
marketingType: z.ZodNativeEnum<typeof MarketingType>;
|
|
@@ -198,8 +198,113 @@ export declare const SyncProductMarketingForMultipleProductsSchema: z.ZodObject<
|
|
|
198
198
|
}, {
|
|
199
199
|
productIds: (string | import("mongoose").Types.ObjectId)[];
|
|
200
200
|
}>;
|
|
201
|
+
export declare const IncreaseDuringDiscountSchema: z.ZodObject<{
|
|
202
|
+
count: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
203
|
+
percentageIncrease: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
204
|
+
}, "strip", z.ZodTypeAny, {
|
|
205
|
+
count: number;
|
|
206
|
+
percentageIncrease: number;
|
|
207
|
+
}, {
|
|
208
|
+
count?: number | undefined;
|
|
209
|
+
percentageIncrease?: number | undefined;
|
|
210
|
+
}>;
|
|
211
|
+
export declare const MarketingMetricsSchema: z.ZodObject<{
|
|
212
|
+
numberOfItems: z.ZodOptional<z.ZodNumber>;
|
|
213
|
+
orderIncreaseWithDiscount: z.ZodOptional<z.ZodObject<{
|
|
214
|
+
count: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
215
|
+
percentageIncrease: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
216
|
+
}, "strip", z.ZodTypeAny, {
|
|
217
|
+
count: number;
|
|
218
|
+
percentageIncrease: number;
|
|
219
|
+
}, {
|
|
220
|
+
count?: number | undefined;
|
|
221
|
+
percentageIncrease?: number | undefined;
|
|
222
|
+
}>>;
|
|
223
|
+
customerIncreaseWithDiscount: z.ZodOptional<z.ZodObject<{
|
|
224
|
+
count: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
225
|
+
percentageIncrease: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
226
|
+
}, "strip", z.ZodTypeAny, {
|
|
227
|
+
count: number;
|
|
228
|
+
percentageIncrease: number;
|
|
229
|
+
}, {
|
|
230
|
+
count?: number | undefined;
|
|
231
|
+
percentageIncrease?: number | undefined;
|
|
232
|
+
}>>;
|
|
233
|
+
}, "strip", z.ZodTypeAny, {
|
|
234
|
+
numberOfItems?: number | undefined;
|
|
235
|
+
orderIncreaseWithDiscount?: {
|
|
236
|
+
count: number;
|
|
237
|
+
percentageIncrease: number;
|
|
238
|
+
} | undefined;
|
|
239
|
+
customerIncreaseWithDiscount?: {
|
|
240
|
+
count: number;
|
|
241
|
+
percentageIncrease: number;
|
|
242
|
+
} | undefined;
|
|
243
|
+
}, {
|
|
244
|
+
numberOfItems?: number | undefined;
|
|
245
|
+
orderIncreaseWithDiscount?: {
|
|
246
|
+
count?: number | undefined;
|
|
247
|
+
percentageIncrease?: number | undefined;
|
|
248
|
+
} | undefined;
|
|
249
|
+
customerIncreaseWithDiscount?: {
|
|
250
|
+
count?: number | undefined;
|
|
251
|
+
percentageIncrease?: number | undefined;
|
|
252
|
+
} | undefined;
|
|
253
|
+
}>;
|
|
254
|
+
export declare const MarketingGraphInputSchema: z.ZodObject<{
|
|
255
|
+
marketingId: z.ZodType<string | import("mongoose").Types.ObjectId, z.ZodTypeDef, string | import("mongoose").Types.ObjectId>;
|
|
256
|
+
startDate: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodDate]>, Date, string | Date>, Date, string | Date>, Date, string | Date>;
|
|
257
|
+
endDate: z.ZodEffects<z.ZodEffects<z.ZodEffects<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, Date, string>, z.ZodDate]>, Date, string | Date>, Date, string | Date>, Date, string | Date>;
|
|
258
|
+
type: z.ZodDefault<z.ZodNativeEnum<typeof GraphType>>;
|
|
259
|
+
}, "strip", z.ZodTypeAny, {
|
|
260
|
+
type: GraphType;
|
|
261
|
+
startDate: Date;
|
|
262
|
+
marketingId: string | import("mongoose").Types.ObjectId;
|
|
263
|
+
endDate: Date;
|
|
264
|
+
}, {
|
|
265
|
+
startDate: string | Date;
|
|
266
|
+
marketingId: string | import("mongoose").Types.ObjectId;
|
|
267
|
+
endDate: string | Date;
|
|
268
|
+
type?: GraphType | undefined;
|
|
269
|
+
}>;
|
|
270
|
+
export declare const MarketingOrdersGraphOutputSchema: z.ZodArray<z.ZodObject<{
|
|
271
|
+
date: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
272
|
+
orders: z.ZodDefault<z.ZodNumber>;
|
|
273
|
+
}, "strip", z.ZodTypeAny, {
|
|
274
|
+
date: string;
|
|
275
|
+
orders: number;
|
|
276
|
+
}, {
|
|
277
|
+
date: string;
|
|
278
|
+
orders?: number | undefined;
|
|
279
|
+
}>, "many">;
|
|
280
|
+
export declare const MarketingCustomersGraphOutputSchema: z.ZodArray<z.ZodObject<{
|
|
281
|
+
date: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
282
|
+
customers: z.ZodDefault<z.ZodNumber>;
|
|
283
|
+
}, "strip", z.ZodTypeAny, {
|
|
284
|
+
date: string;
|
|
285
|
+
customers: number;
|
|
286
|
+
}, {
|
|
287
|
+
date: string;
|
|
288
|
+
customers?: number | undefined;
|
|
289
|
+
}>, "many">;
|
|
290
|
+
export declare const MarketingAmountSpentGraphOutputSchema: z.ZodArray<z.ZodObject<{
|
|
291
|
+
date: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
292
|
+
amount: z.ZodDefault<z.ZodNumber>;
|
|
293
|
+
}, "strip", z.ZodTypeAny, {
|
|
294
|
+
date: string;
|
|
295
|
+
amount: number;
|
|
296
|
+
}, {
|
|
297
|
+
date: string;
|
|
298
|
+
amount?: number | undefined;
|
|
299
|
+
}>, "many">;
|
|
201
300
|
export type CreateMarketingDTO = DTO<typeof MarketingValidationSchema>;
|
|
202
301
|
export type MarketingDTO = DTO<typeof MarketingSchema>;
|
|
203
302
|
export type UpdateMarketingDTO = DTO<typeof UpdateMarketingSchema>;
|
|
204
303
|
export type ProductEntireMenuMarketingHandlerDTO = DTO<typeof ProductEntireMenuMarketingHandlerSchema>;
|
|
304
|
+
export type IncreaseDuringDiscountDTO = DTO<typeof IncreaseDuringDiscountSchema>;
|
|
305
|
+
export type MarketingMetricsDTO = DTO<typeof MarketingMetricsSchema>;
|
|
306
|
+
export type MarketingGraphInputDTO = DTO<typeof MarketingGraphInputSchema>;
|
|
307
|
+
export type MarketingOrdersGraphOutputDTO = DTO<typeof MarketingOrdersGraphOutputSchema>;
|
|
308
|
+
export type MarketingCustomersGraphOutputDTO = DTO<typeof MarketingCustomersGraphOutputSchema>;
|
|
309
|
+
export type MarketingAmountSpentGraphOutputDTO = DTO<typeof MarketingAmountSpentGraphOutputSchema>;
|
|
205
310
|
//# sourceMappingURL=marketing.validation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.validation.d.ts","sourceRoot":"/","sources":["modules/marketing/validations/marketing.validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAGN,GAAG,EACH,MAAM,2DAA2D,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;
|
|
1
|
+
{"version":3,"file":"marketing.validation.d.ts","sourceRoot":"/","sources":["modules/marketing/validations/marketing.validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAGN,GAAG,EACH,MAAM,2DAA2D,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAO9F,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;CAQ/B,CAAC;AAYF,QAAA,MACa,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IACvB,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCACnB,iBAAiB,mNACb,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gCACgB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AAM,kCAAkC,GAAG,GAAG,CAAC,OAAO,qCAAqC,CAAC,CAAC"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SyncProductMarketingForMultipleProductsSchema = exports.MarketingSpendLimitsEvaluationSchema = exports.ProductEntireMenuMarketingHandlerSchema = exports.UpdateMarketingSchema = exports.MarketingIdValidationSchema = exports.MarketingSchema = exports.MarketingValidationSchema = exports.baseMarketingFields = void 0;
|
|
3
|
+
exports.MarketingAmountSpentGraphOutputSchema = exports.MarketingCustomersGraphOutputSchema = exports.MarketingOrdersGraphOutputSchema = exports.MarketingGraphInputSchema = exports.MarketingMetricsSchema = exports.IncreaseDuringDiscountSchema = exports.SyncProductMarketingForMultipleProductsSchema = exports.MarketingSpendLimitsEvaluationSchema = exports.ProductEntireMenuMarketingHandlerSchema = exports.UpdateMarketingSchema = exports.MarketingIdValidationSchema = exports.MarketingSchema = exports.MarketingValidationSchema = exports.baseMarketingFields = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const global_validation_1 = require("@lyxa.ai/core/dist/utilities/validation/global-validation");
|
|
6
6
|
const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
7
7
|
const common_validation_1 = require("@lyxa.ai/core/dist/utilities/validation/common-validation");
|
|
8
|
+
const dayjs_1 = require("@lyxa.ai/core/dist/utilities/dayjs");
|
|
8
9
|
exports.baseMarketingFields = {
|
|
9
10
|
shop: global_validation_1.ZodValidation.objectId('Shop'),
|
|
10
11
|
marketingType: global_validation_1.ZodValidation.enumType(enum_1.MarketingType, 'Marketing type'),
|
|
@@ -30,4 +31,33 @@ exports.MarketingSpendLimitsEvaluationSchema = zod_1.z.object({
|
|
|
30
31
|
exports.SyncProductMarketingForMultipleProductsSchema = zod_1.z.object({
|
|
31
32
|
productIds: global_validation_1.ZodValidation.array(global_validation_1.ZodValidation.objectId('product id'), 'product ids'),
|
|
32
33
|
});
|
|
34
|
+
exports.IncreaseDuringDiscountSchema = zod_1.z.object({
|
|
35
|
+
count: global_validation_1.ZodValidation.number('Count of orders or customers during discount').optional().default(0),
|
|
36
|
+
percentageIncrease: global_validation_1.ZodValidation.number('Percentage increase compared to previous duration')
|
|
37
|
+
.optional()
|
|
38
|
+
.default(0),
|
|
39
|
+
});
|
|
40
|
+
exports.MarketingMetricsSchema = zod_1.z.object({
|
|
41
|
+
numberOfItems: global_validation_1.ZodValidation.number('Number of items in the marketing').optional(),
|
|
42
|
+
orderIncreaseWithDiscount: exports.IncreaseDuringDiscountSchema.optional(),
|
|
43
|
+
customerIncreaseWithDiscount: exports.IncreaseDuringDiscountSchema.optional(),
|
|
44
|
+
});
|
|
45
|
+
exports.MarketingGraphInputSchema = zod_1.z.object({
|
|
46
|
+
marketingId: global_validation_1.ZodValidation.objectIdOrStringSchema,
|
|
47
|
+
startDate: global_validation_1.ZodValidation.date('Start Date').transform(val => (0, dayjs_1.dayjs)(val).startOf('day').toDate()),
|
|
48
|
+
endDate: global_validation_1.ZodValidation.date('End Date').transform(val => (0, dayjs_1.dayjs)(val).endOf('day').toDate()),
|
|
49
|
+
type: global_validation_1.ZodValidation.enumType(enum_1.GraphType, 'Type').default(enum_1.GraphType.DAILY),
|
|
50
|
+
});
|
|
51
|
+
exports.MarketingOrdersGraphOutputSchema = zod_1.z.array(zod_1.z.object({
|
|
52
|
+
date: global_validation_1.ZodValidation.string('Date'),
|
|
53
|
+
orders: global_validation_1.ZodValidation.number('Orders').default(0),
|
|
54
|
+
}));
|
|
55
|
+
exports.MarketingCustomersGraphOutputSchema = zod_1.z.array(zod_1.z.object({
|
|
56
|
+
date: global_validation_1.ZodValidation.string('Date'),
|
|
57
|
+
customers: global_validation_1.ZodValidation.number('Customers').default(0),
|
|
58
|
+
}));
|
|
59
|
+
exports.MarketingAmountSpentGraphOutputSchema = zod_1.z.array(zod_1.z.object({
|
|
60
|
+
date: global_validation_1.ZodValidation.string('Date'),
|
|
61
|
+
amount: global_validation_1.ZodValidation.number('Amount').default(0),
|
|
62
|
+
}));
|
|
33
63
|
//# sourceMappingURL=marketing.validation.js.map
|