@lyxa.ai/marketing 1.0.28 → 1.0.30
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 +642 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts +642 -0
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.js +10 -0
- package/dist/lib/modules/coupon/routers/coupon.router.js.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.d.ts +4 -3
- package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.js +77 -50
- package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/custom-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/custom-coupon.service.js +6 -0
- package/dist/lib/modules/coupon/services/custom-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/global-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/global-coupon.service.js +8 -1
- package/dist/lib/modules/coupon/services/global-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/helper.service.d.ts +12 -0
- package/dist/lib/modules/coupon/services/helper.service.d.ts.map +1 -0
- package/dist/lib/modules/coupon/services/helper.service.js +147 -0
- package/dist/lib/modules/coupon/services/helper.service.js.map +1 -0
- 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 +9 -0
- package/dist/lib/modules/coupon/services/individual-store-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/individual-user-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/individual-user-coupon.service.js +8 -1
- package/dist/lib/modules/coupon/services/individual-user-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.d.ts +6 -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 +102 -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 +0 -1
- 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 +16 -14
- package/dist/lib/modules/coupon/services/referral-code-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.d.ts +2 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js +23 -20
- package/dist/lib/modules/coupon/services/referral-reward-coupon.service.js.map +1 -1
- 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 +11 -1
- package/dist/lib/modules/coupon/services/shops-categories-coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/validations/all-coupons.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/all-coupons.validation.js.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts +21 -0
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.js +11 -8
- package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
- package/dist/lib/modules/deal-setting/routers/deal-setting.router.d.ts.map +1 -1
- package/dist/lib/modules/deal-setting/services/deal-setting.service.d.ts +2 -0
- 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 +32 -8
- package/dist/lib/modules/deal-setting/services/deal-setting.service.js.map +1 -1
- package/dist/lib/modules/featured-setting/routers/featured-setting.router.d.ts.map +1 -1
- package/dist/lib/modules/featured-setting/services/featured-setting.service.d.ts +2 -0
- package/dist/lib/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
- package/dist/lib/modules/featured-setting/services/featured-setting.service.js +54 -8
- package/dist/lib/modules/featured-setting/services/featured-setting.service.js.map +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/lib/modules/marketing/routers/marketing.router.js +5 -8
- package/dist/lib/modules/marketing/routers/marketing.router.js.map +1 -1
- package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.js +22 -6
- package/dist/lib/modules/marketing/services/buy1-get1-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/discount-marketing.service.js +22 -6
- package/dist/lib/modules/marketing/services/discount-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.d.ts +1 -0
- package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.js +31 -4
- package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/validations/featured-marketing.validation.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/featured-marketing.validation.js +12 -13
- package/dist/lib/modules/marketing/validations/featured-marketing.validation.js.map +1 -1
- package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.d.ts.map +1 -1
- package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.js +8 -6
- package/dist/lib/modules/marketing/validations/free-delivery-marketing.validation.js.map +1 -1
- package/dist/lib/modules/marketing/validations/punch-marketing.validation.js +3 -6
- package/dist/lib/modules/marketing/validations/punch-marketing.validation.js.map +1 -1
- package/dist/lib/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts.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 +12 -9
- package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js.map +1 -1
- package/dist/types/index.d.ts +642 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/coupon/routers/coupon.router.d.ts +642 -0
- package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/coupon.service.d.ts +4 -3
- package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/custom-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/global-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/helper.service.d.ts +12 -0
- package/dist/types/modules/coupon/services/helper.service.d.ts.map +1 -0
- package/dist/types/modules/coupon/services/individual-store-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/individual-user-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/patterns/repository/CouponRepository.d.ts +6 -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 +0 -1
- package/dist/types/modules/coupon/services/referral-code-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/referral-reward-coupon.service.d.ts +2 -1
- package/dist/types/modules/coupon/services/referral-reward-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/shops-categories-coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/all-coupons.validation.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts +21 -0
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/deal-setting/routers/deal-setting.router.d.ts.map +1 -1
- package/dist/types/modules/deal-setting/services/deal-setting.service.d.ts +2 -0
- package/dist/types/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
- package/dist/types/modules/featured-setting/routers/featured-setting.router.d.ts.map +1 -1
- package/dist/types/modules/featured-setting/services/featured-setting.service.d.ts +2 -0
- package/dist/types/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/routers/marketing.router.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/buy1-get1-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/discount-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/marketing.service.d.ts +1 -0
- package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/featured-marketing.validation.d.ts.map +1 -1
- package/dist/types/modules/marketing/validations/free-delivery-marketing.validation.d.ts.map +1 -1
- package/dist/types/modules/punch-marketing-history/routers/punch-marketing-history.router.d.ts.map +1 -1
- package/dist/types/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -54,16 +54,17 @@ const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
|
54
54
|
const error_common_1 = require("@lyxa.ai/core/dist/utilities/error-common");
|
|
55
55
|
let DealSettingService = class DealSettingService {
|
|
56
56
|
model;
|
|
57
|
+
ITEM_TYPES = [
|
|
58
|
+
enum_1.ItemType.FOOD,
|
|
59
|
+
enum_1.ItemType.GROCERY,
|
|
60
|
+
enum_1.ItemType.COFFEE,
|
|
61
|
+
enum_1.ItemType.FLOWER,
|
|
62
|
+
enum_1.ItemType.PET,
|
|
63
|
+
];
|
|
57
64
|
constructor() {
|
|
58
65
|
this.model = models_1.DealSettingModel;
|
|
59
66
|
}
|
|
60
67
|
async create(data, admin) {
|
|
61
|
-
if (!admin) {
|
|
62
|
-
throw new server_1.TRPCError({
|
|
63
|
-
code: 'NOT_FOUND',
|
|
64
|
-
message: 'Admin not found',
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
68
|
const exists = await this.model.exists({
|
|
68
69
|
itemType: data.itemType,
|
|
69
70
|
});
|
|
@@ -74,7 +75,9 @@ let DealSettingService = class DealSettingService {
|
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
77
|
const result = await this.model.create(data);
|
|
77
|
-
|
|
78
|
+
if (admin) {
|
|
79
|
+
this.logMarketingSettingAdminAction(new typegoose_1.mongoose.Types.ObjectId(admin), enum_1.AdminLogsUpdatedFieldsType.CREATED_MARKETING_SETTINGS, '', result);
|
|
80
|
+
}
|
|
78
81
|
return result;
|
|
79
82
|
}
|
|
80
83
|
async findById(id) {
|
|
@@ -101,7 +104,11 @@ let DealSettingService = class DealSettingService {
|
|
|
101
104
|
select: data?.select,
|
|
102
105
|
populate: data?.populate,
|
|
103
106
|
};
|
|
104
|
-
|
|
107
|
+
let paginatedResult = await paginate(options);
|
|
108
|
+
if (!data?.query && paginatedResult.metadata.totalElements < this.ITEM_TYPES.length) {
|
|
109
|
+
await this.createDefaultDealSettings(paginatedResult.documents);
|
|
110
|
+
paginatedResult = await paginate(options);
|
|
111
|
+
}
|
|
105
112
|
return paginatedResult;
|
|
106
113
|
}
|
|
107
114
|
catch (err) {
|
|
@@ -111,6 +118,23 @@ let DealSettingService = class DealSettingService {
|
|
|
111
118
|
});
|
|
112
119
|
}
|
|
113
120
|
}
|
|
121
|
+
async createDefaultDealSettings(documents) {
|
|
122
|
+
const existingItemTypes = documents.map(deal => deal.itemType);
|
|
123
|
+
const newItemTypes = this.ITEM_TYPES.filter(item => !existingItemTypes.includes(item));
|
|
124
|
+
const defaultSetting = {
|
|
125
|
+
percentageBundles: [],
|
|
126
|
+
isDiscount: false,
|
|
127
|
+
isBuy1Get1: false,
|
|
128
|
+
isFreeDelivery: false,
|
|
129
|
+
isPunchMarketing: false,
|
|
130
|
+
};
|
|
131
|
+
for (const item of newItemTypes) {
|
|
132
|
+
await this.create({
|
|
133
|
+
...defaultSetting,
|
|
134
|
+
itemType: item,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
114
138
|
async update(id, data, admin) {
|
|
115
139
|
if (!admin)
|
|
116
140
|
(0, error_common_1.notFoundError)('Admin not found');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deal-setting.service.js","sourceRoot":"/","sources":["modules/deal-setting/services/deal-setting.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AACzC,oDAA+E;AAE/E,wEAA6G;AAE7G,sEAAmG;AAOnG,8DAAkE;AAElE,iGAAoG;AACpG,4DAA+E;AAC/E,4EAA2F;AAGpF,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IACtB,KAAK,CAAmD;IAEhE;QACC,IAAI,CAAC,KAAK,GAAG,yBAAoE,CAAC;IACnF,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe,EAAE,KAAc;QAClD,IAAI,CAAC,KAAK,EAAE,CAAC;YACZ,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,WAAW;gBACjB,OAAO,EAAE,iBAAiB;aAC1B,CAAC,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;YACtC,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACvB,CAAC,CAAC;QACH,IAAI,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,UAAU;gBAChB,OAAO,EAAE,8BAA8B,IAAI,CAAC,QAAQ,uDAAuD;aAC3G,CAAC,CAAC;QACJ,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAE7C,IAAI,CAAC,8BAA8B,CAClC,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAClC,iCAA0B,CAAC,0BAA0B,EACrD,EAAE,EACF,MAAM,CACN,CAAC;QAEF,OAAO,MAAM,CAAC;IACf,CAAC;IAMM,KAAK,CAAC,QAAQ,CAAC,EA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'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 { DealSettingModel, DealSetting as Model } from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tCreateDealSettingDTO as CreateDTO,\n\tUpdateDealSettingDTO as UpdateDTO,\n\tDealSettingArrayDTO as UpdateAllDTO\n} from '@modules/deal-setting/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport { BaseEvent } from '@lyxa.ai/core/dist/libraries/event/BaseEvent';\nimport { AdminActivityLogsEvent } from '@lyxa.ai/core/dist/libraries/event/events/admin-logs-event';\nimport { AdminLogsUpdatedFieldsType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { badRequestError, notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class DealSettingService {\n\tprivate model: typeof DealSettingModel & SoftDeleteModel<Model>;\n\n\tconstructor() {\n\t\tthis.model = DealSettingModel as typeof DealSettingModel & SoftDeleteModel<Model>;\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, admin?: string): Promise<DocumentType<Model>> {\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Admin not found',\n\t\t\t});\n\t\t}\n\n\t\tconst exists = await this.model.exists({\n\t\t\titemType: data.itemType,\n\t\t});\n\t\tif (exists) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'CONFLICT',\n\t\t\t\tmessage: `Deal settings for itemType ${data.itemType} already exists. Please update the existing settings.`,\n\t\t\t});\n\t\t}\n\t\tconst result = await this.model.create(data);\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.CREATED_MARKETING_SETTINGS,\n\t\t\t'',\n\t\t\tresult\n\t\t);\n\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 record\n\t * @param id ID of the record\n\t * @param data Data to update\n\t * @param admin Admin id\n\t */\n\tpublic async update(id: string, data: UpdateDTO, admin?: string): Promise<DocumentType<Model>> {\n\t\tif (!admin) notFoundError('Admin not found');\n\n\t\tconst record = await this.model.findById(id);\n\t\tif (!record) notFoundError('Record not found');\n\n\t\tconst result = await this.model.findByIdAndUpdate(id, data, {\n\t\t\tnew: true,\n\t\t\trunValidators: true,\n\t\t});\n\n\t\tif (!result) notFoundError('Record not found');\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.CHANGE_IN_MARKETING_SETTINGS,\n\t\t\trecord,\n\t\t\tresult\n\t\t);\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Update all records\n\t * @param data Data to update\n\t * @param admin Admin id\n\t */\n\tpublic async updateAll(data: UpdateAllDTO[], admin?: string): Promise<DocumentType<Model>[]> {\n\t\t// Check admin existence\n\t\tif (!admin) notFoundError('Admin not found');\n\n\t\tconst results: DocumentType<Model>[] = [];\n\n\t\tfor (const dealSetting of data) {\n\t\t\tconst { _id, ...rest } = dealSetting as UpdateAllDTO & { _id: string | mongoose.Types.ObjectId };\n\n\t\t\tif (!_id) continue;\n\n\t\t\tconst updated = await this.update(String(_id), rest as UpdateAllDTO, admin);\n\t\t\tresults.push(updated);\n\t\t}\n\n\t\treturn results;\n\t}\n\n\tprivate async logMarketingSettingAdminAction(\n\t\tadmin: mongoose.Types.ObjectId,\n\t\tactionType: AdminLogsUpdatedFieldsType,\n\t\toldDocument?: any,\n\t\tnewDocument?: any\n\t) {\n\t\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\t\tadmin,\n\t\t\tupdatedField: actionType,\n\t\t\toldDocument: oldDocument ?? '',\n\t\t\tnewDocument: newDocument ?? '',\n\t\t});\n\t\tawait publishEvent(adminActivityLogsEvent);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO, admin?: string): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Admin not found',\n\t\t\t});\n\t\t}\n\n\t\tconst record = await this.model.findById(_id);\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\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: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Unable to delete record',\n\t\t\t});\n\t\t}\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.DELETED_MARKETING_SETTINGS,\n\t\t\trecord,\n\t\t\tresult\n\t\t);\n\n\t\treturn 'Record deleted successfully';\n\t}\n}\n\nexport const dealSettingService = Container.get(DealSettingService);\n"]}
|
|
1
|
+
{"version":3,"file":"deal-setting.service.js","sourceRoot":"/","sources":["modules/deal-setting/services/deal-setting.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AACzC,oDAA+E;AAE/E,wEAA6G;AAE7G,sEAAmG;AAOnG,8DAAkE;AAElE,iGAAoG;AACpG,4DAAyF;AACzF,4EAA2F;AAGpF,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IACtB,KAAK,CAAmD;IACxD,UAAU,GAAG;QACpB,eAAQ,CAAC,IAAI;QACb,eAAQ,CAAC,OAAO;QAChB,eAAQ,CAAC,MAAM;QACf,eAAQ,CAAC,MAAM;QACf,eAAQ,CAAC,GAAG;KAGZ,CAAC;IAEF;QACC,IAAI,CAAC,KAAK,GAAG,yBAAoE,CAAC;IACnF,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe,EAAE,KAAc;QAClD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAA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ACN,CAAC;QAEF,OAAO,6BAA6B,CAAC;IACtC,CAAC;CACD,CAAA;AA3NY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,gBAAO,GAAE;;GACG,kBAAkB,CA2N9B;AAEY,QAAA,kBAAkB,GAAG,gBAAS,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC","sourcesContent":["import 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 { DealSettingModel, DealSetting as Model } from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {\n\tCreateDealSettingDTO as CreateDTO,\n\tUpdateDealSettingDTO as UpdateDTO,\n\tDealSettingArrayDTO as UpdateAllDTO,\n} from '@modules/deal-setting/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport { BaseEvent } from '@lyxa.ai/core/dist/libraries/event/BaseEvent';\nimport { AdminActivityLogsEvent } from '@lyxa.ai/core/dist/libraries/event/events/admin-logs-event';\nimport { AdminLogsUpdatedFieldsType, ItemType } from '@lyxa.ai/core/dist/utilities/enum';\nimport { badRequestError, notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class DealSettingService {\n\tprivate model: typeof DealSettingModel & SoftDeleteModel<Model>;\n\tprivate ITEM_TYPES = [\n\t\tItemType.FOOD,\n\t\tItemType.GROCERY,\n\t\tItemType.COFFEE,\n\t\tItemType.FLOWER,\n\t\tItemType.PET,\n\t\t// ItemType.PHARMACY,\n\t\t// ItemType.HEALTHY_CORNER,\n\t];\n\n\tconstructor() {\n\t\tthis.model = DealSettingModel as typeof DealSettingModel & SoftDeleteModel<Model>;\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, admin?: string): Promise<DocumentType<Model>> {\n\t\tconst exists = await this.model.exists({\n\t\t\titemType: data.itemType,\n\t\t});\n\t\tif (exists) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'CONFLICT',\n\t\t\t\tmessage: `Deal settings for itemType ${data.itemType} already exists. Please update the existing settings.`,\n\t\t\t});\n\t\t}\n\t\tconst result = await this.model.create(data);\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingSettingAdminAction(\n\t\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\t\tAdminLogsUpdatedFieldsType.CREATED_MARKETING_SETTINGS,\n\t\t\t\t'',\n\t\t\t\tresult\n\t\t\t);\n\t\t}\n\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\tlet paginatedResult = await paginate(options);\n\n\t\t\tif (!data?.query && paginatedResult.metadata.totalElements < this.ITEM_TYPES.length) {\n\t\t\t\tawait this.createDefaultDealSettings(paginatedResult.documents as unknown as DocumentType<Model>[]);\n\t\t\t\tpaginatedResult = await paginate(options);\n\t\t\t}\n\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\tprivate async createDefaultDealSettings(documents: DocumentType<Model>[]): Promise<void> {\n\t\tconst existingItemTypes = documents.map(deal => deal.itemType);\n\t\tconst newItemTypes = this.ITEM_TYPES.filter(item => !existingItemTypes.includes(item));\n\t\tconst defaultSetting = {\n\t\t\tpercentageBundles: [],\n\t\t\tisDiscount: false,\n\t\t\tisBuy1Get1: false,\n\t\t\tisFreeDelivery: false,\n\t\t\tisPunchMarketing: false,\n\t\t};\n\n\t\tfor (const item of newItemTypes) {\n\t\t\tawait this.create({\n\t\t\t\t...defaultSetting,\n\t\t\t\titemType: item as ItemType,\n\t\t\t});\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 * @param admin Admin id\n\t */\n\tpublic async update(id: string, data: UpdateDTO, admin?: string): Promise<DocumentType<Model>> {\n\t\tif (!admin) notFoundError('Admin not found');\n\n\t\tconst record = await this.model.findById(id);\n\t\tif (!record) notFoundError('Record not found');\n\n\t\tconst result = await this.model.findByIdAndUpdate(id, data, {\n\t\t\tnew: true,\n\t\t\trunValidators: true,\n\t\t});\n\n\t\tif (!result) notFoundError('Record not found');\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.CHANGE_IN_MARKETING_SETTINGS,\n\t\t\trecord,\n\t\t\tresult\n\t\t);\n\n\t\treturn result;\n\t}\n\n\t/**\n\t * Update all records\n\t * @param data Data to update\n\t * @param admin Admin id\n\t */\n\tpublic async updateAll(data: UpdateAllDTO[], admin?: string): Promise<DocumentType<Model>[]> {\n\t\t// Check admin existence\n\t\tif (!admin) notFoundError('Admin not found');\n\n\t\tconst results: DocumentType<Model>[] = [];\n\n\t\tfor (const dealSetting of data) {\n\t\t\tconst { _id, ...rest } = dealSetting as UpdateAllDTO & { _id: string | mongoose.Types.ObjectId };\n\n\t\t\tif (!_id) continue;\n\n\t\t\tconst updated = await this.update(String(_id), rest as UpdateAllDTO, admin);\n\t\t\tresults.push(updated);\n\t\t}\n\n\t\treturn results;\n\t}\n\n\tprivate async logMarketingSettingAdminAction(\n\t\tadmin: mongoose.Types.ObjectId,\n\t\tactionType: AdminLogsUpdatedFieldsType,\n\t\toldDocument?: any,\n\t\tnewDocument?: any\n\t) {\n\t\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\t\tadmin,\n\t\t\tupdatedField: actionType,\n\t\t\toldDocument: oldDocument ?? '',\n\t\t\tnewDocument: newDocument ?? '',\n\t\t});\n\t\tawait publishEvent(adminActivityLogsEvent);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO, admin?: string): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Admin not found',\n\t\t\t});\n\t\t}\n\n\t\tconst record = await this.model.findById(_id);\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\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: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Unable to delete record',\n\t\t\t});\n\t\t}\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.DELETED_MARKETING_SETTINGS,\n\t\t\trecord,\n\t\t\tresult\n\t\t);\n\n\t\treturn 'Record deleted successfully';\n\t}\n}\n\nexport const dealSettingService = Container.get(DealSettingService);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"featured-setting.router.d.ts","sourceRoot":"/","sources":["modules/featured-setting/routers/featured-setting.router.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"featured-setting.router.d.ts","sourceRoot":"/","sources":["modules/featured-setting/routers/featured-setting.router.ts"],"names":[],"mappings":"AAcA,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAiBkC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCnE,CAAC"}
|
|
@@ -5,10 +5,12 @@ import { FeaturedSetting as Model } from '@lyxa.ai/core/dist/libraries/mongo/mod
|
|
|
5
5
|
import { CreateFeaturedSettingDTO as CreateDTO, UpdateFeaturedSettingDTO as UpdateDTO } from '../../featured-setting/validations';
|
|
6
6
|
export declare class FeaturedSettingService {
|
|
7
7
|
private model;
|
|
8
|
+
private ITEM_TYPES;
|
|
8
9
|
constructor();
|
|
9
10
|
create(data: CreateDTO, admin?: string): Promise<DocumentType<Model>>;
|
|
10
11
|
findById(id: string | mongoose.Types.ObjectId): Promise<DocumentType<Model>>;
|
|
11
12
|
find(data?: Partial<FilterDTO>): Promise<PaginatedResponse<DocumentType<ModelType<Model>>>>;
|
|
13
|
+
private createDefaultFeaturedSettings;
|
|
12
14
|
update(id: string, data: UpdateDTO, admin?: string): Promise<DocumentType<Model>>;
|
|
13
15
|
private logMarketingSettingAdminAction;
|
|
14
16
|
deleteById(data: DeleteDTO, admin?: string): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"featured-setting.service.d.ts","sourceRoot":"/","sources":["modules/featured-setting/services/featured-setting.service.ts"],"names":[],"mappings":"AAEA,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,EAAwB,eAAe,IAAI,KAAK,EAAE,MAAM,4CAA4C,CAAC;AAC5G,OAAO,EACN,wBAAwB,IAAI,SAAS,EACrC,wBAAwB,IAAI,SAAS,EACrC,MAAM,uCAAuC,CAAC;AAO/C,qBACa,sBAAsB;IAClC,OAAO,CAAC,KAAK,CAAuD;;
|
|
1
|
+
{"version":3,"file":"featured-setting.service.d.ts","sourceRoot":"/","sources":["modules/featured-setting/services/featured-setting.service.ts"],"names":[],"mappings":"AAEA,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,EAAwB,eAAe,IAAI,KAAK,EAAE,MAAM,4CAA4C,CAAC;AAC5G,OAAO,EACN,wBAAwB,IAAI,SAAS,EACrC,wBAAwB,IAAI,SAAS,EACrC,MAAM,uCAAuC,CAAC;AAO/C,qBACa,sBAAsB;IAClC,OAAO,CAAC,KAAK,CAAuD;IACpE,OAAO,CAAC,UAAU,CAQhB;;IAUW,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IA4BrE,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;YA6B1F,6BAA6B;IA+C9B,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;YAsChF,8BAA8B;IAmB/B,UAAU,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAoCzE;AAED,eAAO,MAAM,sBAAsB,wBAAwC,CAAC"}
|
|
@@ -53,16 +53,17 @@ const admin_logs_event_1 = require("@lyxa.ai/core/dist/libraries/event/events/ad
|
|
|
53
53
|
const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
54
54
|
let FeaturedSettingService = class FeaturedSettingService {
|
|
55
55
|
model;
|
|
56
|
+
ITEM_TYPES = [
|
|
57
|
+
enum_1.ItemType.FOOD,
|
|
58
|
+
enum_1.ItemType.GROCERY,
|
|
59
|
+
enum_1.ItemType.COFFEE,
|
|
60
|
+
enum_1.ItemType.FLOWER,
|
|
61
|
+
enum_1.ItemType.PET,
|
|
62
|
+
];
|
|
56
63
|
constructor() {
|
|
57
64
|
this.model = models_1.FeaturedSettingModel;
|
|
58
65
|
}
|
|
59
66
|
async create(data, admin) {
|
|
60
|
-
if (!admin) {
|
|
61
|
-
throw new server_1.TRPCError({
|
|
62
|
-
code: 'NOT_FOUND',
|
|
63
|
-
message: 'Admin not found',
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
67
|
const exists = await this.model.exists({
|
|
67
68
|
itemType: data.itemType,
|
|
68
69
|
});
|
|
@@ -73,7 +74,9 @@ let FeaturedSettingService = class FeaturedSettingService {
|
|
|
73
74
|
});
|
|
74
75
|
}
|
|
75
76
|
const result = await this.model.create(data);
|
|
76
|
-
|
|
77
|
+
if (admin) {
|
|
78
|
+
this.logMarketingSettingAdminAction(new typegoose_1.mongoose.Types.ObjectId(admin), enum_1.AdminLogsUpdatedFieldsType.CREATED_MARKETING_SETTINGS, '', result);
|
|
79
|
+
}
|
|
77
80
|
return result;
|
|
78
81
|
}
|
|
79
82
|
async findById(id) {
|
|
@@ -100,7 +103,11 @@ let FeaturedSettingService = class FeaturedSettingService {
|
|
|
100
103
|
select: data?.select,
|
|
101
104
|
populate: data?.populate,
|
|
102
105
|
};
|
|
103
|
-
|
|
106
|
+
let paginatedResult = await paginate(options);
|
|
107
|
+
if (!data?.query && paginatedResult.metadata.totalElements < this.ITEM_TYPES.length) {
|
|
108
|
+
await this.createDefaultFeaturedSettings(paginatedResult.documents);
|
|
109
|
+
paginatedResult = await paginate(options);
|
|
110
|
+
}
|
|
104
111
|
return paginatedResult;
|
|
105
112
|
}
|
|
106
113
|
catch (err) {
|
|
@@ -110,6 +117,45 @@ let FeaturedSettingService = class FeaturedSettingService {
|
|
|
110
117
|
});
|
|
111
118
|
}
|
|
112
119
|
}
|
|
120
|
+
async createDefaultFeaturedSettings(documents) {
|
|
121
|
+
const existingItemTypes = documents.map(setting => setting.itemType);
|
|
122
|
+
const newItemTypes = this.ITEM_TYPES.filter(item => !existingItemTypes.includes(item));
|
|
123
|
+
const defaultSetting = {
|
|
124
|
+
featuredItems: [
|
|
125
|
+
{
|
|
126
|
+
durationInDays: 3,
|
|
127
|
+
amount: 0,
|
|
128
|
+
status: enum_1.Status.INACTIVE,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
durationInDays: 7,
|
|
132
|
+
amount: 0,
|
|
133
|
+
status: enum_1.Status.INACTIVE,
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
durationInDays: 14,
|
|
137
|
+
amount: 0,
|
|
138
|
+
status: enum_1.Status.INACTIVE,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
durationInDays: 21,
|
|
142
|
+
amount: 0,
|
|
143
|
+
status: enum_1.Status.INACTIVE,
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
durationInDays: 28,
|
|
147
|
+
amount: 0,
|
|
148
|
+
status: enum_1.Status.INACTIVE,
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
};
|
|
152
|
+
for (const item of newItemTypes) {
|
|
153
|
+
await this.create({
|
|
154
|
+
...defaultSetting,
|
|
155
|
+
itemType: item,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
113
159
|
async update(id, data, admin) {
|
|
114
160
|
if (!admin) {
|
|
115
161
|
throw new server_1.TRPCError({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"featured-setting.service.js","sourceRoot":"/","sources":["modules/featured-setting/services/featured-setting.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AACzC,oDAA+E;AAE/E,wEAA6G;AAE7G,uEAA4G;AAM5G,8DAAkE;AAElE,iGAAoG;AACpG,4DAA+E;AAGxE,IAAM,sBAAsB,GAA5B,MAAM,sB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C,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,UAAU,CAAC,CAAC;QACnF,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,uBAAuB;gBAC7B,OAAO,EAAE,yBAAyB;aAClC,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,8BAA8B,CAClC,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAClC,iCAA0B,CAAC,0BAA0B,EACrD,MAAM,EACN,MAAM,CACN,CAAC;QAEF,OAAO,6BAA6B,CAAC;IACtC,CAAC;CACD,CAAA;AAtLY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,gBAAO,GAAE;;GACG,sBAAsB,CAsLlC;AAEY,QAAA,sBAAsB,GAAG,gBAAS,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC","sourcesContent":["import 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 { FeaturedSettingModel, FeaturedSetting as Model } from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateFeaturedSettingDTO as CreateDTO,\n\tUpdateFeaturedSettingDTO as UpdateDTO,\n} from '@modules/featured-setting/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport { BaseEvent } from '@lyxa.ai/core/dist/libraries/event/BaseEvent';\nimport { AdminActivityLogsEvent } from '@lyxa.ai/core/dist/libraries/event/events/admin-logs-event';\nimport { AdminLogsUpdatedFieldsType } from '@lyxa.ai/core/dist/utilities/enum';\n\n@Service()\nexport class FeaturedSettingService {\n\tprivate model: typeof FeaturedSettingModel & SoftDeleteModel<Model>;\n\n\tconstructor() {\n\t\tthis.model = FeaturedSettingModel as typeof FeaturedSettingModel & SoftDeleteModel<Model>;\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, admin?: string): Promise<DocumentType<Model>> {\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Admin not found',\n\t\t\t});\n\t\t}\n\n\t\tconst exists = await this.model.exists({\n\t\t\titemType: data.itemType,\n\t\t});\n\t\tif (exists) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'CONFLICT',\n\t\t\t\tmessage: `Featured settings for itemType ${data.itemType} already exists. Please update the existing settings.`,\n\t\t\t});\n\t\t}\n\t\tconst result = await this.model.create(data);\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.CREATED_MARKETING_SETTINGS,\n\t\t\t'',\n\t\t\tresult\n\t\t);\n\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 record\n\t * @param id ID of the record\n\t * @param data Data to update\n\t * @param admin Admin id\n\t */\n\tpublic async update(id: string, data: UpdateDTO, admin?: string): Promise<DocumentType<Model>> {\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Admin not found`,\n\t\t\t});\n\t\t}\n\n\t\tconst record = await this.model.findById(id);\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\tconst result = await this.model.findByIdAndUpdate(id, data, {\n\t\t\tnew: true,\n\t\t\trunValidators: true,\n\t\t});\n\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\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.CHANGE_IN_MARKETING_SETTINGS,\n\t\t\trecord,\n\t\t\tresult\n\t\t);\n\n\t\treturn result;\n\t}\n\n\tprivate async logMarketingSettingAdminAction(\n\t\tadmin: mongoose.Types.ObjectId,\n\t\tactionType: AdminLogsUpdatedFieldsType,\n\t\toldDocument?: any,\n\t\tnewDocument?: any\n\t) {\n\t\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\t\tadmin,\n\t\t\tupdatedField: actionType,\n\t\t\toldDocument: oldDocument ?? '',\n\t\t\tnewDocument: newDocument ?? '',\n\t\t});\n\t\tawait publishEvent(adminActivityLogsEvent);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO, admin?: string): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Admin not found',\n\t\t\t});\n\t\t}\n\n\t\tconst record = await this.model.findById(_id);\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\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: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Unable to delete record',\n\t\t\t});\n\t\t}\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.DELETED_MARKETING_SETTINGS,\n\t\t\trecord,\n\t\t\tresult\n\t\t);\n\n\t\treturn 'Record deleted successfully';\n\t}\n}\n\nexport const featuredSettingService = Container.get(FeaturedSettingService);\n"]}
|
|
1
|
+
{"version":3,"file":"featured-setting.service.js","sourceRoot":"/","sources":["modules/featured-setting/services/featured-setting.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAC5C,yCAAyC;AACzC,oDAA+E;AAE/E,wEAA6G;AAE7G,uEAA4G;AAM5G,8DAAkE;AAElE,iGAAoG;AACpG,4DAAiG;A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WAAW;gBACjB,OAAO,EAAE,kBAAkB;aAC3B,CAAC,CAAC;QACJ,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,UAAU,CAAC,CAAC;QACnF,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,MAAM,IAAI,kBAAS,CAAC;gBACnB,IAAI,EAAE,uBAAuB;gBAC7B,OAAO,EAAE,yBAAyB;aAClC,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,8BAA8B,CAClC,IAAI,oBAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAClC,iCAA0B,CAAC,0BAA0B,EACrD,MAAM,EACN,MAAM,CACN,CAAC;QAEF,OAAO,6BAA6B,CAAC;IACtC,CAAC;CACD,CAAA;AA3OY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,gBAAO,GAAE;;GACG,sBAAsB,CA2OlC;AAEY,QAAA,sBAAsB,GAAG,gBAAS,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC","sourcesContent":["import 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 { FeaturedSettingModel, FeaturedSetting as Model } from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateFeaturedSettingDTO as CreateDTO,\n\tUpdateFeaturedSettingDTO as UpdateDTO,\n} from '@modules/featured-setting/validations';\nimport { SoftDeleteModel } from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport { publishEvent } from '@lyxa.ai/core/dist/libraries/event';\nimport { BaseEvent } from '@lyxa.ai/core/dist/libraries/event/BaseEvent';\nimport { AdminActivityLogsEvent } from '@lyxa.ai/core/dist/libraries/event/events/admin-logs-event';\nimport { AdminLogsUpdatedFieldsType, ItemType, Status } from '@lyxa.ai/core/dist/utilities/enum';\n\n@Service()\nexport class FeaturedSettingService {\n\tprivate model: typeof FeaturedSettingModel & SoftDeleteModel<Model>;\n\tprivate ITEM_TYPES = [\n\t\tItemType.FOOD,\n\t\tItemType.GROCERY,\n\t\tItemType.COFFEE,\n\t\tItemType.FLOWER,\n\t\tItemType.PET,\n\t\t// ItemType.PHARMACY,\n\t\t// ItemType.HEALTHY_CORNER,\n\t];\n\n\tconstructor() {\n\t\tthis.model = FeaturedSettingModel as typeof FeaturedSettingModel & SoftDeleteModel<Model>;\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, admin?: string): Promise<DocumentType<Model>> {\n\t\tconst exists = await this.model.exists({\n\t\t\titemType: data.itemType,\n\t\t});\n\t\tif (exists) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'CONFLICT',\n\t\t\t\tmessage: `Featured settings for itemType ${data.itemType} already exists. Please update the existing settings.`,\n\t\t\t});\n\t\t}\n\t\tconst result = await this.model.create(data);\n\n\t\tif (admin) {\n\t\t\tthis.logMarketingSettingAdminAction(\n\t\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\t\tAdminLogsUpdatedFieldsType.CREATED_MARKETING_SETTINGS,\n\t\t\t\t'',\n\t\t\t\tresult\n\t\t\t);\n\t\t}\n\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\tlet paginatedResult = await paginate(options);\n\n\t\t\tif (!data?.query && paginatedResult.metadata.totalElements < this.ITEM_TYPES.length) {\n\t\t\t\tawait this.createDefaultFeaturedSettings(\n\t\t\t\t\tpaginatedResult.documents as unknown as DocumentType<Model>[]\n\t\t\t\t);\n\t\t\t\tpaginatedResult = await paginate(options);\n\t\t\t}\n\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\tprivate async createDefaultFeaturedSettings(documents: DocumentType<Model>[]): Promise<void> {\n\t\tconst existingItemTypes = documents.map(setting => setting.itemType);\n\t\tconst newItemTypes = this.ITEM_TYPES.filter(item => !existingItemTypes.includes(item));\n\t\tconst defaultSetting = {\n\t\t\tfeaturedItems: [\n\t\t\t\t{\n\t\t\t\t\tdurationInDays: 3,\n\t\t\t\t\tamount: 0,\n\t\t\t\t\tstatus: Status.INACTIVE,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdurationInDays: 7,\n\t\t\t\t\tamount: 0,\n\t\t\t\t\tstatus: Status.INACTIVE,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdurationInDays: 14,\n\t\t\t\t\tamount: 0,\n\t\t\t\t\tstatus: Status.INACTIVE,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdurationInDays: 21,\n\t\t\t\t\tamount: 0,\n\t\t\t\t\tstatus: Status.INACTIVE,\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdurationInDays: 28,\n\t\t\t\t\tamount: 0,\n\t\t\t\t\tstatus: Status.INACTIVE,\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\n\t\tfor (const item of newItemTypes) {\n\t\t\tawait this.create({\n\t\t\t\t...defaultSetting,\n\t\t\t\titemType: item as ItemType,\n\t\t\t});\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 * @param admin Admin id\n\t */\n\tpublic async update(id: string, data: UpdateDTO, admin?: string): Promise<DocumentType<Model>> {\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: `Admin not found`,\n\t\t\t});\n\t\t}\n\n\t\tconst record = await this.model.findById(id);\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\tconst result = await this.model.findByIdAndUpdate(id, data, {\n\t\t\tnew: true,\n\t\t\trunValidators: true,\n\t\t});\n\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\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.CHANGE_IN_MARKETING_SETTINGS,\n\t\t\trecord,\n\t\t\tresult\n\t\t);\n\n\t\treturn result;\n\t}\n\n\tprivate async logMarketingSettingAdminAction(\n\t\tadmin: mongoose.Types.ObjectId,\n\t\tactionType: AdminLogsUpdatedFieldsType,\n\t\toldDocument?: any,\n\t\tnewDocument?: any\n\t) {\n\t\tconst adminActivityLogsEvent: BaseEvent<Record<string, unknown>> = new AdminActivityLogsEvent({\n\t\t\tadmin,\n\t\t\tupdatedField: actionType,\n\t\t\toldDocument: oldDocument ?? '',\n\t\t\tnewDocument: newDocument ?? '',\n\t\t});\n\t\tawait publishEvent(adminActivityLogsEvent);\n\t}\n\n\t/**\n\t * Delete record\n\t * @param data Data for delete\n\t */\n\tpublic async deleteById(data: DeleteDTO, admin?: string): Promise<string> {\n\t\tconst { _id, softDelete } = data;\n\n\t\tif (!admin) {\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'NOT_FOUND',\n\t\t\t\tmessage: 'Admin not found',\n\t\t\t});\n\t\t}\n\n\t\tconst record = await this.model.findById(_id);\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\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: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Unable to delete record',\n\t\t\t});\n\t\t}\n\n\t\tthis.logMarketingSettingAdminAction(\n\t\t\tnew mongoose.Types.ObjectId(admin),\n\t\t\tAdminLogsUpdatedFieldsType.DELETED_MARKETING_SETTINGS,\n\t\t\trecord,\n\t\t\tresult\n\t\t);\n\n\t\treturn 'Record deleted successfully';\n\t}\n}\n\nexport const featuredSettingService = Container.get(FeaturedSettingService);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.router.d.ts","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"marketing.router.d.ts","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4BAeZ,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2Cf,CAAC"}
|
|
@@ -19,15 +19,11 @@ exports.marketingRouter = (0, trpc_1.createTRPCRouter)({
|
|
|
19
19
|
await services_1.marketingService.create(input, isAdmin ? new typegoose_1.mongoose.Types.ObjectId(ctx.entity?.id) : undefined);
|
|
20
20
|
return (0, response_1.response)('Marketing created successfully');
|
|
21
21
|
})),
|
|
22
|
-
getById: trpc_1.publicProcedure
|
|
23
|
-
.input(validation_1.GetByIdInputSchema)
|
|
24
|
-
.query(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
22
|
+
getById: trpc_1.publicProcedure.input(validation_1.GetByIdInputSchema).query(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
25
23
|
const result = await services_1.marketingService.findById(input);
|
|
26
24
|
return (0, response_1.response)('Marketing fetched successfully', result);
|
|
27
25
|
})),
|
|
28
|
-
get: trpc_1.publicProcedure
|
|
29
|
-
.input(validation_1.FilterSchema)
|
|
30
|
-
.query(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
26
|
+
get: trpc_1.publicProcedure.input(validation_1.FilterSchema).query(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
31
27
|
const result = await services_1.marketingService.find(input);
|
|
32
28
|
return (0, response_1.response)('Marketing fetched successfully', result);
|
|
33
29
|
})),
|
|
@@ -40,11 +36,12 @@ exports.marketingRouter = (0, trpc_1.createTRPCRouter)({
|
|
|
40
36
|
await services_1.marketingService.update(_id, rest, isAdmin ? new typegoose_1.mongoose.Types.ObjectId(ctx.entity?.id) : undefined);
|
|
41
37
|
return (0, response_1.response)('Marketing updated successfully');
|
|
42
38
|
})),
|
|
43
|
-
deleteById: (0, auth_1.createAuthenticatedProcedure)({ entityTypes: [auth_2.AuthEntityType.CRM] })
|
|
39
|
+
deleteById: (0, auth_1.createAuthenticatedProcedure)({ entityTypes: [auth_2.AuthEntityType.CRM, auth_2.AuthEntityType.SELLER] })
|
|
44
40
|
.input(validation_1.DeleteSchema)
|
|
45
41
|
.output(validations_1.MarketingResponseSchema)
|
|
46
42
|
.mutation(async ({ ctx, input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
47
|
-
|
|
43
|
+
const isAdmin = ctx.entity?.type == auth_2.AuthEntityType.CRM;
|
|
44
|
+
await services_1.marketingService.deleteById(input, isAdmin ? new typegoose_1.mongoose.Types.ObjectId(ctx.entity?.id) : undefined);
|
|
48
45
|
return (0, response_1.response)('Marketing deleted successfully');
|
|
49
46
|
})),
|
|
50
47
|
handleNewProductForEntireMenuMarketing: trpc_1.publicProcedure
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketing.router.js","sourceRoot":"/","sources":["modules/marketing/routers/marketing.router.ts"],"names":[],"mappings":";;;AAAA,4DAAsF;AACtF,6EAAkG;AAClG,0DAA0E;AAC1E,gEAKwC;AACxC,oEAAiE;AACjE,wEAAyG;AACzG,8EAA0E;AAC1E,4DAAmE;AACnE,oDAAgD;AAEnC,QAAA,eAAe,GAAG,IAAA,uBAAgB,EAAC;IAC/C,MAAM,EAAE,IAAA,mCAA4B,EAAC,EAAE,WAAW,EAAE,CAAC,qBAAc,CAAC,GAAG,EAAE,qBAAc,CAAC,MAAM,CAAC,EAAE,CAAC;SAChG,KAAK,CAAC,2CAA6B,CAAC;SACpC,MAAM,CAAC,qCAAc,CAAC;SACtB,QAAQ,CAAC,KAAK,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,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BAA8B,CAAC,CAAC;IACjD,CAAC,CAAC,CACF;CACF,CAAC,CAAC","sourcesContent":["import { createTRPCRouter, publicProcedure } from '@lyxa.ai/core/dist/libraries/trpc';\nimport { createAuthenticatedProcedure } from '@lyxa.ai/core/dist/libraries/trpc/middlewares/auth';\nimport { marketingService as service } from '@modules/marketing/services';\nimport {\n\tAllMarketingsValidationSchema,\n\tMarketingResponseSchema as ResponseSchema,\n\tAllMarketingsUpdateSchema,\n\tProductEntireMenuMarketingHandlerSchema,\n} from '@modules/marketing/validations';\nimport { response } from '@lyxa.ai/core/dist/utilities/response';\nimport { FilterSchema, DeleteSchema, GetByIdInputSchema } from '@lyxa.ai/core/dist/utilities/validation';\nimport { ErrorHandler } from '@lyxa.ai/core/dist/utilities/error-handler';\nimport { AuthEntityType } from '@lyxa.ai/core/dist/libraries/auth';\nimport { mongoose } from '@typegoose/typegoose';\n\nexport const marketingRouter = createTRPCRouter({\n\tcreate: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(AllMarketingsValidationSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\t\t\t\tawait service.create(input, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing created successfully');\n\t\t\t})\n\t\t),\n\n\tgetById: publicProcedure.input(GetByIdInputSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.findById(input);\n\t\t\treturn response('Marketing fetched successfully', result);\n\t\t})\n\t),\n\n\tget: publicProcedure.input(FilterSchema).query(async ({ input }) =>\n\t\tErrorHandler.wrapAsync(async () => {\n\t\t\tconst result = await service.find(input);\n\t\t\treturn response('Marketing fetched successfully', result);\n\t\t})\n\t),\n\n\tupdate: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(AllMarketingsUpdateSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst { _id, ...rest } = input;\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\n\t\t\t\tawait service.update(_id, rest, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing updated successfully');\n\t\t\t})\n\t\t),\n\n\tdeleteById: createAuthenticatedProcedure({ entityTypes: [AuthEntityType.CRM, AuthEntityType.SELLER] })\n\t\t.input(DeleteSchema)\n\t\t.output(ResponseSchema)\n\t\t.mutation(async ({ ctx, input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tconst isAdmin = ctx.entity?.type == AuthEntityType.CRM;\n\t\t\t\tawait service.deleteById(input, isAdmin ? new mongoose.Types.ObjectId(ctx.entity?.id) : undefined);\n\t\t\t\treturn response('Marketing deleted successfully');\n\t\t\t})\n\t\t),\n\n\thandleNewProductForEntireMenuMarketing: publicProcedure\n\t\t.input(ProductEntireMenuMarketingHandlerSchema)\n\t\t.mutation(async ({ input }) =>\n\t\t\tErrorHandler.wrapAsync(async () => {\n\t\t\t\tawait service.handleNewProductForEntireMenuMarketing(input);\n\t\t\t\treturn response('Product handled successfully');\n\t\t\t})\n\t\t),\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buy1-get1-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/buy1-get1-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,iBAAiB,IAAI,KAAK,EAE1B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;AAIxC,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAAsB;;IAW7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"buy1-get1-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/buy1-get1-marketing.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,iBAAiB,IAAI,KAAK,EAE1B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;AAIxC,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAAsB;;IAW7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAmFrD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IA0FnF,uBAAuB,CACnC,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EACpC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,GAChC,OAAO,CAAC,IAAI,CAAC;CAOhB;AAED,eAAO,MAAM,wBAAwB,0BAA0C,CAAC"}
|
|
@@ -56,7 +56,10 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
|
|
|
56
56
|
}
|
|
57
57
|
async create(data) {
|
|
58
58
|
const result = await this.model.create(data);
|
|
59
|
-
if (data.products &&
|
|
59
|
+
if (data.products &&
|
|
60
|
+
data.products.length > 0 &&
|
|
61
|
+
(!data.categories || data.categories.length === 0) &&
|
|
62
|
+
!data.isEntireMenu) {
|
|
60
63
|
for (const product of data.products) {
|
|
61
64
|
if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
|
|
62
65
|
this.productMarketingsCreate(result._id, product.product);
|
|
@@ -65,7 +68,8 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
|
|
|
65
68
|
}
|
|
66
69
|
else if (data.categories &&
|
|
67
70
|
data.categories.length > 0 &&
|
|
68
|
-
(!data.products || data.products.length === 0)
|
|
71
|
+
(!data.products || data.products.length === 0) &&
|
|
72
|
+
!data.isEntireMenu) {
|
|
69
73
|
const categoryWiseProducts = await this.productModel
|
|
70
74
|
.find({
|
|
71
75
|
shopCategory: { $in: data.categories },
|
|
@@ -77,7 +81,11 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
|
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
}
|
|
80
|
-
else if (data.categories &&
|
|
84
|
+
else if (data.categories &&
|
|
85
|
+
data.categories.length > 0 &&
|
|
86
|
+
data.products &&
|
|
87
|
+
data.products.length > 0 &&
|
|
88
|
+
!data.isEntireMenu) {
|
|
81
89
|
const categoryWiseProducts = await this.productModel
|
|
82
90
|
.find({
|
|
83
91
|
shopCategory: { $in: data.categories },
|
|
@@ -123,14 +131,18 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
|
|
|
123
131
|
data.isEntireMenu) {
|
|
124
132
|
await _1.productMarketingService.deleteMany({ marketing: _id }, true);
|
|
125
133
|
}
|
|
126
|
-
if (data.products &&
|
|
134
|
+
if (data.products &&
|
|
135
|
+
data.products.length > 0 &&
|
|
136
|
+
(!data.categories || data.categories.length === 0) &&
|
|
137
|
+
!data.isEntireMenu) {
|
|
127
138
|
for (const product of data.products) {
|
|
128
139
|
this.productMarketingsCreate(_id, product.product);
|
|
129
140
|
}
|
|
130
141
|
}
|
|
131
142
|
else if (data.categories &&
|
|
132
143
|
data.categories.length > 0 &&
|
|
133
|
-
(!data.products || data.products.length === 0)
|
|
144
|
+
(!data.products || data.products.length === 0) &&
|
|
145
|
+
!data.isEntireMenu) {
|
|
134
146
|
const categoryWiseProducts = await this.productModel
|
|
135
147
|
.find({
|
|
136
148
|
shopCategory: { $in: data.categories },
|
|
@@ -140,7 +152,11 @@ let Buy1Get1MarketingService = class Buy1Get1MarketingService {
|
|
|
140
152
|
this.productMarketingsCreate(_id, product._id);
|
|
141
153
|
}
|
|
142
154
|
}
|
|
143
|
-
else if (data.categories &&
|
|
155
|
+
else if (data.categories &&
|
|
156
|
+
data.categories.length > 0 &&
|
|
157
|
+
data.products &&
|
|
158
|
+
data.products.length > 0 &&
|
|
159
|
+
!data.isEntireMenu) {
|
|
144
160
|
const categoryWiseProducts = await this.productModel
|
|
145
161
|
.find({
|
|
146
162
|
shopCategory: { $in: data.categories },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buy1-get1-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/buy1-get1-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAG5C,uEAIoD;AAKpD,yBAA6C;AAC7C,4EAA0E;AAGnE,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAC5B,KAAK,CAAgC;IACrC,YAAY,CAAsB;IAE1C;QACC,IAAI,CAAC,KAAK,GAAG,+BAAsB,CAAC;QACpC,IAAI,CAAC,YAAY,GAAG,qBAAY,CAAC;IAClC,CAAC;IAMM,KAAK,CAAC,MAAM,CAAC,IAAe;QAClC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAG7C,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU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,YAAY;iBACf,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;iBACzB,MAAM,CAAC,KAAK,CAAC;iBACb,IAAI,EAAE;iBACN,IAAI,CAAC,gBAAgB,CAAC,EAAE;gBACxB,KAAK,MAAM,OAAO,IAAI,gBAAgB,EAAE,CAAC;oBACxC,IAAI,CAAC,uBAAuB,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;gBAChD,CAAC;YACF,CAAC,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM;YAAE,IAAA,4BAAa,EAAC,kBAAkB,CAAC,CAAC;QAE/C,OAAO,MAAM,CAAC;IACf,CAAC;IAEM,KAAK,CAAC,uBAAuB,CACnC,WAAoC,EACpC,SAAkC;QAElC,0BAAuB,CAAC,MAAM,CAAC;YAC9B,SAAS,EAAE,WAAW;YACtB,OAAO,EAAE,SAAS;YAClB,UAAU,EAAE,IAAI;SAChB,CAAC,CAAC;IACJ,CAAC;CACD,CAAA;AA5KY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CA4KpC;AAEY,QAAA,wBAAwB,GAAG,gBAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tBuy1Get1MarketingModel,\n\tBuy1Get1Marketing as Model,\n\tProductModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateBuy1Get1MarketingDTO as CreateDTO,\n\tUpdateBuy1Get1MarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { productMarketingService } from './';\nimport { notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class Buy1Get1MarketingService {\n\tprivate model: typeof Buy1Get1MarketingModel;\n\tprivate productModel: typeof ProductModel;\n\n\tconstructor() {\n\t\tthis.model = Buy1Get1MarketingModel;\n\t\tthis.productModel = ProductModel;\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\n\t\t// Only products\n\t\tif (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0)\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({ shop: data.shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\treturn result;\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: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst { products, ...rest } = data;\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\trest,\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\t// Remove all products from product-marketings collection\n\t\tif (\n\t\t\t(data.products && data.products.length > 0) ||\n\t\t\t(data.categories && data.categories.length > 0) ||\n\t\t\tdata.isEntireMenu\n\t\t) {\n\t\t\tawait productMarketingService.deleteMany({ marketing: _id }, true);\n\t\t}\n\n\t\t// Only products\n\t\tif (data.products && data.products.length > 0 && (!data.categories || data.categories.length === 0)) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tthis.productMarketingsCreate(_id, product.product);\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0)\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t}\n\t\t} else if (data.categories && data.categories.length > 0 && data.products && data.products.length > 0) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\tthis.productMarketingsCreate(_id, product.product);\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({ shop: data.shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n\n\tpublic async productMarketingsCreate(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproductId: mongoose.Types.ObjectId\n\t): Promise<void> {\n\t\tproductMarketingService.create({\n\t\t\tmarketing: marketingId,\n\t\t\tproduct: productId,\n\t\t\tisBuy1Get1: true,\n\t\t});\n\t}\n}\n\nexport const buy1Get1MarketingService = Container.get(Buy1Get1MarketingService);\n"]}
|
|
1
|
+
{"version":3,"file":"buy1-get1-marketing.service.js","sourceRoot":"/","sources":["modules/marketing/services/buy1-get1-marketing.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA4C;AAG5C,uEAIoD;AAKpD,yBAA6C;AAC7C,4EAA0E;AAGnE,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB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AxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CAoMpC;AAEY,QAAA,wBAAwB,GAAG,gBAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import Container, { Service } from 'typedi';\nimport { TRPCError } from '@trpc/server';\nimport { DocumentType, mongoose } from '@typegoose/typegoose';\nimport {\n\tBuy1Get1MarketingModel,\n\tBuy1Get1Marketing as Model,\n\tProductModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models/';\nimport {\n\tCreateBuy1Get1MarketingDTO as CreateDTO,\n\tUpdateBuy1Get1MarketingDTO as UpdateDTO,\n} from '@modules/marketing/validations';\nimport { productMarketingService } from './';\nimport { notFoundError } from '@lyxa.ai/core/dist/utilities/error-common';\n\n@Service()\nexport class Buy1Get1MarketingService {\n\tprivate model: typeof Buy1Get1MarketingModel;\n\tprivate productModel: typeof ProductModel;\n\n\tconstructor() {\n\t\tthis.model = Buy1Get1MarketingModel;\n\t\tthis.productModel = ProductModel;\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\n\t\t// Only products\n\t\tif (\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t(!data.categories || data.categories.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {\n\t\t\t\t\tthis.productMarketingsCreate(result._id, product.product);\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({ shop: data.shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tif (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product._id))) {\n\t\t\t\t\t\t\tthis.productMarketingsCreate(result._id, product._id);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\treturn result;\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: mongoose.Types.ObjectId, data: UpdateDTO): Promise<DocumentType<Model>> {\n\t\tconst { products, ...rest } = data;\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\trest,\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\t// Remove all products from product-marketings collection\n\t\tif (\n\t\t\t(data.products && data.products.length > 0) ||\n\t\t\t(data.categories && data.categories.length > 0) ||\n\t\t\tdata.isEntireMenu\n\t\t) {\n\t\t\tawait productMarketingService.deleteMany({ marketing: _id }, true);\n\t\t}\n\n\t\t// Only products\n\t\tif (\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t(!data.categories || data.categories.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\tfor (const product of data.products) {\n\t\t\t\tthis.productMarketingsCreate(_id, product.product);\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\t(!data.products || data.products.length === 0) &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Only categories\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t}\n\t\t} else if (\n\t\t\tdata.categories &&\n\t\t\tdata.categories.length > 0 &&\n\t\t\tdata.products &&\n\t\t\tdata.products.length > 0 &&\n\t\t\t!data.isEntireMenu\n\t\t) {\n\t\t\t// Both products and categories\n\t\t\t// For category\n\t\t\tconst categoryWiseProducts = await this.productModel\n\t\t\t\t.find({\n\t\t\t\t\tshopCategory: { $in: data.categories },\n\t\t\t\t})\n\t\t\t\t.lean();\n\n\t\t\tfor (const product of categoryWiseProducts) {\n\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t}\n\n\t\t\t// For products\n\t\t\tfor (const product of data.products) {\n\t\t\t\tthis.productMarketingsCreate(_id, product.product);\n\t\t\t}\n\t\t} else if (data.isEntireMenu) {\n\t\t\t// Entire menu\n\t\t\tthis.productModel\n\t\t\t\t.find({ shop: data.shop })\n\t\t\t\t.select('_id')\n\t\t\t\t.exec()\n\t\t\t\t.then(productDocuments => {\n\t\t\t\t\tfor (const product of productDocuments) {\n\t\t\t\t\t\tthis.productMarketingsCreate(_id, product._id);\n\t\t\t\t\t}\n\t\t\t\t});\n\t\t}\n\n\t\tif (!record) notFoundError('Record not found');\n\n\t\treturn record;\n\t}\n\n\tpublic async productMarketingsCreate(\n\t\tmarketingId: mongoose.Types.ObjectId,\n\t\tproductId: mongoose.Types.ObjectId\n\t): Promise<void> {\n\t\tproductMarketingService.create({\n\t\t\tmarketing: marketingId,\n\t\t\tproduct: productId,\n\t\t\tisBuy1Get1: true,\n\t\t});\n\t}\n}\n\nexport const buy1Get1MarketingService = Container.get(Buy1Get1MarketingService);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discount-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/discount-marketing.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,iBAAiB,IAAI,KAAK,EAE1B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAG9D,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAAsB;;IAW7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"discount-marketing.service.d.ts","sourceRoot":"/","sources":["modules/marketing/services/discount-marketing.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAEN,iBAAiB,IAAI,KAAK,EAE1B,MAAM,2CAA2C,CAAC;AACnD,OAAO,EACN,0BAA0B,IAAI,SAAS,EACvC,0BAA0B,IAAI,SAAS,EACvC,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,SAAS,EAAE,MAAM,mCAAmC,CAAC;AAG9D,qBACa,wBAAwB;IACpC,OAAO,CAAC,KAAK,CAAgC;IAC7C,OAAO,CAAC,YAAY,CAAsB;;IAW7B,MAAM,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAmIrD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;IAiInF,uBAAuB,CACnC,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EACpC,SAAS,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAClC,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,SAAS,GAClB,OAAO,CAAC,IAAI,CAAC;CAQhB;AAED,eAAO,MAAM,wBAAwB,0BAA0C,CAAC"}
|
|
@@ -56,7 +56,10 @@ let DiscountMarketingService = class DiscountMarketingService {
|
|
|
56
56
|
}
|
|
57
57
|
async create(data) {
|
|
58
58
|
const result = await this.model.create(data);
|
|
59
|
-
if (data.products &&
|
|
59
|
+
if (data.products &&
|
|
60
|
+
data.products.length > 0 &&
|
|
61
|
+
(!data.categories || data.categories.length === 0) &&
|
|
62
|
+
!data.isEntireMenu) {
|
|
60
63
|
for (const product of data.products) {
|
|
61
64
|
if (product.valueType !== undefined && product.valueType !== null) {
|
|
62
65
|
if (!data.excludeProducts || !data.excludeProducts.some(p => p.equals(product.product))) {
|
|
@@ -70,7 +73,8 @@ let DiscountMarketingService = class DiscountMarketingService {
|
|
|
70
73
|
}
|
|
71
74
|
else if (data.categories &&
|
|
72
75
|
data.categories.length > 0 &&
|
|
73
|
-
(!data.products || data.products.length === 0)
|
|
76
|
+
(!data.products || data.products.length === 0) &&
|
|
77
|
+
!data.isEntireMenu) {
|
|
74
78
|
const categoryWiseProducts = await this.productModel
|
|
75
79
|
.find({
|
|
76
80
|
shopCategory: { $in: data.categories },
|
|
@@ -87,7 +91,11 @@ let DiscountMarketingService = class DiscountMarketingService {
|
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
}
|
|
90
|
-
else if (data.categories &&
|
|
94
|
+
else if (data.categories &&
|
|
95
|
+
data.categories.length > 0 &&
|
|
96
|
+
data.products &&
|
|
97
|
+
data.products.length > 0 &&
|
|
98
|
+
!data.isEntireMenu) {
|
|
91
99
|
const categoryWiseProducts = await this.productModel
|
|
92
100
|
.find({
|
|
93
101
|
shopCategory: { $in: data.categories },
|
|
@@ -153,7 +161,10 @@ let DiscountMarketingService = class DiscountMarketingService {
|
|
|
153
161
|
data.isEntireMenu) {
|
|
154
162
|
await _1.productMarketingService.deleteMany({ marketing: _id }, true);
|
|
155
163
|
}
|
|
156
|
-
if (data.products &&
|
|
164
|
+
if (data.products &&
|
|
165
|
+
data.products.length > 0 &&
|
|
166
|
+
(!data.categories || data.categories.length === 0) &&
|
|
167
|
+
!data.isEntireMenu) {
|
|
157
168
|
for (const product of data.products) {
|
|
158
169
|
if (product.valueType !== undefined && product.valueType !== null) {
|
|
159
170
|
await this.productMarketingsCreate(_id, product.product, Number(product.value), product.valueType);
|
|
@@ -166,7 +177,8 @@ let DiscountMarketingService = class DiscountMarketingService {
|
|
|
166
177
|
}
|
|
167
178
|
else if (data.categories &&
|
|
168
179
|
data.categories.length > 0 &&
|
|
169
|
-
(!data.products || data.products.length === 0)
|
|
180
|
+
(!data.products || data.products.length === 0) &&
|
|
181
|
+
!data.isEntireMenu) {
|
|
170
182
|
const categoryWiseProducts = await this.productModel
|
|
171
183
|
.find({
|
|
172
184
|
shopCategory: { $in: data.categories },
|
|
@@ -181,7 +193,11 @@ let DiscountMarketingService = class DiscountMarketingService {
|
|
|
181
193
|
}
|
|
182
194
|
}
|
|
183
195
|
}
|
|
184
|
-
else if (data.categories &&
|
|
196
|
+
else if (data.categories &&
|
|
197
|
+
data.categories.length > 0 &&
|
|
198
|
+
data.products &&
|
|
199
|
+
data.products.length > 0 &&
|
|
200
|
+
!data.isEntireMenu) {
|
|
185
201
|
const categoryWiseProducts = await this.productModel
|
|
186
202
|
.find({
|
|
187
203
|
shopCategory: { $in: data.categories },
|