@lyxa.ai/marketing 1.0.38 → 1.0.40
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 +80 -9
- package/dist/lib/index.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 +122 -5
- package/dist/lib/modules/coupon/services/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 +7 -0
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.js +5 -14
- package/dist/lib/modules/coupon/validations/coupon.validation.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 +80 -9
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.js +23 -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/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 +80 -9
- package/dist/types/index.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/patterns/repository/CouponRepository.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/coupon.validation.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 +80 -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/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,OAAO,EAAyB,gBAAgB,IAAI,KAAK,EAAE,MAAM,4CAA4C,CAAC;AAC9G,OAAO,EACN,yBAAyB,IAAI,SAAS,EACtC,wBAAwB,IAAI,QAAQ,EACpC,gCAAgC,EAChC,yBAAyB,IAAI,SAAS,EACtC,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAEvF,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAQ3D,qBACa,uBAAuB;IACnC,OAAO,CAAC,KAAK,CAAwD;IAErE,OAAO,CAAC,gCAAgC,CAAqC;;IAYhE,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAWrD,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAkB5E,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,iBAAiB,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IA0B3F,SAAS,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAoB5D,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,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,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAoB5D,UAAU,CAAC,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAgBlE,wBAAwB,CAAC,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ;IAe7D,sBAAsB,CAClC,MAAM,EAAE,gCAAgC,EACxC,UAAU,EAAE,OAAO,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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AK,CAAC,iCAAiC,CAAC,QAAmC;QACjF,MAAM,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC;QAEvB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;YACzC;gBACC,MAAM,EAAE,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE;aACvD;YACD;gBACC,OAAO,EAAE;oBACR,IAAI,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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,mCAAmC,CAAC,CAAC;QAClE,MAAM,IAAI,CAAC,gCAAgC,CAAC,mCAAmC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC9F,OAAO,MAAM,CAAC;IACf,CAAC;IAMM,KAAK,CAAC,QAAQ,CAAC,EAAoC;QACzD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;YACvC,GAAG,EAAE,EAAE;YACP,SAAS,EAAE,IAAI;SACf,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,kBAAkB;aAC3B,CA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C,OAAO,CAAC,QAAQ,CAAC;IAClB,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,MAAgB;QAC3C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,GAAG,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC9E,OAAO,KAAK,IAAI,CAAC,CAAC;IACnB,CAAC;CACD,CAAA;AA/KY,0DAAuB;kCAAvB,uBAAuB;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,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;;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AAM,mBAAmB,GAAG,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC;AACrE,MAAM,MAAM,sBAAsB,GAAG,GAAG,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAC3E,MAAM,MAAM,6BAA6B,GAAG,GAAG,CAAC,OAAO,gCAAgC,CAAC,CAAC;AACzF,MAAM,MAAM,gCAAgC,GAAG,GAAG,CAAC,OAAO,mCAAmC,CAAC,CAAC;AAC/F,MAAM,MAAM,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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.validation.js","sourceRoot":"/","sources":["modules/marketing/validations/marketing.validation.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,iGAImE;AACnE,
|
|
1
|
+
{"version":3,"file":"marketing.validation.js","sourceRoot":"/","sources":["modules/marketing/validations/marketing.validation.ts"],"names":[],"mappings":";;;AAAA,6BAAwB;AACxB,iGAImE;AACnE,4DAA8F;AAC9F,iGAA2F;AAC3F,8DAA2D;AAK9C,QAAA,mBAAmB,GAAG;IAClC,IAAI,EAAE,iCAAa,CAAC,QAAQ,CAAC,MAAM,CAAC;IACpC,aAAa,EAAE,iCAAa,CAAC,QAAQ,CAAC,oBAAa,EAAE,gBAAgB,CAAC;IACtE,kBAAkB,EAAE,iCAAa,CAAC,OAAO,CAAC,oBAAoB,CAAC;IAC/D,QAAQ,EAAE,kCAAc;IACxB,MAAM,EAAE,iCAAa,CAAC,QAAQ,CAAC,sBAAe,EAAE,kBAAkB,CAAC,CAAC,OAAO,CAAC,sBAAe,CAAC,MAAM,CAAC;IACnG,QAAQ,EAAE,iCAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IAC7E,KAAK,EAAE,iCAAa,CAAC,QAAQ,CA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AAC,CAAC;CACvD,CAAC,CACF,CAAC;AAEW,QAAA,qCAAqC,GAAG,OAAC,CAAC,KAAK,CAC3D,OAAC,CAAC,MAAM,CAAC;IACR,IAAI,EAAE,iCAAa,CAAC,MAAM,CAAC,MAAM,CAAC;IAClC,MAAM,EAAE,iCAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;CACjD,CAAC,CACF,CAAC","sourcesContent":["import { z } from 'zod';\nimport {\n\tZodValidation,\n\tcreateSchemaBuilder,\n\tDTO,\n} from '@lyxa.ai/core/dist/utilities/validation/global-validation';\nimport { GraphType, MarketingStatus, MarketingType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { DurationSchema } from '@lyxa.ai/core/dist/utilities/validation/common-validation';\nimport { dayjs } from '@lyxa.ai/core/dist/utilities/dayjs';\n\n/**\n * Define the base parent schema fields\n */\nexport const baseMarketingFields = {\n\tshop: ZodValidation.objectId('Shop'),\n\tmarketingType: ZodValidation.enumType(MarketingType, 'Marketing type'),\n\tisAppliedByCompany: ZodValidation.boolean('isAppliedByCompany'),\n\tduration: DurationSchema,\n\tstatus: ZodValidation.enumType(MarketingStatus, 'Marketing status').default(MarketingStatus.ACTIVE),\n\tpausedAt: ZodValidation.date('Paused at').optional().nullable().default(null),\n\tadmin: ZodValidation.objectId('Admin').optional().nullable(),\n};\n\n/**\n * Create schema builder for Parent entity\n * - Includes timestamps\n * - Excludes 'createdAt' from update operations\n */\nconst schemaBuilder = createSchemaBuilder(baseMarketingFields);\n\n/**\n * Get all schemas for the Parent entity\n */\nconst {\n\tBaseSchema: MarketingValidationSchema,\n\tEntitySchema: MarketingSchema,\n\tIdSchema: MarketingIdSchema,\n\tUpdateSchema: UpdateMarketingSchema,\n} = schemaBuilder.getAllSchemas({ createdAt: true });\n\n/**\n * Export schemas\n */\nexport {\n\tMarketingValidationSchema,\n\tMarketingSchema,\n\tMarketingIdSchema as MarketingIdValidationSchema,\n\tUpdateMarketingSchema,\n};\n\nexport const ProductEntireMenuMarketingHandlerSchema = z.object({\n\tproduct: ZodValidation.objectId('Product'),\n\tshop: ZodValidation.objectId('Shop'),\n});\n\nexport const MarketingSpendLimitsEvaluationSchema = z.object({\n\tmarketings: ZodValidation.array(ZodValidation.objectId('marketing'), 'marketings'),\n});\n\nexport const SyncProductMarketingForMultipleProductsSchema = z.object({\n\tproductIds: ZodValidation.array(ZodValidation.objectId('product id'), 'product ids'),\n});\n\nexport const IncreaseDuringDiscountSchema = z.object({\n\tcount: ZodValidation.number('Count of orders or customers during discount').optional().default(0),\n\tpercentageIncrease: ZodValidation.number('Percentage increase compared to previous duration')\n\t\t.optional()\n\t\t.default(0),\n});\n\nexport const MarketingMetricsSchema = z.object({\n\tnumberOfItems: ZodValidation.number('Number of items in the marketing').optional(),\n\torderIncreaseWithDiscount: IncreaseDuringDiscountSchema.optional(),\n\tcustomerIncreaseWithDiscount: IncreaseDuringDiscountSchema.optional(),\n});\n\nexport const MarketingGraphInputSchema = z.object({\n\tmarketingId: ZodValidation.objectIdOrStringSchema,\n\tstartDate: ZodValidation.date('Start Date').transform(val => dayjs(val).startOf('day').toDate()),\n\tendDate: ZodValidation.date('End Date').transform(val => dayjs(val).endOf('day').toDate()),\n\ttype: ZodValidation.enumType(GraphType, 'Type').default(GraphType.DAILY),\n});\n\nexport const MarketingOrdersGraphOutputSchema = z.array(\n\tz.object({\n\t\tdate: ZodValidation.string('Date'),\n\t\torders: ZodValidation.number('Orders').default(0),\n\t})\n);\n\nexport const MarketingCustomersGraphOutputSchema = z.array(\n\tz.object({\n\t\tdate: ZodValidation.string('Date'),\n\t\tcustomers: ZodValidation.number('Customers').default(0),\n\t})\n);\n\nexport const MarketingAmountSpentGraphOutputSchema = z.array(\n\tz.object({\n\t\tdate: ZodValidation.string('Date'),\n\t\tamount: ZodValidation.number('Amount').default(0),\n\t})\n);\n\n/**\n * Export DTO types\n */\nexport type CreateMarketingDTO = DTO<typeof MarketingValidationSchema>;\nexport type MarketingDTO = DTO<typeof MarketingSchema>;\nexport type UpdateMarketingDTO = DTO<typeof UpdateMarketingSchema>;\nexport type ProductEntireMenuMarketingHandlerDTO = DTO<typeof ProductEntireMenuMarketingHandlerSchema>;\nexport type IncreaseDuringDiscountDTO = DTO<typeof IncreaseDuringDiscountSchema>;\nexport type MarketingMetricsDTO = DTO<typeof MarketingMetricsSchema>;\nexport type MarketingGraphInputDTO = DTO<typeof MarketingGraphInputSchema>;\nexport type MarketingOrdersGraphOutputDTO = DTO<typeof MarketingOrdersGraphOutputSchema>;\nexport type MarketingCustomersGraphOutputDTO = DTO<typeof MarketingCustomersGraphOutputSchema>;\nexport type MarketingAmountSpentGraphOutputDTO = DTO<typeof MarketingAmountSpentGraphOutputSchema>;"]}
|
package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"punch-marketing-history.service.d.ts","sourceRoot":"/","sources":["modules/punch-marketing-history/services/punch-marketing-history.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAmB,MAAM,sBAAsB,CAAC;AAC/E,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAElG,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAC3D,OAAO,EAEN,qBAAqB,IAAI,KAAK,EAK9B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACN,8BAA8B,IAAI,SAAS,EAC3C,mBAAmB,EACnB,8BAA8B,IAAI,SAAS,EAC3C,MAAM,8CAA8C,CAAC;AAWtD,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"punch-marketing-history.service.d.ts","sourceRoot":"/","sources":["modules/punch-marketing-history/services/punch-marketing-history.service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,QAA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,KAAK,CAAC,QAAQ,GAC9B,OAAO,CAAC,MAAM,CAAC;YA0DJ,gBAAgB;IA+CjB,yBAAyB,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ;IA0C3F,gBAAgB,CAAC,IAAI,EAAE,iBAAiB,GAAG,OAAO,CAAC,yBAAyB,CAAC;IA2D7E,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;CA4CvG;AAED,eAAO,MAAM,4BAA4B,8BAA8C,CAAC"}
|
package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js
CHANGED
|
@@ -53,6 +53,8 @@ const dayjs_1 = require("@lyxa.ai/core/dist/utilities/dayjs");
|
|
|
53
53
|
const currency_1 = require("@lyxa.ai/core/dist/utilities/currency");
|
|
54
54
|
const shared_1 = require("@lyxa.ai/core/dist/utilities/shared");
|
|
55
55
|
const core_1 = require("@lyxa.ai/core");
|
|
56
|
+
const events_common_methods_1 = require("@lyxa.ai/core/dist/utilities/events-common-methods");
|
|
57
|
+
const mongo_stream_changes_batch_process_shops_event_1 = require("@lyxa.ai/core/dist/libraries/event/events/mongo-stream-changes-batch-process-shops-event");
|
|
56
58
|
let PunchMarketingHistoryService = class PunchMarketingHistoryService {
|
|
57
59
|
model;
|
|
58
60
|
marketingModel;
|
|
@@ -158,7 +160,6 @@ let PunchMarketingHistoryService = class PunchMarketingHistoryService {
|
|
|
158
160
|
return 'Record deleted successfully';
|
|
159
161
|
}
|
|
160
162
|
async incrementUserHistory(userId, orderId) {
|
|
161
|
-
console.log('here we go');
|
|
162
163
|
const order = await this.orderModel.findById(orderId);
|
|
163
164
|
if (!order || order.user.toString != userId.toString) {
|
|
164
165
|
(0, error_common_1.notFoundError)('Order not found');
|
|
@@ -193,6 +194,11 @@ let PunchMarketingHistoryService = class PunchMarketingHistoryService {
|
|
|
193
194
|
else {
|
|
194
195
|
await this.createNewHistory(userId, order);
|
|
195
196
|
}
|
|
197
|
+
await (0, events_common_methods_1.publishSyncUserShopPunchMarketingHistoryWithPunchSectionCacheProcessEvent)({
|
|
198
|
+
userId,
|
|
199
|
+
shopId: order.shop._id,
|
|
200
|
+
operation: mongo_stream_changes_batch_process_shops_event_1.ChangeStreamOperationTypes.UPDATE,
|
|
201
|
+
});
|
|
196
202
|
return 'Record updated successfully';
|
|
197
203
|
}
|
|
198
204
|
async createNewHistory(userId, order) {
|
|
@@ -263,6 +269,11 @@ let PunchMarketingHistoryService = class PunchMarketingHistoryService {
|
|
|
263
269
|
marketings: punchHistory.marketing,
|
|
264
270
|
},
|
|
265
271
|
});
|
|
272
|
+
await (0, events_common_methods_1.publishSyncUserShopPunchMarketingHistoryWithPunchSectionCacheProcessEvent)({
|
|
273
|
+
userId,
|
|
274
|
+
shopId: order.shop._id,
|
|
275
|
+
operation: mongo_stream_changes_batch_process_shops_event_1.ChangeStreamOperationTypes.DELETE,
|
|
276
|
+
});
|
|
266
277
|
}
|
|
267
278
|
async getPunchDiscount(data) {
|
|
268
279
|
const punchHistory = await this.model.findOne({
|
|
@@ -276,6 +287,13 @@ let PunchMarketingHistoryService = class PunchMarketingHistoryService {
|
|
|
276
287
|
isValid: false,
|
|
277
288
|
};
|
|
278
289
|
}
|
|
290
|
+
if (data.scheduledAt &&
|
|
291
|
+
Boolean(punchHistory.couponExpiryDate) &&
|
|
292
|
+
(0, dayjs_1.dayjs)(punchHistory.couponExpiryDate).isBefore(data.scheduledAt)) {
|
|
293
|
+
return {
|
|
294
|
+
isValid: false,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
279
297
|
let discountAmount = punchHistory.couponValueType == enum_1.ValueType.FIXED
|
|
280
298
|
? punchHistory.couponValue
|
|
281
299
|
: (0, shared_1.roundBaseCurrency)((punchHistory.couponValue / 100) * data.amountBeforeCoupon);
|
package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"punch-marketing-history.service.js","sourceRoot":"/","sources":["modules/punch-marketing-history/services/punch-marketing-history.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4EAA0E;AAC1E,iDAA4C;AAC5C,yCAAyC;AAGzC,wEAA6G;AAE7G,sEAOmD;AAOnD,4DAM2C;AAC3C,8DAA2D;AAG3D,oEAA2E;AAC3E,gEAAgG;AAChG,wCAA6C;AAGtC,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAChC,KAAK,CAA6D;IAClE,cAAc,CAA+D;IAC7E,UAAU,CAA2D;IAE7E;QACC,IAAI,CAAC,KAAK,GAAG,mCAAwF,CAAC;QACtG,IAAI,CAAC,cAAc,GAAG,4BAAmF,CAAC;QAC1G,IAAI,CAAC,UAAU,GAAG,0BAA6E,CAAC;IACjG,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe;QAClC,OAAO,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAMM,KAAK,CAAC,QAAQ,CAAC,EAAoC;QACzD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;YACvC,GAAG,EAAE,EAAE;YACP,SAAS,EAAE,IAAI;SACf,CAAC,CAAC;QACH,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,kBAAkB;aAC3B,CAAC,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAMM,KAAK,CAAC,IAAI,CAAC,IAAyB;QAC1C,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,IAAA,6CAAgC,EAAC,IAAI,CAA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,GAAG,gBAAS,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC","sourcesContent":["import { notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\nimport Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport { FilterDTO, PaginatedResponse, DeleteDTO } 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 {\n\tPunchMarketingHistoryModel,\n\tPunchMarketingHistory as Model,\n\tPunchMarketingModel,\n\tPunchMarketing,\n\tRegularOrder,\n\tRegularOrderModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tCreatePunchMarketingHistoryDTO as CreateDTO,\n\tGetByUserAndShopDTO,\n\tUpdatePunchMarketingHistoryDTO as UpdateDTO,\n} from '@modules/punch-marketing-history/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport {\n\tCouponType,\n\tMarketingType,\n\tPunchMarketingStatus,\n\tStatus,\n\tValueType,\n} from '@lyxa.ai/core/dist/utilities/enum';\nimport { dayjs } from '@lyxa.ai/core/dist/utilities/dayjs';\nimport { PunchMarketingSchema, PunchMarketingValidationSchema } from '@modules/marketing/validations';\nimport { CouponValidationOutputDTO, ValidateCouponDTO } from '@modules/coupon/validations';\nimport { convertToSecondary } from '@lyxa.ai/core/dist/utilities/currency';\nimport { roundBaseCurrency, roundSecondaryCurrency } from '@lyxa.ai/core/dist/utilities/shared';\nimport { getLibraries } from '@lyxa.ai/core';\n\n@Service()\nexport class PunchMarketingHistoryService {\n\tprivate model: typeof PunchMarketingHistoryModel & SoftDeleteModel<Model>;\n\tprivate marketingModel: typeof PunchMarketingModel & SoftDeleteModel<PunchMarketing>;\n\tprivate orderModel: typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\n\tconstructor() {\n\t\tthis.model = PunchMarketingHistoryModel as typeof PunchMarketingHistoryModel & SoftDeleteModel<Model>;\n\t\tthis.marketingModel = PunchMarketingModel as typeof PunchMarketingModel & SoftDeleteModel<PunchMarketing>;\n\t\tthis.orderModel = RegularOrderModel as typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\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\treturn await this.model.create(data);\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 * Get Record\n\t * @param UserId ShopId to find records\n\t */\n\tpublic async getByUserAndShop(data: GetByUserAndShopDTO): Promise<any> {\n\t\tlet result = await this.model.findOne({\n\t\t\tuser: data.userId,\n\t\t\tshop: data.shopId,\n\t\t\texpiryDate: { $gt: new Date() },\n\t\t\tcompletedAt: null,\n\t\t\tstatus: PunchMarketingStatus.ACTIVE,\n\t\t});\n\n\t\tif (result) return result;\n\n\t\tconst marketing = await this.marketingModel.findOne({\n\t\t\tmarketingType: MarketingType.PUNCH_MARKETING,\n\t\t\tshop: data.shopId,\n\t\t\tstatus: Status.ACTIVE,\n\t\t\t'duration.start': { $lt: new Date() },\n\t\t\t'duration.end': { $gt: new Date() },\n\t\t});\n\n\t\tif (!marketing) notFoundError('No Punch Marketing is Active For This Shop...');\n\n\t\treturn {\n\t\t\tuser: data.userId,\n\t\t\tshop: data.shopId,\n\t\t\tmarketing: marketing!._id,\n\t\t\ttargetOrder: marketing.targetOrders,\n\t\t\tminimumOrderValue: marketing.minimumOrderValue,\n\t\t\tcompletedOrder: 0,\n\t\t\tcouponValueType: marketing.couponValueType,\n\t\t\tcouponValue: marketing.couponValue,\n\t\t\tcouponDurationInDays: marketing.couponDurationInDays,\n\t\t};\n\t}\n\n\t/**\n\t * Update record\n\t * @param id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(id: string, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst record = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: id,\n\t\t\t\tdeletedAt: null,\n\t\t\t},\n\t\t\tdata,\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\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 record;\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tconst result = await this.model.deleteRecord({ _id, deletedAt: null }, softDelete);\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\n\t\treturn 'Record deleted successfully';\n\t}\n\n\t/**\n\t * Increment punch history for user\n\t * @param userId User ID\n\t * @param orderId Order ID\n\t */\n\tpublic async incrementUserHistory(\n\t\tuserId: mongoose.Types.ObjectId,\n\t\torderId: mongoose.Types.ObjectId\n\t): Promise<string> {\n\t\tconsole.log('here we go');\n\t\tconst order = await this.orderModel.findById(orderId);\n\n\t\tif (!order || order.user.toString != userId.toString) {\n\t\t\tnotFoundError('Order not found');\n\t\t}\n\n\t\tconst existingHistory = await this.model.findOne({\n\t\t\tuser: userId,\n\t\t\tshop: order.shop,\n\t\t\texpiryDate: { $gt: new Date() },\n\t\t\tcompletedAt: null,\n\t\t\tstatus: PunchMarketingStatus.ACTIVE,\n\t\t});\n\n\t\tif (existingHistory) {\n\t\t\tif (order.finance.pricing.subtotal ?? 0 >= existingHistory.minimumOrderValue) {\n\t\t\t\tconst completedAt =\n\t\t\t\t\texistingHistory.targetOrder == existingHistory.completedOrder + 1 ? new Date() : null;\n\t\t\t\tconst couponExpiryDate = completedAt\n\t\t\t\t\t? dayjs(completedAt).add(existingHistory.couponDurationInDays, 'day').toDate()\n\t\t\t\t\t: null;\n\t\t\t\tconst status = completedAt ? PunchMarketingStatus.COMPLETED : PunchMarketingStatus.ACTIVE;\n\n\t\t\t\tawait this.model.findByIdAndUpdate(\n\t\t\t\t\texistingHistory._id,\n\t\t\t\t\t{\n\t\t\t\t\t\t$inc: {\n\t\t\t\t\t\t\tcompletedOrder: 1,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcompletedAt,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\tcouponExpiryDate,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tnew: true,\n\t\t\t\t\t\trunValidators: true,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tawait this.createNewHistory(userId, order);\n\t\t}\n\n\t\treturn 'Record updated successfully';\n\t}\n\n\t/**\n\t * Create new history with current punch marketing of the shop\n\t * @param userId User ID\n\t * @param order Order document\n\t */\n\tprivate async createNewHistory(userId: mongoose.Types.ObjectId, order: DocumentType<RegularOrder>) {\n\t\tconst marketing = await this.marketingModel.findOne({\n\t\t\tmarketingType: MarketingType.PUNCH_MARKETING,\n\t\t\tshop: order.shop,\n\t\t\tstatus: Status.ACTIVE,\n\t\t\t'duration.start': { $lt: new Date() },\n\t\t\t'duration.end': { $gt: new Date() },\n\t\t});\n\n\t\tif (!marketing) notFoundError('Marketing Not Found');\n\n\t\tconst expiryDate = dayjs().add(marketing.dayLimit, 'day').toDate();\n\t\tconst couponDurationInDays = marketing!.couponDurationInDays;\n\t\tconst couponValue = marketing!.couponValue;\n\t\tconst couponValueType = marketing!.couponValueType;\n\t\tconst targetOrder = marketing!.targetOrders;\n\t\tconst minimumOrderValue = marketing!.minimumOrderValue;\n\t\tconst completedOrder = 1;\n\t\tconst status =\n\t\t\tmarketing!.targetOrders == completedOrder\n\t\t\t\t? PunchMarketingStatus.COMPLETED\n\t\t\t\t: PunchMarketingStatus.ACTIVE;\n\t\tconst completedAt = marketing!.targetOrders == completedOrder ? new Date() : null;\n\t\tconst couponExpiryDate = completedAt\n\t\t\t? dayjs(completedAt).add(marketing!.couponDurationInDays, 'day').toDate()\n\t\t\t: null;\n\n\t\tif (order.finance.pricing.subtotal ?? 0 >= marketing.minimumOrderValue) {\n\t\t\tconst data: CreateDTO = {\n\t\t\t\tuser: userId as mongoose.Types.ObjectId,\n\t\t\t\tshop: order!.shop as mongoose.Types.ObjectId,\n\t\t\t\tmarketing: marketing!._id as mongoose.Types.ObjectId,\n\t\t\t\ttargetOrder,\n\t\t\t\tminimumOrderValue,\n\t\t\t\tcompletedOrder,\n\t\t\t\tstatus,\n\t\t\t\tcouponValueType,\n\t\t\t\tcouponValue,\n\t\t\t\tcouponDurationInDays,\n\t\t\t\texpiryDate,\n\t\t\t\t...(completedAt && { completedAt }),\n\t\t\t\t...(couponExpiryDate && { couponExpiryDate }),\n\t\t\t};\n\t\t\tawait this.create(data);\n\t\t}\n\t}\n\n\tpublic async applyPunchDiscountToOrder(userId: mongoose.Types.ObjectId, orderId: mongoose.Types.ObjectId) {\n\t\tconst order = await this.orderModel.findById(orderId);\n\t\tif (!order) notFoundError('Order not found');\n\n\t\tconst punchHistory = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\tuser: userId,\n\t\t\t\tshop: order.shop,\n\t\t\t\tcouponExpiryDate: { $gte: new Date() },\n\t\t\t\tstatus: PunchMarketingStatus.COMPLETED,\n\t\t\t},\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\torder: orderId,\n\t\t\t\t\tstatus: PunchMarketingStatus.COUPON_USED,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\n\t\t);\n\n\t\tif (!punchHistory) notFoundError('No valid punch coupon available');\n\n\t\tawait this.orderModel.findByIdAndUpdate(orderId, {\n\t\t\t$push: {\n\t\t\t\tmarketings: punchHistory.marketing,\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Get punch discount\n\t * @param data Data to use for validating discount\n\t */\n\tpublic async getPunchDiscount(data: ValidateCouponDTO): Promise<CouponValidationOutputDTO> {\n\t\tconst punchHistory = await this.model.findOne({\n\t\t\tuser: data.user,\n\t\t\tshop: data.shop,\n\t\t\tcouponExpiryDate: { $gte: new Date() },\n\t\t\tstatus: PunchMarketingStatus.COMPLETED,\n\t\t});\n\n\t\tif (!punchHistory) {\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t};\n\t\t}\n\n\t\tlet discountAmount =\n\t\t\tpunchHistory.couponValueType == ValueType.FIXED\n\t\t\t\t? punchHistory.couponValue\n\t\t\t\t: roundBaseCurrency((punchHistory.couponValue / 100) * data.amountBeforeCoupon);\n\n\t\tlet secondaryDiscountAmount =\n\t\t\tpunchHistory.couponValueType == ValueType.FIXED\n\t\t\t\t? await convertToSecondary(punchHistory.couponValue)\n\t\t\t\t: roundSecondaryCurrency((punchHistory.couponValue / 100) * data.secondaryAmountBeforeCoupon);\n\n\t\tif (discountAmount > data.amountBeforeCoupon) {\n\t\t\tdiscountAmount = data.amountBeforeCoupon;\n\t\t}\n\t\tif (secondaryDiscountAmount > data.secondaryAmountBeforeCoupon) {\n\t\t\tsecondaryDiscountAmount = data.secondaryAmountBeforeCoupon;\n\t\t}\n\n\t\treturn {\n\t\t\tisValid: true,\n\t\t\tdiscountAmount,\n\t\t\tsecondaryDiscountAmount,\n\t\t\tamountAfterCoupon: Math.max(0, roundBaseCurrency(data.amountBeforeCoupon - discountAmount)),\n\t\t\tsecondaryAmountAfterCoupon: Math.max(\n\t\t\t\t0,\n\t\t\t\troundSecondaryCurrency(data.secondaryAmountBeforeCoupon - secondaryDiscountAmount)\n\t\t\t),\n\t\t\tdiscountCut: {\n\t\t\t\tcompanyCut: 0,\n\t\t\t\tsecondaryCompanyCut: 0,\n\t\t\t\tshopCut: discountAmount,\n\t\t\t\tsecondaryShopCut: secondaryDiscountAmount,\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic async getPunchCoupon(user: mongoose.Types.ObjectId, shop: mongoose.Types.ObjectId): Promise<any> {\n\t\tconst punchHistory = await this.model.findOne({\n\t\t\tuser: user,\n\t\t\tshop: shop,\n\t\t\tcouponExpiryDate: { $gte: new Date() },\n\t\t\tstatus: PunchMarketingStatus.COMPLETED,\n\t\t});\n\t\tif (!punchHistory) return null;\n\n\t\tconst settings = await getLibraries().getCachedSettingsService().getSettings();\n\t\tconst exchangeRate = settings?.currencySetting?.exchangeRate ?? 0;\n\n\t\tconst punchCoupon = {\n\t\t\t_id: null,\n\t\t\tcode: 'punch',\n\t\t\tcouponType: CouponType.INDIVIDUAL_USER,\n\t\t\torderLimitPerUser: 1,\n\t\t\tcreatedBy: null,\n\t\t\tdeletedAt: null,\n\t\t\tvalueType: punchHistory.couponValueType,\n\t\t\tvalue: punchHistory.couponValue,\n\t\t\tmaxDiscountLimit: null,\n\t\t\tduration: {\n\t\t\t\tstart: punchHistory.completedAt,\n\t\t\t\tend: punchHistory.couponExpiryDate,\n\t\t\t},\n\t\t\tshops: [shop],\n\t\t\tspendLimit: null,\n\t\t\ttotalOrderLimit: 1,\n\t\t\tminOrderValue: null,\n\t\t\tforNewUserOnly: false,\n\t\t\tstatus: Status.ACTIVE,\n\t\t\texpirationReason: null,\n\t\t\tcreatedAt: punchHistory.completedAt,\n\t\t\tupdatedAt: punchHistory.completedAt,\n\t\t\tsecondaryCurrencyValue:\n\t\t\t\tpunchHistory.couponValueType === ValueType.FIXED\n\t\t\t\t\t? roundSecondaryCurrency(punchHistory.couponValue * exchangeRate)\n\t\t\t\t\t: null,\n\t\t\tsecondaryCurrencyMaxDiscountLimit: null,\n\t\t\tsecondaryCurrencyMinOrderValue: null,\n\t\t};\n\t\treturn punchCoupon;\n\t}\n}\n\nexport const punchMarketingHistoryService = Container.get(PunchMarketingHistoryService);\n"]}
|
|
1
|
+
{"version":3,"file":"punch-marketing-history.service.js","sourceRoot":"/","sources":["modules/punch-marketing-history/services/punch-marketing-history.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4EAA0E;AAC1E,iDAA4C;AAC5C,yCAAyC;AAGzC,wEAA6G;AAE7G,sEAOmD;AAOnD,4DAM2C;AAC3C,8DAA2D;AAG3D,oEAA2E;AAC3E,gEAAgG;AAChG,wCAA6C;AAC7C,8FAA+I;AAC/I,6JAAsI;AAG/H,IAAM,4BAA4B,GAAlC,MAAM,4BAA4B;IAChC,KAAK,CAA6D;IAClE,cAAc,CAA+D;IAC7E,UAAU,CAA2D;IAE7E;QACC,IAAI,CAAC,KAAK,G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AAC,CAAC","sourcesContent":["import { notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\nimport Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose, ReturnModelType } from '@typegoose/typegoose';\nimport { FilterDTO, PaginatedResponse, DeleteDTO } 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 {\n\tPunchMarketingHistoryModel,\n\tPunchMarketingHistory as Model,\n\tPunchMarketingModel,\n\tPunchMarketing,\n\tRegularOrder,\n\tRegularOrderModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tCreatePunchMarketingHistoryDTO as CreateDTO,\n\tGetByUserAndShopDTO,\n\tUpdatePunchMarketingHistoryDTO as UpdateDTO,\n} from '@modules/punch-marketing-history/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport {\n\tCouponType,\n\tMarketingType,\n\tPunchMarketingStatus,\n\tStatus,\n\tValueType,\n} from '@lyxa.ai/core/dist/utilities/enum';\nimport { dayjs } from '@lyxa.ai/core/dist/utilities/dayjs';\nimport { PunchMarketingSchema, PunchMarketingValidationSchema } from '@modules/marketing/validations';\nimport { CouponValidationOutputDTO, ValidateCouponDTO } from '@modules/coupon/validations';\nimport { convertToSecondary } from '@lyxa.ai/core/dist/utilities/currency';\nimport { roundBaseCurrency, roundSecondaryCurrency } from '@lyxa.ai/core/dist/utilities/shared';\nimport { getLibraries } from '@lyxa.ai/core';\nimport { publishSyncUserShopPunchMarketingHistoryWithPunchSectionCacheProcessEvent } from '@lyxa.ai/core/dist/utilities/events-common-methods';\nimport { ChangeStreamOperationTypes } from '@lyxa.ai/core/dist/libraries/event/events/mongo-stream-changes-batch-process-shops-event';\n\n@Service()\nexport class PunchMarketingHistoryService {\n\tprivate model: typeof PunchMarketingHistoryModel & SoftDeleteModel<Model>;\n\tprivate marketingModel: typeof PunchMarketingModel & SoftDeleteModel<PunchMarketing>;\n\tprivate orderModel: typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\n\n\tconstructor() {\n\t\tthis.model = PunchMarketingHistoryModel as typeof PunchMarketingHistoryModel & SoftDeleteModel<Model>;\n\t\tthis.marketingModel = PunchMarketingModel as typeof PunchMarketingModel & SoftDeleteModel<PunchMarketing>;\n\t\tthis.orderModel = RegularOrderModel as typeof RegularOrderModel & SoftDeleteModel<RegularOrder>;\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\treturn await this.model.create(data);\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 * Get Record\n\t * @param UserId ShopId to find records\n\t */\n\tpublic async getByUserAndShop(data: GetByUserAndShopDTO): Promise<any> {\n\t\tlet result = await this.model.findOne({\n\t\t\tuser: data.userId,\n\t\t\tshop: data.shopId,\n\t\t\texpiryDate: { $gt: new Date() },\n\t\t\tcompletedAt: null,\n\t\t\tstatus: PunchMarketingStatus.ACTIVE,\n\t\t});\n\n\t\tif (result) return result;\n\n\t\tconst marketing = await this.marketingModel.findOne({\n\t\t\tmarketingType: MarketingType.PUNCH_MARKETING,\n\t\t\tshop: data.shopId,\n\t\t\tstatus: Status.ACTIVE,\n\t\t\t'duration.start': { $lt: new Date() },\n\t\t\t'duration.end': { $gt: new Date() },\n\t\t});\n\n\t\tif (!marketing) notFoundError('No Punch Marketing is Active For This Shop...');\n\n\t\treturn {\n\t\t\tuser: data.userId,\n\t\t\tshop: data.shopId,\n\t\t\tmarketing: marketing!._id,\n\t\t\ttargetOrder: marketing.targetOrders,\n\t\t\tminimumOrderValue: marketing.minimumOrderValue,\n\t\t\tcompletedOrder: 0,\n\t\t\tcouponValueType: marketing.couponValueType,\n\t\t\tcouponValue: marketing.couponValue,\n\t\t\tcouponDurationInDays: marketing.couponDurationInDays,\n\t\t};\n\t}\n\n\t/**\n\t * Update record\n\t * @param id ID of the record\n\t * @param data Data to update\n\t */\n\tpublic async update(id: string, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst record = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\t_id: id,\n\t\t\t\tdeletedAt: null,\n\t\t\t},\n\t\t\tdata,\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\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 record;\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tconst result = await this.model.deleteRecord({ _id, deletedAt: null }, softDelete);\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\n\t\treturn 'Record deleted successfully';\n\t}\n\n\t/**\n\t * Increment punch history for user\n\t * @param userId User ID\n\t * @param orderId Order ID\n\t */\n\tpublic async incrementUserHistory(\n\t\tuserId: mongoose.Types.ObjectId,\n\t\torderId: mongoose.Types.ObjectId\n\t): Promise<string> {\n\t\tconst order = await this.orderModel.findById(orderId);\n\n\t\tif (!order || order.user.toString != userId.toString) {\n\t\t\tnotFoundError('Order not found');\n\t\t}\n\n\t\tconst existingHistory = await this.model.findOne({\n\t\t\tuser: userId,\n\t\t\tshop: order.shop,\n\t\t\texpiryDate: { $gt: new Date() },\n\t\t\tcompletedAt: null,\n\t\t\tstatus: PunchMarketingStatus.ACTIVE,\n\t\t});\n\n\t\tif (existingHistory) {\n\t\t\tif (order.finance.pricing.subtotal ?? 0 >= existingHistory.minimumOrderValue) {\n\t\t\t\tconst completedAt =\n\t\t\t\t\texistingHistory.targetOrder == existingHistory.completedOrder + 1 ? new Date() : null;\n\t\t\t\tconst couponExpiryDate = completedAt\n\t\t\t\t\t? dayjs(completedAt).add(existingHistory.couponDurationInDays, 'day').toDate()\n\t\t\t\t\t: null;\n\t\t\t\tconst status = completedAt ? PunchMarketingStatus.COMPLETED : PunchMarketingStatus.ACTIVE;\n\n\t\t\t\tawait this.model.findByIdAndUpdate(\n\t\t\t\t\texistingHistory._id,\n\t\t\t\t\t{\n\t\t\t\t\t\t$inc: {\n\t\t\t\t\t\t\tcompletedOrder: 1,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcompletedAt,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\tcouponExpiryDate,\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tnew: true,\n\t\t\t\t\t\trunValidators: true,\n\t\t\t\t\t}\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tawait this.createNewHistory(userId, order);\n\t\t}\n\n\t\tawait publishSyncUserShopPunchMarketingHistoryWithPunchSectionCacheProcessEvent({\n\t\t\tuserId,\n\t\t\tshopId: order.shop._id,\n\t\t\toperation: ChangeStreamOperationTypes.UPDATE,\n\t\t})\n\n\t\treturn 'Record updated successfully';\n\t}\n\n\t/**\n\t * Create new history with current punch marketing of the shop\n\t * @param userId User ID\n\t * @param order Order document\n\t */\n\tprivate async createNewHistory(userId: mongoose.Types.ObjectId, order: DocumentType<RegularOrder>) {\n\t\tconst marketing = await this.marketingModel.findOne({\n\t\t\tmarketingType: MarketingType.PUNCH_MARKETING,\n\t\t\tshop: order.shop,\n\t\t\tstatus: Status.ACTIVE,\n\t\t\t'duration.start': { $lt: new Date() },\n\t\t\t'duration.end': { $gt: new Date() },\n\t\t});\n\n\t\tif (!marketing) notFoundError('Marketing Not Found');\n\n\t\tconst expiryDate = dayjs().add(marketing.dayLimit, 'day').toDate();\n\t\tconst couponDurationInDays = marketing!.couponDurationInDays;\n\t\tconst couponValue = marketing!.couponValue;\n\t\tconst couponValueType = marketing!.couponValueType;\n\t\tconst targetOrder = marketing!.targetOrders;\n\t\tconst minimumOrderValue = marketing!.minimumOrderValue;\n\t\tconst completedOrder = 1;\n\t\tconst status =\n\t\t\tmarketing!.targetOrders == completedOrder\n\t\t\t\t? PunchMarketingStatus.COMPLETED\n\t\t\t\t: PunchMarketingStatus.ACTIVE;\n\t\tconst completedAt = marketing!.targetOrders == completedOrder ? new Date() : null;\n\t\tconst couponExpiryDate = completedAt\n\t\t\t? dayjs(completedAt).add(marketing!.couponDurationInDays, 'day').toDate()\n\t\t\t: null;\n\n\t\tif (order.finance.pricing.subtotal ?? 0 >= marketing.minimumOrderValue) {\n\t\t\tconst data: CreateDTO = {\n\t\t\t\tuser: userId as mongoose.Types.ObjectId,\n\t\t\t\tshop: order!.shop as mongoose.Types.ObjectId,\n\t\t\t\tmarketing: marketing!._id as mongoose.Types.ObjectId,\n\t\t\t\ttargetOrder,\n\t\t\t\tminimumOrderValue,\n\t\t\t\tcompletedOrder,\n\t\t\t\tstatus,\n\t\t\t\tcouponValueType,\n\t\t\t\tcouponValue,\n\t\t\t\tcouponDurationInDays,\n\t\t\t\texpiryDate,\n\t\t\t\t...(completedAt && { completedAt }),\n\t\t\t\t...(couponExpiryDate && { couponExpiryDate }),\n\t\t\t};\n\t\t\tawait this.create(data);\n\t\t}\n\t}\n\n\tpublic async applyPunchDiscountToOrder(userId: mongoose.Types.ObjectId, orderId: mongoose.Types.ObjectId) {\n\t\tconst order = await this.orderModel.findById(orderId);\n\t\tif (!order) notFoundError('Order not found');\n\n\t\tconst punchHistory = await this.model.findOneAndUpdate(\n\t\t\t{\n\t\t\t\tuser: userId,\n\t\t\t\tshop: order.shop,\n\t\t\t\tcouponExpiryDate: { $gte: new Date() },\n\t\t\t\tstatus: PunchMarketingStatus.COMPLETED,\n\t\t\t},\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\torder: orderId,\n\t\t\t\t\tstatus: PunchMarketingStatus.COUPON_USED,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tnew: true,\n\t\t\t\trunValidators: true,\n\t\t\t}\n\t\t);\n\n\t\tif (!punchHistory) notFoundError('No valid punch coupon available');\n\n\t\tawait this.orderModel.findByIdAndUpdate(orderId, {\n\t\t\t$push: {\n\t\t\t\tmarketings: punchHistory.marketing,\n\t\t\t},\n\t\t});\n\t\t\n\t\tawait publishSyncUserShopPunchMarketingHistoryWithPunchSectionCacheProcessEvent({\n\t\t\tuserId,\n\t\t\tshopId: order.shop._id,\n\t\t\toperation: ChangeStreamOperationTypes.DELETE,\n\t\t})\n\t}\n\n\t/**\n\t * Get punch discount\n\t * @param data Data to use for validating discount\n\t */\n\tpublic async getPunchDiscount(data: ValidateCouponDTO): Promise<CouponValidationOutputDTO> {\n\t\tconst punchHistory = await this.model.findOne({\n\t\t\tuser: data.user,\n\t\t\tshop: data.shop,\n\t\t\tcouponExpiryDate: { $gte: new Date() },\n\t\t\tstatus: PunchMarketingStatus.COMPLETED,\n\t\t});\n\n\t\tif (!punchHistory) {\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t};\n\t\t}\n\n\t\tif (\n\t\t\tdata.scheduledAt &&\n\t\t\tBoolean(punchHistory.couponExpiryDate) &&\n\t\t\tdayjs(punchHistory.couponExpiryDate).isBefore(data.scheduledAt)\n\t\t) {\n\t\t\treturn {\n\t\t\t\tisValid: false,\n\t\t\t};\n\t\t}\n\n\t\tlet discountAmount =\n\t\t\tpunchHistory.couponValueType == ValueType.FIXED\n\t\t\t\t? punchHistory.couponValue\n\t\t\t\t: roundBaseCurrency((punchHistory.couponValue / 100) * data.amountBeforeCoupon);\n\n\t\tlet secondaryDiscountAmount =\n\t\t\tpunchHistory.couponValueType == ValueType.FIXED\n\t\t\t\t? await convertToSecondary(punchHistory.couponValue)\n\t\t\t\t: roundSecondaryCurrency((punchHistory.couponValue / 100) * data.secondaryAmountBeforeCoupon);\n\n\t\tif (discountAmount > data.amountBeforeCoupon) {\n\t\t\tdiscountAmount = data.amountBeforeCoupon;\n\t\t}\n\t\tif (secondaryDiscountAmount > data.secondaryAmountBeforeCoupon) {\n\t\t\tsecondaryDiscountAmount = data.secondaryAmountBeforeCoupon;\n\t\t}\n\n\t\treturn {\n\t\t\tisValid: true,\n\t\t\tdiscountAmount,\n\t\t\tsecondaryDiscountAmount,\n\t\t\tamountAfterCoupon: Math.max(0, roundBaseCurrency(data.amountBeforeCoupon - discountAmount)),\n\t\t\tsecondaryAmountAfterCoupon: Math.max(\n\t\t\t\t0,\n\t\t\t\troundSecondaryCurrency(data.secondaryAmountBeforeCoupon - secondaryDiscountAmount)\n\t\t\t),\n\t\t\tdiscountCut: {\n\t\t\t\tcompanyCut: 0,\n\t\t\t\tsecondaryCompanyCut: 0,\n\t\t\t\tshopCut: discountAmount,\n\t\t\t\tsecondaryShopCut: secondaryDiscountAmount,\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic async getPunchCoupon(user: mongoose.Types.ObjectId, shop: mongoose.Types.ObjectId): Promise<any> {\n\t\tconst punchHistory = await this.model.findOne({\n\t\t\tuser: user,\n\t\t\tshop: shop,\n\t\t\tcouponExpiryDate: { $gte: new Date() },\n\t\t\tstatus: PunchMarketingStatus.COMPLETED,\n\t\t});\n\t\tif (!punchHistory) return null;\n\n\t\tconst settings = await getLibraries().getCachedSettingsService().getSettings();\n\t\tconst exchangeRate = settings?.currencySetting?.exchangeRate ?? 0;\n\n\t\tconst punchCoupon = {\n\t\t\t_id: null,\n\t\t\tcode: 'punch',\n\t\t\tcouponType: CouponType.INDIVIDUAL_USER,\n\t\t\torderLimitPerUser: 1,\n\t\t\tcreatedBy: null,\n\t\t\tdeletedAt: null,\n\t\t\tvalueType: punchHistory.couponValueType,\n\t\t\tvalue: punchHistory.couponValue,\n\t\t\tmaxDiscountLimit: null,\n\t\t\tduration: {\n\t\t\t\tstart: punchHistory.completedAt,\n\t\t\t\tend: punchHistory.couponExpiryDate,\n\t\t\t},\n\t\t\tshops: [shop],\n\t\t\tspendLimit: null,\n\t\t\ttotalOrderLimit: 1,\n\t\t\tminOrderValue: null,\n\t\t\tforNewUserOnly: false,\n\t\t\tstatus: Status.ACTIVE,\n\t\t\texpirationReason: null,\n\t\t\tcreatedAt: punchHistory.completedAt,\n\t\t\tupdatedAt: punchHistory.completedAt,\n\t\t\tsecondaryCurrencyValue:\n\t\t\t\tpunchHistory.couponValueType === ValueType.FIXED\n\t\t\t\t\t? roundSecondaryCurrency(punchHistory.couponValue * exchangeRate)\n\t\t\t\t\t: null,\n\t\t\tsecondaryCurrencyMaxDiscountLimit: null,\n\t\t\tsecondaryCurrencyMinOrderValue: null,\n\t\t};\n\t\treturn punchCoupon;\n\t}\n}\n\nexport const punchMarketingHistoryService = Container.get(PunchMarketingHistoryService);\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { GraphType } from '@lyxa.ai/core/dist/utilities/enum';
|
|
2
|
+
export declare function fillMissingPeriods<T extends Record<string, any>>(results: T[], startDate: Date, endDate: Date, type: GraphType, defaultFields: Omit<T, 'date'>): T[];
|
|
3
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"/","sources":["utility/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAc9D,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5D,OAAO,EAAE,CAAC,EAAE,EACZ,SAAS,EAAE,IAAI,EACf,OAAO,EAAE,IAAI,EACb,IAAI,EAAE,SAAS,EACf,aAAa,EAAE,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,GAC/B,CAAC,EAAE,CAqCL"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fillMissingPeriods = fillMissingPeriods;
|
|
4
|
+
const dayjs_1 = require("@lyxa.ai/core/dist/utilities/dayjs");
|
|
5
|
+
const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
6
|
+
function fillMissingPeriods(results, startDate, endDate, type, defaultFields) {
|
|
7
|
+
const filledData = [];
|
|
8
|
+
const resultMap = new Map();
|
|
9
|
+
for (const item of results) {
|
|
10
|
+
resultMap.set(item.date, item);
|
|
11
|
+
}
|
|
12
|
+
const fieldKeys = Object.keys(defaultFields);
|
|
13
|
+
const unit = type === enum_1.GraphType.MONTHLY ? 'month' : 'day';
|
|
14
|
+
const dateFormat = type === enum_1.GraphType.MONTHLY ? 'YYYY-MM' : 'YYYY-MM-DD';
|
|
15
|
+
let current = (0, dayjs_1.dayjs)(startDate).startOf(unit);
|
|
16
|
+
const end = (0, dayjs_1.dayjs)(endDate).startOf(unit);
|
|
17
|
+
while (current.isBefore(end) || current.isSame(end)) {
|
|
18
|
+
const dateKey = current.format(dateFormat);
|
|
19
|
+
const existing = resultMap.get(dateKey);
|
|
20
|
+
const entry = {
|
|
21
|
+
date: dateKey,
|
|
22
|
+
...(existing
|
|
23
|
+
? Object.fromEntries(fieldKeys.map(key => [key, existing[key] ?? defaultFields[key]]))
|
|
24
|
+
: { ...defaultFields }),
|
|
25
|
+
};
|
|
26
|
+
filledData.push(entry);
|
|
27
|
+
current = current.add(1, unit);
|
|
28
|
+
}
|
|
29
|
+
return filledData;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"/","sources":["utility/utils.ts"],"names":[],"mappings":";;AAeA,gDA2CC;AA1DD,8DAA2D;AAC3D,4DAA8D;AAc9D,SAAgB,kBAAkB,CAC9B,OAAY,EACZ,SAAe,EACf,OAAa,EACb,IAAe,EACf,aAA8B;IAE9B,MAAM,UAAU,GAAQ,EAAE,CAAC;IAC3B,MAAM,SAAS,GAAG,IAAI,GAAG,EAAa,CAAC;IAGvC,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QACzB,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAGD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,aAAa,CAAmC,CAAC;IAG/E,MAAM,IAAI,GAAG,IAAI,KAAK,gBAAS,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;IAC1D,MAAM,UAAU,GAAG,IAAI,KAAK,gBAAS,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC;IAEzE,IAAI,OAAO,GAAG,IAAA,aAAK,EAAC,SAAS,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7C,MAAM,GAAG,GAAG,IAAA,aAAK,EAAC,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAGzC,OAAO,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;QAClD,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAC3C,MAAM,QAAQ,GAAG,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAGxC,MAAM,KAAK,GAAG;YACV,IAAI,EAAE,OAAO;YACb,GAAG,CAAC,QAAQ;gBACR,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBACtF,CAAC,CAAC,EAAE,GAAG,aAAa,EAAE,CAAC;SACd,CAAC;QAElB,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACvB,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC;IAED,OAAO,UAAU,CAAC;AACtB,CAAC","sourcesContent":["import { dayjs } from '@lyxa.ai/core/dist/utilities/dayjs';\nimport { GraphType } from '@lyxa.ai/core/dist/utilities/enum';\n\n/**\n * Fills in missing periods (daily or monthly) between two dates in a time-series dataset,\n * assigning default values for fields when data is missing.\n *\n * @template T - The shape of the result item, must include a `date` field.\n * @param results - Original array of time-series data with `date` keys.\n * @param startDate - The start date of the period to cover.\n * @param endDate - The end date of the period to cover.\n * @param type - Graph type (e.g., daily or monthly).\n * @param defaultFields - Default values to assign when a date is missing.\n * @returns A new array with missing dates filled in and populated with default values.\n */\nexport function fillMissingPeriods<T extends Record<string, any>>(\n results: T[],\n startDate: Date,\n endDate: Date,\n type: GraphType,\n defaultFields: Omit<T, 'date'>\n): T[] {\n const filledData: T[] = [];\n const resultMap = new Map<string, T>();\n\n // Index results by date string for quick lookup\n for (const item of results) {\n resultMap.set(item.date, item);\n }\n\n // Extract the field keys from defaultFields for dynamic value assignment\n const fieldKeys = Object.keys(defaultFields) as (keyof typeof defaultFields)[];\n\n // Determine the unit and format based on the graph type\n const unit = type === GraphType.MONTHLY ? 'month' : 'day';\n const dateFormat = type === GraphType.MONTHLY ? 'YYYY-MM' : 'YYYY-MM-DD';\n\n let current = dayjs(startDate).startOf(unit);\n const end = dayjs(endDate).startOf(unit);\n\n // Iterate through each period (day or month) and build the result\n while (current.isBefore(end) || current.isSame(end)) {\n const dateKey = current.format(dateFormat);\n const existing = resultMap.get(dateKey);\n\n // Construct the data entry using existing values or defaults\n const entry = {\n date: dateKey,\n ...(existing\n ? Object.fromEntries(fieldKeys.map(key => [key, existing[key] ?? defaultFields[key]]))\n : { ...defaultFields }),\n } as unknown as T;\n\n filledData.push(entry);\n current = current.add(1, unit);\n }\n\n return filledData;\n}"]}
|