@lyxa.ai/marketing 1.0.59 → 1.0.60
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/event/event-initializations.d.ts.map +1 -1
- package/dist/lib/event/event-initializations.js +0 -1
- package/dist/lib/event/event-initializations.js.map +1 -1
- package/dist/lib/event/event-listeners/event-listeners.d.ts +0 -1
- package/dist/lib/event/event-listeners/event-listeners.d.ts.map +1 -1
- package/dist/lib/event/event-listeners/event-listeners.js +12 -62
- package/dist/lib/event/event-listeners/event-listeners.js.map +1 -1
- package/dist/lib/event/events/marketing-product-seed.event.d.ts +2 -1
- package/dist/lib/event/events/marketing-product-seed.event.d.ts.map +1 -1
- package/dist/lib/event/events/marketing-product-seed.event.js.map +1 -1
- package/dist/lib/index.d.ts +11 -7869
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +0 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts +2 -7630
- package/dist/lib/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/lib/modules/coupon/routers/coupon.router.js +7 -0
- package/dist/lib/modules/coupon/routers/coupon.router.js.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.d.ts +1 -0
- package/dist/lib/modules/coupon/services/coupon.service.d.ts.map +1 -1
- package/dist/lib/modules/coupon/services/coupon.service.js +4 -3
- package/dist/lib/modules/coupon/services/coupon.service.js.map +1 -1
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js +2 -2
- package/dist/lib/modules/coupon/services/patterns/repository/CouponRepository.js.map +1 -1
- package/dist/lib/modules/coupon/validations/coupon.validation.d.ts +6 -6
- package/dist/lib/modules/coupon/validations/coupon.validation.js +2 -2
- package/dist/lib/modules/coupon/validations/coupon.validation.js.map +1 -1
- package/dist/lib/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -1
- package/dist/lib/modules/coupon/validations/create-coupon.validation.js +1 -4
- package/dist/lib/modules/coupon/validations/create-coupon.validation.js.map +1 -1
- package/dist/lib/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
- package/dist/lib/modules/deal-setting/services/deal-setting.service.js +1 -4
- package/dist/lib/modules/deal-setting/services/deal-setting.service.js.map +1 -1
- 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 +0 -3
- package/dist/lib/modules/featured-setting/services/featured-setting.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts +8 -54
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js +0 -11
- package/dist/lib/modules/limited-time-offer/campaign/campaign.router.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.js +0 -6
- package/dist/lib/modules/limited-time-offer/campaign/jobs/index.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +1 -0
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js +6 -2
- package/dist/lib/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +3 -16
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js +3 -22
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +0 -2
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js +0 -12
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +35 -242
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js +1 -19
- package/dist/lib/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +1 -6
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.js +1 -45
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts +0 -3
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.js +8 -66
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js +19 -37
- package/dist/lib/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts +10 -241
- package/dist/lib/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.d.ts +0 -2
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.js +3 -15
- package/dist/lib/modules/limited-time-offer/limited-time-offer.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.d.ts +1 -1
- package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.js +1 -1
- package/dist/lib/modules/limited-time-offer/notification/limited-time-offer-notification.constants.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +2 -10
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js +1 -4
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.builder.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +0 -10
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js +0 -43
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +2 -187
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js +0 -29
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +0 -395
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js +6 -16
- package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.validation.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +4 -7
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.js +6 -31
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.js.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +3 -14
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js +16 -76
- package/dist/lib/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.d.ts +0 -1
- package/dist/lib/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/marketing.service.js +46 -60
- package/dist/lib/modules/marketing/services/marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts +3 -2
- package/dist/lib/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/product-marketing.service.js +13 -42
- package/dist/lib/modules/marketing/services/product-marketing.service.js.map +1 -1
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -1
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js +27 -95
- package/dist/lib/modules/marketing/services/synchronize-product-marketing.service.js.map +1 -1
- package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts +1 -0
- 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 +49 -2
- package/dist/lib/modules/punch-marketing-history/services/punch-marketing-history.service.js.map +1 -1
- package/dist/types/event/event-initializations.d.ts.map +1 -1
- package/dist/types/event/event-listeners/event-listeners.d.ts +0 -1
- package/dist/types/event/event-listeners/event-listeners.d.ts.map +1 -1
- package/dist/types/event/events/marketing-product-seed.event.d.ts +2 -1
- package/dist/types/event/events/marketing-product-seed.event.d.ts.map +1 -1
- package/dist/types/index.d.ts +11 -7869
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modules/coupon/routers/coupon.router.d.ts +2 -7630
- package/dist/types/modules/coupon/routers/coupon.router.d.ts.map +1 -1
- package/dist/types/modules/coupon/services/coupon.service.d.ts +1 -0
- package/dist/types/modules/coupon/services/coupon.service.d.ts.map +1 -1
- package/dist/types/modules/coupon/validations/coupon.validation.d.ts +6 -6
- package/dist/types/modules/coupon/validations/create-coupon.validation.d.ts.map +1 -1
- package/dist/types/modules/deal-setting/services/deal-setting.service.d.ts.map +1 -1
- package/dist/types/modules/featured-setting/services/featured-setting.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts +8 -54
- package/dist/types/modules/limited-time-offer/campaign/campaign.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/jobs/index.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts +1 -0
- package/dist/types/modules/limited-time-offer/campaign/jobs/limited-time-offer-campaign.worker.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts +3 -16
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.builder.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts +0 -2
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.repository.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts +35 -242
- package/dist/types/modules/limited-time-offer/campaign/limited-time-offer-campaign.validation.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts +1 -6
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-lifecycle.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts +0 -3
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign-scheduler.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts +1 -1
- package/dist/types/modules/limited-time-offer/campaign/services/limited-time-offer-campaign.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts +10 -241
- package/dist/types/modules/limited-time-offer/limited-time-offer.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/limited-time-offer.service.d.ts +0 -2
- package/dist/types/modules/limited-time-offer/limited-time-offer.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/notification/limited-time-offer-notification.constants.d.ts +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts +2 -10
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.builder.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts +0 -10
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.repository.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts +2 -187
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts +0 -395
- package/dist/types/modules/limited-time-offer/participant/limited-time-offer-participant.validation.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts +4 -7
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts +3 -14
- package/dist/types/modules/limited-time-offer/participant/services/limited-time-offer-participant.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/marketing.service.d.ts +0 -1
- package/dist/types/modules/marketing/services/marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts +3 -7
- package/dist/types/modules/marketing/services/product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/marketing/services/synchronize-product-marketing.service.d.ts.map +1 -1
- package/dist/types/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts +5 -0
- package/dist/types/modules/punch-marketing-history/services/punch-marketing-history.service.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/lib/event/events/marketing-product-sync.event.d.ts +0 -11
- package/dist/lib/event/events/marketing-product-sync.event.d.ts.map +0 -1
- package/dist/lib/event/events/marketing-product-sync.event.js +0 -12
- package/dist/lib/event/events/marketing-product-sync.event.js.map +0 -1
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.d.ts +0 -13
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.d.ts.map +0 -1
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.js +0 -75
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.js.map +0 -1
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts +0 -21
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts.map +0 -1
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.js +0 -83
- package/dist/lib/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.js.map +0 -1
- package/dist/types/event/events/marketing-product-sync.event.d.ts +0 -11
- package/dist/types/event/events/marketing-product-sync.event.d.ts.map +0 -1
- package/dist/types/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.d.ts +0 -13
- package/dist/types/modules/limited-time-offer/session/limited-time-offer-campaign-session.repository.d.ts.map +0 -1
- package/dist/types/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts +0 -21
- package/dist/types/modules/limited-time-offer/session/limited-time-offer-campaign-session.service.d.ts.map +0 -1
package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.repository.js
CHANGED
|
@@ -45,7 +45,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
45
45
|
exports.ltoParticipantRepository = exports.LtoParticipantRepository = void 0;
|
|
46
46
|
const typedi_1 = __importStar(require("typedi"));
|
|
47
47
|
const models_1 = require("@lyxa.ai/core/dist/libraries/mongo/models");
|
|
48
|
-
const enum_1 = require("@lyxa.ai/core/dist/utilities/enum");
|
|
49
48
|
const limited_time_offer_participant_builder_1 = require("./limited-time-offer-participant.builder");
|
|
50
49
|
let LtoParticipantRepository = class LtoParticipantRepository {
|
|
51
50
|
model;
|
|
@@ -156,48 +155,6 @@ let LtoParticipantRepository = class LtoParticipantRepository {
|
|
|
156
155
|
.lean();
|
|
157
156
|
return participants.map(p => p.marketing).filter(Boolean);
|
|
158
157
|
}
|
|
159
|
-
async countNonWithdrawnByCampaign(campaignId) {
|
|
160
|
-
return this.model.countDocuments({ campaign: campaignId, isWithdrawn: false });
|
|
161
|
-
}
|
|
162
|
-
async findAllActiveByCampaign(campaignId) {
|
|
163
|
-
return this.model.find({ campaign: campaignId, isWithdrawn: false });
|
|
164
|
-
}
|
|
165
|
-
async findPausedMarketingIdsByCampaign(campaignId) {
|
|
166
|
-
const participants = await this.model
|
|
167
|
-
.find({ campaign: campaignId, isWithdrawn: false, pausedMarketings: { $exists: true, $ne: [] } })
|
|
168
|
-
.select('pausedMarketings')
|
|
169
|
-
.lean();
|
|
170
|
-
return participants.flatMap(p => (p.pausedMarketings ?? []));
|
|
171
|
-
}
|
|
172
|
-
async findActiveMarketingIdsByShop(shopId, marketingType) {
|
|
173
|
-
const marketings = await models_1.MarketingModel.find({
|
|
174
|
-
shop: shopId,
|
|
175
|
-
marketingType,
|
|
176
|
-
campaignType: {
|
|
177
|
-
$in: [enum_1.MarketingCampaignType.STANDARD, null],
|
|
178
|
-
},
|
|
179
|
-
status: enum_1.MarketingStatus.ACTIVE,
|
|
180
|
-
deletedAt: null,
|
|
181
|
-
'duration.end': { $gt: new Date() },
|
|
182
|
-
})
|
|
183
|
-
.select('_id')
|
|
184
|
-
.lean();
|
|
185
|
-
return marketings.map(m => m._id);
|
|
186
|
-
}
|
|
187
|
-
async findRevivableMarketings(ids) {
|
|
188
|
-
const results = await models_1.MarketingModel.find({
|
|
189
|
-
_id: { $in: ids },
|
|
190
|
-
status: enum_1.MarketingStatus.PAUSED,
|
|
191
|
-
deletedAt: null,
|
|
192
|
-
'duration.end': { $gt: new Date() },
|
|
193
|
-
})
|
|
194
|
-
.select('_id shop')
|
|
195
|
-
.lean();
|
|
196
|
-
return results;
|
|
197
|
-
}
|
|
198
|
-
async updateMarketingStatus(ids, status) {
|
|
199
|
-
await models_1.MarketingModel.updateMany({ _id: { $in: ids } }, { $set: { status } });
|
|
200
|
-
}
|
|
201
158
|
async findParticipantIdsByCampaignId(campaignId) {
|
|
202
159
|
const participants = await this.model
|
|
203
160
|
.find({ campaign: campaignId, isWithdrawn: false })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limited-time-offer-participant.repository.js","sourceRoot":"/","sources":["modules/limited-time-offer/participant/limited-time-offer-participant.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAE1C,sEAMmD;AACnD,4DAAwG;AAMxG,qGAAoF;AAQ7E,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAC5B,KAAK,CAAmE;IACxE,SAAS,CAAmB;IAEpC;QACC,IAAI,CAAC,KAAK,GAAG,yCACU,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,kBAA6B,CAAC;IAChD,CAAC;IAEM,KAAK,CAAC,UAAU,CACtB,UAAmC,EACnC,KAGC,EACD,WAAmB;QAEnB,MAAM,YAAY,GAAG,MAAM,IAAI,CAA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AE;YAC3B;gBACC,MAAM,EAAE;oBACP,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;oBAC5B,SAAS,EAAE;wBACV,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,EAAE;wBACpC,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,EAAE;wBACpB;4BACC,QAAQ,EAAE;gCACT,MAAM,EAAE,eAAe;gCACvB,QAAQ,EAAE,EAAE,OAAO,EAAE,CAAC,gBAAgB,EAAE,IAAI,CAAC,EAAE;gCAC/C,SAAS,EAAE,EAAE,OAAO,EAAE,CAAC,gBAAgB,EAAE,IAAI,CAAC,EAAE;gCAChD,QAAQ,EAAE,CAAC;gCACX,kBAAkB,EAAE,CAAC;gCACrB,cAAc,EAAE,CAAC;6BACjB;yBACD;qBACD;iBACD;aACD;SACD,CAAC,CAAC;QAEH,OAAO;YACN,SAAS,EAAE,MAAM,EAAE,SAAS,IAAI,EAAE;YAClC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC;SACrC,CAAC;IACH,CAAC;CACD,CAAA;AAvRY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CAuRpC;AAEY,QAAA,wBAAwB,GAAG,gBAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {DocumentType, mongoose} from '@typegoose/typegoose';\nimport {\n\tLimitedTimeOfferParticipant as Model,\n\tLimitedTimeOfferParticipantModel,\n\tMarketingModel,\n\tProductModel,\n\tShopModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {MarketingCampaignType, MarketingStatus, MarketingType} from '@lyxa.ai/core/dist/utilities/enum';\nimport {SoftDeleteModel} from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport {\n\tGetLtoCampaignParticipantsDTO,\n\tLtoCampaignParticipantItemDTO,\n} from '../campaign/limited-time-offer-campaign.validation';\nimport {LtoParticipantQueryBuilder} from './limited-time-offer-participant.builder';\nimport {\n\tActiveParticipantMarketingDTO,\n\tParticipantSummaryDTO,\n\tUpdateParticipantDataDTO,\n} from './limited-time-offer-participant.validation';\n\n@Service()\nexport class LtoParticipantRepository {\n\tprivate model: typeof LimitedTimeOfferParticipantModel & SoftDeleteModel<Model>;\n\tprivate shopModel: typeof ShopModel;\n\n\tconstructor() {\n\t\tthis.model = LimitedTimeOfferParticipantModel as typeof LimitedTimeOfferParticipantModel &\n\t\t\tSoftDeleteModel<Model>;\n\t\tthis.shopModel = ShopModel as typeof ShopModel;\n\t}\n\n\tpublic async findNearby(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tinput: {\n\t\t\tlatitude: number;\n\t\t\tlongitude: number;\n\t\t},\n\t\tmaxDistance: number\n\t) {\n\t\tconst participants = await this.model\n\t\t\t.find({\n\t\t\t\tcampaign: campaignId,\n\t\t\t\tisWithdrawn: false,\n\t\t\t\tdeletedAt: null,\n\t\t\t})\n\t\t\t.select('shop')\n\t\t\t.lean();\n\n\t\tif (!participants.length) return [];\n\n\t\tconst shopIds = participants.map(p => p.shop);\n\n\t\treturn this.shopModel.aggregate([\n\t\t\t{\n\t\t\t\t$geoNear: {\n\t\t\t\t\tnear: {\n\t\t\t\t\t\ttype: 'Point',\n\t\t\t\t\t\tcoordinates: [input.longitude, input.latitude],\n\t\t\t\t\t},\n\t\t\t\t\tdistanceField: 'distance',\n\t\t\t\t\tmaxDistance: maxDistance,\n\t\t\t\t\tspherical: true,\n\t\t\t\t\tkey: 'address.location',\n\t\t\t\t\tquery: {\n\t\t\t\t\t\t_id: { $in: shopIds },\n\t\t\t\t\t\tstatus: 'active',\n\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t$project: {\n\t\t\t\t\t_id: 1,\n\t\t\t\t\tname: 1,\n\t\t\t\t\t'address.location': 1,\n\t\t\t\t},\n\t\t\t},\n\t\t]);\n\t}\n\n\tasync create(input: object): Promise<DocumentType<Model>> {\n\t\treturn this.model.create(input);\n\t}\n\tasync updateShopOrderCapacity(\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tisOrderCapacityEnabled: boolean,\n\t\tmaxOrderCapacity?: number\n\t) {\n\t\treturn this.shopModel.findByIdAndUpdate(\n\t\t\tshopId,\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\torderCapacityEnabled: isOrderCapacityEnabled,\n\t\t\t\t\torderCapacity: maxOrderCapacity,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ new: true }\n\t\t);\n\t}\n\tasync findActiveByCampaignAndShop(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId\n\t): Promise<ParticipantSummaryDTO | null> {\n\t\tconst result = await this.model\n\t\t\t.findOne({ campaign: campaignId, shop: shopId, isWithdrawn: false })\n\t\t\t.select(\n\t\t\t\t'discountPercentage maxDiscountCap joinedAt isEntireMenu isOrderCapacityEnabled maxOrderCapacity products marketing'\n\t\t\t)\n\t\t\t.lean();\n\t\tif (!result) return null;\n\t\tconst { products, marketing, ...rest } = result as any;\n\t\treturn { ...rest, productIds: products ?? [], marketingId: marketing };\n\t}\n\n\tasync withdraw(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model> | null> {\n\t\treturn this.model.findOneAndUpdate(\n\t\t\t{ campaign: campaignId, shop: shopId, isWithdrawn: false },\n\t\t\t{ $set: { isWithdrawn: true, withdrawnAt: new Date() } },\n\t\t\t{ new: true }\n\t\t);\n\t}\n\n\tasync existsActiveByCampaignAndShop(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId\n\t): Promise<boolean> {\n\t\treturn !!(await this.model.exists({ campaign: campaignId, shop: shopId, isWithdrawn: false }));\n\t}\n\n\tasync findActiveForUpdate(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId\n\t): Promise<ActiveParticipantMarketingDTO | null> {\n\t\tconst result = await this.model\n\t\t\t.findOne({ campaign: campaignId, shop: shopId, isWithdrawn: false })\n\t\t\t.select('marketing')\n\t\t\t.lean();\n\t\tif (!result) return null;\n\t\treturn { marketingId: (result as any).marketing };\n\t}\n\n\tasync updateParticipant(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tdata: UpdateParticipantDataDTO\n\t): Promise<DocumentType<Model> | null> {\n\t\treturn this.model.findOneAndUpdate(\n\t\t\t{ campaign: campaignId, shop: shopId, isWithdrawn: false },\n\t\t\t{ $set: data },\n\t\t\t{ new: true }\n\t\t);\n\t}\n\n\tasync countShopProducts(\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tproductIds: mongoose.Types.ObjectId[]\n\t): Promise<number> {\n\t\tif (!productIds.length) return 0;\n\t\treturn ProductModel.countDocuments({ _id: { $in: productIds }, shop: shopId, deletedAt: null });\n\t}\n\n\tasync findProductIdsByCategories(\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tcategoryIds: mongoose.Types.ObjectId[]\n\t): Promise<mongoose.Types.ObjectId[]> {\n\t\tif (!categoryIds.length) return [];\n\t\t// Shop-scoped so the {shop, shopCategory} partial index is used; only _id is needed.\n\t\tconst products = await ProductModel.find({\n\t\t\tshop: shopId,\n\t\t\tshopCategory: { $in: categoryIds },\n\t\t\tdeletedAt: null,\n\t\t})\n\t\t\t.select('_id')\n\t\t\t.lean();\n\t\treturn products.map(p => p._id as mongoose.Types.ObjectId);\n\t}\n\n\tasync findMarketingIdsByCampaign(campaignId: mongoose.Types.ObjectId): Promise<mongoose.Types.ObjectId[]> {\n\t\tconst participants = await this.model\n\t\t\t.find({ campaign: campaignId, isWithdrawn: false, marketing: { $exists: true, $ne: null } })\n\t\t\t.select('marketing')\n\t\t\t.lean();\n\t\treturn participants.map(p => p.marketing as mongoose.Types.ObjectId).filter(Boolean);\n\t}\n\n\tasync countNonWithdrawnByCampaign(campaignId: mongoose.Types.ObjectId): Promise<number> {\n\t\treturn this.model.countDocuments({campaign: campaignId, isWithdrawn: false});\n\t}\n\n\tasync findAllActiveByCampaign(campaignId: mongoose.Types.ObjectId): Promise<DocumentType<Model>[]> {\n\t\treturn this.model.find({campaign: campaignId, isWithdrawn: false});\n\t}\n\n\tasync findPausedMarketingIdsByCampaign(\n\t\tcampaignId: mongoose.Types.ObjectId\n\t): Promise<mongoose.Types.ObjectId[]> {\n\t\tconst participants = await this.model\n\t\t\t.find({ campaign: campaignId, isWithdrawn: false, pausedMarketings: { $exists: true, $ne: [] } })\n\t\t\t.select('pausedMarketings')\n\t\t\t.lean();\n\t\treturn participants.flatMap(p => (p.pausedMarketings ?? []) as mongoose.Types.ObjectId[]);\n\t}\n\n\tasync findActiveMarketingIdsByShop(shopId: mongoose.Types.ObjectId, marketingType: MarketingType): Promise<mongoose.Types.ObjectId[]> {\n\t\tconst marketings = await MarketingModel.find({\n\t\t\tshop: shopId,\n\t\t\tmarketingType,\n\t\t\tcampaignType: {\n\t\t\t\t$in: [MarketingCampaignType.STANDARD, null],\n\t\t\t},\n\t\t\tstatus: MarketingStatus.ACTIVE,\n\t\t\tdeletedAt: null,\n\t\t\t'duration.end': {$gt: new Date()},\n\t\t})\n\t\t\t.select('_id')\n\t\t\t.lean();\n\t\treturn marketings.map(m => m._id as mongoose.Types.ObjectId);\n\t}\n\n\tasync findRevivableMarketings(\n\t\tids: mongoose.Types.ObjectId[]\n\t): Promise<Array<{_id: mongoose.Types.ObjectId; shop: mongoose.Types.ObjectId}>> {\n\t\tconst results = await MarketingModel.find({\n\t\t\t_id: {$in: ids},\n\t\t\tstatus: MarketingStatus.PAUSED,\n\t\t\tdeletedAt: null,\n\t\t\t'duration.end': {$gt: new Date()},\n\t\t})\n\t\t\t.select('_id shop')\n\t\t\t.lean();\n\t\treturn results as Array<{_id: mongoose.Types.ObjectId; shop: mongoose.Types.ObjectId}>;\n\t}\n\n\tasync updateMarketingStatus(ids: mongoose.Types.ObjectId[], status: MarketingStatus): Promise<void> {\n\t\tawait MarketingModel.updateMany({_id: {$in: ids}}, {$set: {status}});\n\t}\n\n\tasync findParticipantIdsByCampaignId(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t): Promise<mongoose.Types.ObjectId[]> {\n\t\tconst participants = await this.model\n\t\t\t.find({campaign: campaignId, isWithdrawn: false})\n\t\t\t.select(\"shop\")\n\t\t\t.lean()\n\t\t\t.exec();\n\n\t\treturn participants.map((p) => p.shop as mongoose.Types.ObjectId);\n\t}\n\n\tasync findByCampaign(\n\t\tdto: GetLtoCampaignParticipantsDTO\n\t): Promise<{ documents: LtoCampaignParticipantItemDTO[]; total: number }> {\n\t\tconst filter = LtoParticipantQueryBuilder.buildCampaignFilter(dto);\n\t\tconst search = LtoParticipantQueryBuilder.buildSearchTerm(dto);\n\n\t\tconst [result] = await this.model.aggregate([\n\t\t\t{ $match: filter },\n\t\t\t{\n\t\t\t\t$lookup: {\n\t\t\t\t\tfrom: ShopModel.collection.name,\n\t\t\t\t\tlet: { shopId: '$shop' },\n\t\t\t\t\tpipeline: [\n\t\t\t\t\t\t{ $match: { $expr: { $eq: ['$_id', '$$shopId'] } } },\n\t\t\t\t\t\t{ $project: { name: 1, logo: 1 } },\n\t\t\t\t\t],\n\t\t\t\t\tas: 'shopData',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ $unwind: { path: '$shopData', preserveNullAndEmptyArrays: true } },\n\t\t\t...(search ? [{ $match: { 'shopData.name': { $regex: search, $options: 'i' } } }] : []),\n\t\t\t{ $sort: { joinedAt: -1 } },\n\t\t\t{\n\t\t\t\t$facet: {\n\t\t\t\t\ttotal: [{ $count: 'count' }],\n\t\t\t\t\tdocuments: [\n\t\t\t\t\t\t{ $skip: (dto.page - 1) * dto.size },\n\t\t\t\t\t\t{ $limit: dto.size },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$project: {\n\t\t\t\t\t\t\t\tshopId: '$shopData._id',\n\t\t\t\t\t\t\t\tshopName: { $ifNull: ['$shopData.name', null] },\n\t\t\t\t\t\t\t\tshopPhoto: { $ifNull: ['$shopData.logo', null] },\n\t\t\t\t\t\t\t\tjoinedAt: 1,\n\t\t\t\t\t\t\t\tdiscountPercentage: 1,\n\t\t\t\t\t\t\t\tmaxDiscountCap: 1,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t]);\n\n\t\treturn {\n\t\t\tdocuments: result?.documents ?? [],\n\t\t\ttotal: result?.total?.[0]?.count ?? 0,\n\t\t};\n\t}\n}\n\nexport const ltoParticipantRepository = Container.get(LtoParticipantRepository);\n"]}
|
|
1
|
+
{"version":3,"file":"limited-time-offer-participant.repository.js","sourceRoot":"/","sources":["modules/limited-time-offer/participant/limited-time-offer-participant.repository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA0C;AAE1C,sEAKmD;AAMnD,qGAAoF;AAQ7E,IAAM,wBAAwB,GAA9B,MAAM,wBAAwB;IAC5B,KAAK,CAAmE;IACxE,SAAS,CAAmB;IAEpC;QACC,IAAI,CAAC,KAAK,GAAG,yCACU,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,kBAA6B,CAAC;IAChD,CAAC;IAEM,KAAK,CAAC,UAAU,CACtB,UAAmC,EACnC,KAGC,EACD,WAAmB;QAEnB,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,KAAK;aACnC,IAAI,CAAC;YACL,QAAQ,EAAE,UAAU;YACpB,WAAW,EAAE,KAAK;YAClB,SAAS,EAAE,IAAI;SACf,CAAC;aACD,MAAM,CAAC,MAAM,CAAC;aACd,IAAI,EAAE,CAAC;QAET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C,IAAA,gBAAO,GAAE;;GACG,wBAAwB,CAmOpC;AAEY,QAAA,wBAAwB,GAAG,gBAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC","sourcesContent":["import Container, {Service} from 'typedi';\nimport {DocumentType, mongoose} from '@typegoose/typegoose';\nimport {\n\tLimitedTimeOfferParticipant as Model,\n\tLimitedTimeOfferParticipantModel,\n\tProductModel,\n\tShopModel,\n} from '@lyxa.ai/core/dist/libraries/mongo/models';\nimport {SoftDeleteModel} from '@lyxa.ai/core/dist/libraries/mongo/plugins/soft-delete-plugin';\nimport {\n\tGetLtoCampaignParticipantsDTO,\n\tLtoCampaignParticipantItemDTO,\n} from '../campaign/limited-time-offer-campaign.validation';\nimport {LtoParticipantQueryBuilder} from './limited-time-offer-participant.builder';\nimport {\n\tActiveParticipantMarketingDTO,\n\tParticipantSummaryDTO,\n\tUpdateParticipantDataDTO,\n} from './limited-time-offer-participant.validation';\n\n@Service()\nexport class LtoParticipantRepository {\n\tprivate model: typeof LimitedTimeOfferParticipantModel & SoftDeleteModel<Model>;\n\tprivate shopModel: typeof ShopModel;\n\n\tconstructor() {\n\t\tthis.model = LimitedTimeOfferParticipantModel as typeof LimitedTimeOfferParticipantModel &\n\t\t\tSoftDeleteModel<Model>;\n\t\tthis.shopModel = ShopModel as typeof ShopModel;\n\t}\n\n\tpublic async findNearby(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tinput: {\n\t\t\tlatitude: number;\n\t\t\tlongitude: number;\n\t\t},\n\t\tmaxDistance: number\n\t) {\n\t\tconst participants = await this.model\n\t\t\t.find({\n\t\t\t\tcampaign: campaignId,\n\t\t\t\tisWithdrawn: false,\n\t\t\t\tdeletedAt: null,\n\t\t\t})\n\t\t\t.select('shop')\n\t\t\t.lean();\n\n\t\tif (!participants.length) return [];\n\n\t\tconst shopIds = participants.map(p => p.shop);\n\n\t\treturn this.shopModel.aggregate([\n\t\t\t{\n\t\t\t\t$geoNear: {\n\t\t\t\t\tnear: {\n\t\t\t\t\t\ttype: 'Point',\n\t\t\t\t\t\tcoordinates: [input.longitude, input.latitude],\n\t\t\t\t\t},\n\t\t\t\t\tdistanceField: 'distance',\n\t\t\t\t\tmaxDistance: maxDistance,\n\t\t\t\t\tspherical: true,\n\t\t\t\t\tkey: 'address.location',\n\t\t\t\t\tquery: {\n\t\t\t\t\t\t_id: { $in: shopIds },\n\t\t\t\t\t\tstatus: 'active',\n\t\t\t\t\t\tdeletedAt: null,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t$project: {\n\t\t\t\t\t_id: 1,\n\t\t\t\t\tname: 1,\n\t\t\t\t\t'address.location': 1,\n\t\t\t\t},\n\t\t\t},\n\t\t]);\n\t}\n\n\tasync create(input: object): Promise<DocumentType<Model>> {\n\t\treturn this.model.create(input);\n\t}\n\tasync updateShopOrderCapacity(\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tisOrderCapacityEnabled: boolean,\n\t\tmaxOrderCapacity?: number\n\t) {\n\t\treturn this.shopModel.findByIdAndUpdate(\n\t\t\tshopId,\n\t\t\t{\n\t\t\t\t$set: {\n\t\t\t\t\torderCapacityEnabled: isOrderCapacityEnabled,\n\t\t\t\t\torderCapacity: maxOrderCapacity,\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ new: true }\n\t\t);\n\t}\n\tasync findActiveByCampaignAndShop(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId\n\t): Promise<ParticipantSummaryDTO | null> {\n\t\tconst result = await this.model\n\t\t\t.findOne({ campaign: campaignId, shop: shopId, isWithdrawn: false })\n\t\t\t.select(\n\t\t\t\t'discountPercentage maxDiscountCap joinedAt isEntireMenu isOrderCapacityEnabled maxOrderCapacity products marketing'\n\t\t\t)\n\t\t\t.lean();\n\t\tif (!result) return null;\n\t\tconst { products, marketing, ...rest } = result as any;\n\t\treturn { ...rest, productIds: products ?? [], marketingId: marketing };\n\t}\n\n\tasync withdraw(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId\n\t): Promise<DocumentType<Model> | null> {\n\t\treturn this.model.findOneAndUpdate(\n\t\t\t{ campaign: campaignId, shop: shopId, isWithdrawn: false },\n\t\t\t{ $set: { isWithdrawn: true, withdrawnAt: new Date() } },\n\t\t\t{ new: true }\n\t\t);\n\t}\n\n\tasync existsActiveByCampaignAndShop(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId\n\t): Promise<boolean> {\n\t\treturn !!(await this.model.exists({ campaign: campaignId, shop: shopId, isWithdrawn: false }));\n\t}\n\n\tasync findActiveForUpdate(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId\n\t): Promise<ActiveParticipantMarketingDTO | null> {\n\t\tconst result = await this.model\n\t\t\t.findOne({ campaign: campaignId, shop: shopId, isWithdrawn: false })\n\t\t\t.select('marketing')\n\t\t\t.lean();\n\t\tif (!result) return null;\n\t\treturn { marketingId: (result as any).marketing };\n\t}\n\n\tasync updateParticipant(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tdata: UpdateParticipantDataDTO\n\t): Promise<DocumentType<Model> | null> {\n\t\treturn this.model.findOneAndUpdate(\n\t\t\t{ campaign: campaignId, shop: shopId, isWithdrawn: false },\n\t\t\t{ $set: data },\n\t\t\t{ new: true }\n\t\t);\n\t}\n\n\tasync countShopProducts(\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tproductIds: mongoose.Types.ObjectId[]\n\t): Promise<number> {\n\t\tif (!productIds.length) return 0;\n\t\treturn ProductModel.countDocuments({ _id: { $in: productIds }, shop: shopId, deletedAt: null });\n\t}\n\n\tasync findProductIdsByCategories(\n\t\tshopId: mongoose.Types.ObjectId,\n\t\tcategoryIds: mongoose.Types.ObjectId[]\n\t): Promise<mongoose.Types.ObjectId[]> {\n\t\tif (!categoryIds.length) return [];\n\t\t// Shop-scoped so the {shop, shopCategory} partial index is used; only _id is needed.\n\t\tconst products = await ProductModel.find({\n\t\t\tshop: shopId,\n\t\t\tshopCategory: { $in: categoryIds },\n\t\t\tdeletedAt: null,\n\t\t})\n\t\t\t.select('_id')\n\t\t\t.lean();\n\t\treturn products.map(p => p._id as mongoose.Types.ObjectId);\n\t}\n\n\tasync findMarketingIdsByCampaign(campaignId: mongoose.Types.ObjectId): Promise<mongoose.Types.ObjectId[]> {\n\t\tconst participants = await this.model\n\t\t\t.find({ campaign: campaignId, isWithdrawn: false, marketing: { $exists: true, $ne: null } })\n\t\t\t.select('marketing')\n\t\t\t.lean();\n\t\treturn participants.map(p => p.marketing as mongoose.Types.ObjectId).filter(Boolean);\n\t}\n\n\tasync findParticipantIdsByCampaignId(\n\t\tcampaignId: mongoose.Types.ObjectId,\n\t): Promise<mongoose.Types.ObjectId[]> {\n\t\tconst participants = await this.model\n\t\t\t.find({campaign: campaignId, isWithdrawn: false})\n\t\t\t.select(\"shop\")\n\t\t\t.lean()\n\t\t\t.exec();\n\n\t\treturn participants.map((p) => p.shop as mongoose.Types.ObjectId);\n\t}\n\n\tasync findByCampaign(\n\t\tdto: GetLtoCampaignParticipantsDTO\n\t): Promise<{ documents: LtoCampaignParticipantItemDTO[]; total: number }> {\n\t\tconst filter = LtoParticipantQueryBuilder.buildCampaignFilter(dto);\n\t\tconst search = LtoParticipantQueryBuilder.buildSearchTerm(dto);\n\n\t\tconst [result] = await this.model.aggregate([\n\t\t\t{ $match: filter },\n\t\t\t{\n\t\t\t\t$lookup: {\n\t\t\t\t\tfrom: ShopModel.collection.name,\n\t\t\t\t\tlet: { shopId: '$shop' },\n\t\t\t\t\tpipeline: [\n\t\t\t\t\t\t{ $match: { $expr: { $eq: ['$_id', '$$shopId'] } } },\n\t\t\t\t\t\t{ $project: { name: 1, logo: 1 } },\n\t\t\t\t\t],\n\t\t\t\t\tas: 'shopData',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{ $unwind: { path: '$shopData', preserveNullAndEmptyArrays: true } },\n\t\t\t...(search ? [{ $match: { 'shopData.name': { $regex: search, $options: 'i' } } }] : []),\n\t\t\t{ $sort: { joinedAt: -1 } },\n\t\t\t{\n\t\t\t\t$facet: {\n\t\t\t\t\ttotal: [{ $count: 'count' }],\n\t\t\t\t\tdocuments: [\n\t\t\t\t\t\t{ $skip: (dto.page - 1) * dto.size },\n\t\t\t\t\t\t{ $limit: dto.size },\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$project: {\n\t\t\t\t\t\t\t\tshopId: '$shopData._id',\n\t\t\t\t\t\t\t\tshopName: { $ifNull: ['$shopData.name', null] },\n\t\t\t\t\t\t\t\tshopPhoto: { $ifNull: ['$shopData.logo', null] },\n\t\t\t\t\t\t\t\tjoinedAt: 1,\n\t\t\t\t\t\t\t\tdiscountPercentage: 1,\n\t\t\t\t\t\t\t\tmaxDiscountCap: 1,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t]);\n\n\t\treturn {\n\t\t\tdocuments: result?.documents ?? [],\n\t\t\ttotal: result?.total?.[0]?.count ?? 0,\n\t\t};\n\t}\n}\n\nexport const ltoParticipantRepository = Container.get(LtoParticipantRepository);\n"]}
|
package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.d.ts
CHANGED
|
@@ -192,130 +192,6 @@ export declare const participantRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
192
192
|
};
|
|
193
193
|
meta: object;
|
|
194
194
|
}>;
|
|
195
|
-
enrollShops: import("@trpc/server").TRPCMutationProcedure<{
|
|
196
|
-
input: {
|
|
197
|
-
shops: {
|
|
198
|
-
isEntireMenu: boolean;
|
|
199
|
-
shopId: string | mongoose.Types.ObjectId;
|
|
200
|
-
discountPercentage: number;
|
|
201
|
-
maxDiscountCap: number;
|
|
202
|
-
isOrderCapacityEnabled: boolean;
|
|
203
|
-
products?: (string | mongoose.Types.ObjectId)[] | undefined;
|
|
204
|
-
maxOrderCapacity?: number | undefined;
|
|
205
|
-
shopCategories?: (string | mongoose.Types.ObjectId)[] | undefined;
|
|
206
|
-
}[];
|
|
207
|
-
};
|
|
208
|
-
output: {
|
|
209
|
-
message: string;
|
|
210
|
-
success: boolean;
|
|
211
|
-
data?: {
|
|
212
|
-
_id: string | mongoose.Types.ObjectId;
|
|
213
|
-
shop: string | mongoose.Types.ObjectId;
|
|
214
|
-
isEntireMenu: boolean;
|
|
215
|
-
joinedAt: Date;
|
|
216
|
-
campaign: string | mongoose.Types.ObjectId;
|
|
217
|
-
isOrderCapacityEnabled: boolean;
|
|
218
|
-
isWithdrawn: boolean;
|
|
219
|
-
createdAt?: Date | null | undefined;
|
|
220
|
-
updatedAt?: Date | null | undefined;
|
|
221
|
-
products?: (string | mongoose.Types.ObjectId)[] | undefined;
|
|
222
|
-
discountPercentage?: number | undefined;
|
|
223
|
-
maxDiscountCap?: number | undefined;
|
|
224
|
-
maxOrderCapacity?: number | undefined;
|
|
225
|
-
withdrawnAt?: Date | null | undefined;
|
|
226
|
-
}[] | {
|
|
227
|
-
documents: {
|
|
228
|
-
_id: string | mongoose.Types.ObjectId;
|
|
229
|
-
shop: string | mongoose.Types.ObjectId;
|
|
230
|
-
isEntireMenu: boolean;
|
|
231
|
-
joinedAt: Date;
|
|
232
|
-
campaign: string | mongoose.Types.ObjectId;
|
|
233
|
-
isOrderCapacityEnabled: boolean;
|
|
234
|
-
isWithdrawn: boolean;
|
|
235
|
-
createdAt?: Date | null | undefined;
|
|
236
|
-
updatedAt?: Date | null | undefined;
|
|
237
|
-
products?: (string | mongoose.Types.ObjectId)[] | undefined;
|
|
238
|
-
discountPercentage?: number | undefined;
|
|
239
|
-
maxDiscountCap?: number | undefined;
|
|
240
|
-
maxOrderCapacity?: number | undefined;
|
|
241
|
-
withdrawnAt?: Date | null | undefined;
|
|
242
|
-
}[][];
|
|
243
|
-
metadata?: {
|
|
244
|
-
page: number;
|
|
245
|
-
size: number;
|
|
246
|
-
totalElements: number;
|
|
247
|
-
totalPages: number;
|
|
248
|
-
} | undefined;
|
|
249
|
-
} | undefined;
|
|
250
|
-
};
|
|
251
|
-
meta: object;
|
|
252
|
-
}>;
|
|
253
|
-
updateShop: import("@trpc/server").TRPCMutationProcedure<{
|
|
254
|
-
input: {
|
|
255
|
-
isEntireMenu: boolean;
|
|
256
|
-
shopId: string | mongoose.Types.ObjectId;
|
|
257
|
-
discountPercentage: number;
|
|
258
|
-
maxDiscountCap: number;
|
|
259
|
-
isOrderCapacityEnabled: boolean;
|
|
260
|
-
products?: (string | mongoose.Types.ObjectId)[] | undefined;
|
|
261
|
-
maxOrderCapacity?: number | undefined;
|
|
262
|
-
shopCategories?: (string | mongoose.Types.ObjectId)[] | undefined;
|
|
263
|
-
};
|
|
264
|
-
output: {
|
|
265
|
-
message: string;
|
|
266
|
-
success: boolean;
|
|
267
|
-
data?: {
|
|
268
|
-
_id: string | mongoose.Types.ObjectId;
|
|
269
|
-
shop: string | mongoose.Types.ObjectId;
|
|
270
|
-
isEntireMenu: boolean;
|
|
271
|
-
joinedAt: Date;
|
|
272
|
-
campaign: string | mongoose.Types.ObjectId;
|
|
273
|
-
isOrderCapacityEnabled: boolean;
|
|
274
|
-
isWithdrawn: boolean;
|
|
275
|
-
createdAt?: Date | null | undefined;
|
|
276
|
-
updatedAt?: Date | null | undefined;
|
|
277
|
-
products?: (string | mongoose.Types.ObjectId)[] | undefined;
|
|
278
|
-
discountPercentage?: number | undefined;
|
|
279
|
-
maxDiscountCap?: number | undefined;
|
|
280
|
-
maxOrderCapacity?: number | undefined;
|
|
281
|
-
withdrawnAt?: Date | null | undefined;
|
|
282
|
-
} | {
|
|
283
|
-
documents: {
|
|
284
|
-
_id: string | mongoose.Types.ObjectId;
|
|
285
|
-
shop: string | mongoose.Types.ObjectId;
|
|
286
|
-
isEntireMenu: boolean;
|
|
287
|
-
joinedAt: Date;
|
|
288
|
-
campaign: string | mongoose.Types.ObjectId;
|
|
289
|
-
isOrderCapacityEnabled: boolean;
|
|
290
|
-
isWithdrawn: boolean;
|
|
291
|
-
createdAt?: Date | null | undefined;
|
|
292
|
-
updatedAt?: Date | null | undefined;
|
|
293
|
-
products?: (string | mongoose.Types.ObjectId)[] | undefined;
|
|
294
|
-
discountPercentage?: number | undefined;
|
|
295
|
-
maxDiscountCap?: number | undefined;
|
|
296
|
-
maxOrderCapacity?: number | undefined;
|
|
297
|
-
withdrawnAt?: Date | null | undefined;
|
|
298
|
-
}[];
|
|
299
|
-
metadata?: {
|
|
300
|
-
page: number;
|
|
301
|
-
size: number;
|
|
302
|
-
totalElements: number;
|
|
303
|
-
totalPages: number;
|
|
304
|
-
} | undefined;
|
|
305
|
-
} | undefined;
|
|
306
|
-
};
|
|
307
|
-
meta: object;
|
|
308
|
-
}>;
|
|
309
|
-
withdrawShop: import("@trpc/server").TRPCMutationProcedure<{
|
|
310
|
-
input: {
|
|
311
|
-
shopId: string | mongoose.Types.ObjectId;
|
|
312
|
-
};
|
|
313
|
-
output: {
|
|
314
|
-
message: string;
|
|
315
|
-
success: boolean;
|
|
316
|
-
};
|
|
317
|
-
meta: object;
|
|
318
|
-
}>;
|
|
319
195
|
getParticipants: import("@trpc/server").TRPCQueryProcedure<{
|
|
320
196
|
input: {
|
|
321
197
|
campaignId: string | mongoose.Types.ObjectId;
|
|
@@ -330,78 +206,17 @@ export declare const participantRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
330
206
|
shopId: string | mongoose.Types.ObjectId;
|
|
331
207
|
joinedAt: Date;
|
|
332
208
|
shopName: string | null;
|
|
333
|
-
shopPhoto?: string | null | undefined;
|
|
334
209
|
discountPercentage?: number | undefined;
|
|
335
210
|
maxDiscountCap?: number | undefined;
|
|
211
|
+
shopPhoto?: string | null | undefined;
|
|
336
212
|
} | {
|
|
337
213
|
documents: {
|
|
338
214
|
shopId: string | mongoose.Types.ObjectId;
|
|
339
215
|
joinedAt: Date;
|
|
340
216
|
shopName: string | null;
|
|
341
|
-
shopPhoto?: string | null | undefined;
|
|
342
217
|
discountPercentage?: number | undefined;
|
|
343
218
|
maxDiscountCap?: number | undefined;
|
|
344
|
-
|
|
345
|
-
metadata?: {
|
|
346
|
-
page: number;
|
|
347
|
-
size: number;
|
|
348
|
-
totalElements: number;
|
|
349
|
-
totalPages: number;
|
|
350
|
-
} | undefined;
|
|
351
|
-
} | undefined;
|
|
352
|
-
};
|
|
353
|
-
meta: object;
|
|
354
|
-
}>;
|
|
355
|
-
getParticipantByShop: import("@trpc/server").TRPCQueryProcedure<{
|
|
356
|
-
input: {
|
|
357
|
-
shopId: string | mongoose.Types.ObjectId;
|
|
358
|
-
};
|
|
359
|
-
output: {
|
|
360
|
-
message: string;
|
|
361
|
-
success: boolean;
|
|
362
|
-
data?: {
|
|
363
|
-
campaignState: import("./limited-time-offer-participant.validation").LtoCardState;
|
|
364
|
-
campaign?: {
|
|
365
|
-
_id: string | mongoose.Types.ObjectId;
|
|
366
|
-
startDate?: Date | null | undefined;
|
|
367
|
-
endDate?: Date | null | undefined;
|
|
368
|
-
title?: string | undefined;
|
|
369
|
-
subTitle?: string | undefined;
|
|
370
|
-
discountOptions?: number[] | undefined;
|
|
371
|
-
maxDiscountCaps?: number[] | undefined;
|
|
372
|
-
} | undefined;
|
|
373
|
-
participant?: {
|
|
374
|
-
isEntireMenu: boolean;
|
|
375
|
-
joinedAt: Date;
|
|
376
|
-
isOrderCapacityEnabled: boolean;
|
|
377
|
-
productIds?: (string | mongoose.Types.ObjectId)[] | undefined;
|
|
378
|
-
marketingId?: string | mongoose.Types.ObjectId | undefined;
|
|
379
|
-
discountPercentage?: number | undefined;
|
|
380
|
-
maxDiscountCap?: number | undefined;
|
|
381
|
-
maxOrderCapacity?: number | undefined;
|
|
382
|
-
} | undefined;
|
|
383
|
-
} | {
|
|
384
|
-
documents: {
|
|
385
|
-
campaignState: import("./limited-time-offer-participant.validation").LtoCardState;
|
|
386
|
-
campaign?: {
|
|
387
|
-
_id: string | mongoose.Types.ObjectId;
|
|
388
|
-
startDate?: Date | null | undefined;
|
|
389
|
-
endDate?: Date | null | undefined;
|
|
390
|
-
title?: string | undefined;
|
|
391
|
-
subTitle?: string | undefined;
|
|
392
|
-
discountOptions?: number[] | undefined;
|
|
393
|
-
maxDiscountCaps?: number[] | undefined;
|
|
394
|
-
} | undefined;
|
|
395
|
-
participant?: {
|
|
396
|
-
isEntireMenu: boolean;
|
|
397
|
-
joinedAt: Date;
|
|
398
|
-
isOrderCapacityEnabled: boolean;
|
|
399
|
-
productIds?: (string | mongoose.Types.ObjectId)[] | undefined;
|
|
400
|
-
marketingId?: string | mongoose.Types.ObjectId | undefined;
|
|
401
|
-
discountPercentage?: number | undefined;
|
|
402
|
-
maxDiscountCap?: number | undefined;
|
|
403
|
-
maxOrderCapacity?: number | undefined;
|
|
404
|
-
} | undefined;
|
|
219
|
+
shopPhoto?: string | null | undefined;
|
|
405
220
|
}[];
|
|
406
221
|
metadata?: {
|
|
407
222
|
page: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limited-time-offer-participant.router.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/participant/limited-time-offer-participant.router.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"limited-time-offer-participant.router.d.ts","sourceRoot":"/","sources":["modules/limited-time-offer/participant/limited-time-offer-participant.router.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAY9C,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgD5B,CAAC"}
|
package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js
CHANGED
|
@@ -46,28 +46,6 @@ exports.participantRouter = (0, trpc_1.createTRPCRouter)({
|
|
|
46
46
|
const result = await limited_time_offer_participant_service_1.ltoParticipantService.getStatus(resolveShopId(ctx));
|
|
47
47
|
return (0, response_1.response)('Status fetched successfully', result);
|
|
48
48
|
})),
|
|
49
|
-
enrollShops: crmProcedure
|
|
50
|
-
.input(limited_time_offer_participant_validation_1.AdminEnrollShopsSchema)
|
|
51
|
-
.output(limited_time_offer_participant_validation_1.AdminJoinParticipantsResponseSchema)
|
|
52
|
-
.mutation(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
53
|
-
const results = await limited_time_offer_participant_service_1.ltoParticipantService.enrollShops(input.shops);
|
|
54
|
-
return (0, response_1.response)('Successfully joined the campaign', results);
|
|
55
|
-
})),
|
|
56
|
-
updateShop: crmProcedure
|
|
57
|
-
.input(limited_time_offer_participant_validation_1.AdminUpdateShopSchema)
|
|
58
|
-
.output(limited_time_offer_participant_validation_1.ParticipantResponseSchema)
|
|
59
|
-
.mutation(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
60
|
-
const { shopId, ...dto } = input;
|
|
61
|
-
const result = await limited_time_offer_participant_service_1.ltoParticipantService.update(shopId, dto);
|
|
62
|
-
return (0, response_1.response)('Participation updated successfully', result);
|
|
63
|
-
})),
|
|
64
|
-
withdrawShop: crmProcedure
|
|
65
|
-
.input(limited_time_offer_participant_validation_1.AdminWithdrawShopSchema)
|
|
66
|
-
.output(limited_time_offer_campaign_validation_1.LtoEmptyResponseSchema)
|
|
67
|
-
.mutation(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
68
|
-
await limited_time_offer_participant_service_1.ltoParticipantService.withdraw(input.shopId);
|
|
69
|
-
return (0, response_1.response)('Successfully withdrawn from the campaign');
|
|
70
|
-
})),
|
|
71
49
|
getParticipants: crmProcedure
|
|
72
50
|
.input(limited_time_offer_campaign_validation_1.GetLtoCampaignParticipantsSchema)
|
|
73
51
|
.output(limited_time_offer_campaign_validation_1.LtoCampaignParticipantsResponseSchema)
|
|
@@ -75,12 +53,5 @@ exports.participantRouter = (0, trpc_1.createTRPCRouter)({
|
|
|
75
53
|
const result = await limited_time_offer_participant_service_1.ltoParticipantService.getParticipants(input);
|
|
76
54
|
return (0, response_1.response)('Participants fetched successfully', result);
|
|
77
55
|
})),
|
|
78
|
-
getParticipantByShop: crmProcedure
|
|
79
|
-
.input(limited_time_offer_participant_validation_1.AdminGetParticipantByShopSchema)
|
|
80
|
-
.output(limited_time_offer_participant_validation_1.ParticipantStatusResponseSchema)
|
|
81
|
-
.query(async ({ input }) => error_handler_1.ErrorHandler.wrapAsync(async () => {
|
|
82
|
-
const result = await limited_time_offer_participant_service_1.ltoParticipantService.getStatus(input.shopId);
|
|
83
|
-
return (0, response_1.response)('Status fetched successfully', result);
|
|
84
|
-
})),
|
|
85
56
|
});
|
|
86
57
|
//# sourceMappingURL=limited-time-offer-participant.router.js.map
|
package/dist/lib/modules/limited-time-offer/participant/limited-time-offer-participant.router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"limited-time-offer-participant.router.js","sourceRoot":"/","sources":["modules/limited-time-offer/participant/limited-time-offer-participant.router.ts"],"names":[],"mappings":";;;AAAA,4DAAmE;AACnE,4DAAiE;AACjE,6EAAgG;AAChG,8EAAwE;AACxE,oEAA+D;AAC/D,8GAAmG;AACnG,
|
|
1
|
+
{"version":3,"file":"limited-time-offer-participant.router.js","sourceRoot":"/","sources":["modules/limited-time-offer/participant/limited-time-offer-participant.router.ts"],"names":[],"mappings":";;;AAAA,4DAAmE;AACnE,4DAAiE;AACjE,6EAAgG;AAChG,8EAAwE;AACxE,oEAA+D;AAC/D,8GAAmG;AACnG,2GAIqD;AACrD,+GAI4D;AAC5D,oDAA8C;AAC9C,4EAA0E;AAE1E,MAA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{createTRPCRouter} from '@lyxa.ai/core/dist/libraries/trpc';\nimport {AuthEntityType} from '@lyxa.ai/core/dist/libraries/auth';\nimport {createAuthenticatedProcedure} from '@lyxa.ai/core/dist/libraries/trpc/middlewares/auth';\nimport {ErrorHandler} from '@lyxa.ai/core/dist/utilities/error-handler';\nimport {response} from '@lyxa.ai/core/dist/utilities/response';\nimport {ltoParticipantService as service} from './services/limited-time-offer-participant.service';\nimport {\n JoinLtoCampaignSchema,\n ParticipantResponseSchema,\n ParticipantStatusResponseSchema,\n} from './limited-time-offer-participant.validation';\nimport {\n GetLtoCampaignParticipantsSchema,\n LtoCampaignParticipantsResponseSchema,\n LtoEmptyResponseSchema,\n} from '../campaign/limited-time-offer-campaign.validation';\nimport {mongoose} from '@typegoose/typegoose';\nimport {badRequestError} from '@lyxa.ai/core/dist/utilities/error-common';\n\nconst sellerProcedure = createAuthenticatedProcedure({entityTypes: [AuthEntityType.SELLER]});\nconst crmProcedure = createAuthenticatedProcedure({entityTypes: [AuthEntityType.CRM]});\n\nfunction resolveShopId(ctx: { entity?: { parameters?: Record<string, unknown> } | null }): mongoose.Types.ObjectId {\n const shops = ctx.entity?.parameters?.shops as string[] | undefined;\n if (!shops || shops.length === 0) throw badRequestError('No shop associated with this account');\n return new mongoose.Types.ObjectId(shops[0]);\n}\n\nexport const participantRouter = createTRPCRouter({\n join: sellerProcedure\n .input(JoinLtoCampaignSchema)\n .output(ParticipantResponseSchema)\n .mutation(async ({input, ctx}) =>\n ErrorHandler.wrapAsync(async () => {\n const result = await service.join(resolveShopId(ctx), input);\n return response('Successfully joined the campaign', result as any);\n })\n ),\n\n update: sellerProcedure\n .input(JoinLtoCampaignSchema)\n .output(ParticipantResponseSchema)\n .mutation(async ({input, ctx}) =>\n ErrorHandler.wrapAsync(async () => {\n const result = await service.update(resolveShopId(ctx), input);\n return response('Participation updated successfully', result as any);\n })\n ),\n\n withdraw: sellerProcedure\n .output(LtoEmptyResponseSchema)\n .mutation(async ({ctx}) =>\n ErrorHandler.wrapAsync(async () => {\n await service.withdraw(resolveShopId(ctx));\n return response('Successfully withdrawn from the campaign');\n })\n ),\n\n getStatus: sellerProcedure\n .output(ParticipantStatusResponseSchema)\n .query(async ({ctx}) =>\n ErrorHandler.wrapAsync(async () => {\n const result = await service.getStatus(resolveShopId(ctx));\n return response('Status fetched successfully', result);\n })\n ),\n\n getParticipants: crmProcedure\n .input(GetLtoCampaignParticipantsSchema)\n .output(LtoCampaignParticipantsResponseSchema)\n .query(async ({input}) =>\n ErrorHandler.wrapAsync(async () => {\n const result = await service.getParticipants(input);\n return response('Participants fetched successfully', result);\n })\n ),\n});\n"]}
|