@timardex/cluemart-server-shared 2.0.2 → 2.1.0
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/{chunk-IICIHY26.mjs → chunk-BEUTBR4H.mjs} +22 -9
- package/dist/chunk-BEUTBR4H.mjs.map +1 -0
- package/dist/index.cjs +134 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.mjs +132 -42
- package/dist/index.mjs.map +1 -1
- package/dist/mongoose/index.cjs +21 -8
- package/dist/mongoose/index.cjs.map +1 -1
- package/dist/mongoose/index.mjs +1 -1
- package/dist/service/index.cjs +134 -43
- package/dist/service/index.cjs.map +1 -1
- package/dist/service/index.d.mts +10 -2
- package/dist/service/index.d.ts +10 -2
- package/dist/service/index.mjs +112 -35
- package/dist/service/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/chunk-IICIHY26.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1158,7 +1158,15 @@ declare function sendDeactivationNotification(payload: {
|
|
|
1158
1158
|
*/
|
|
1159
1159
|
declare function processUserCompliance(user: SchemaUserType, now: dayjs.Dayjs): Promise<void>;
|
|
1160
1160
|
|
|
1161
|
-
declare function
|
|
1161
|
+
declare function downgradeVendorProFeatures(userId: ObjectId, licenceType: EnumUserLicence): Promise<void>;
|
|
1162
|
+
/**
|
|
1163
|
+
* Restores the PRO vendor features that are removed by
|
|
1164
|
+
* downgradeVendorProFeatures when a vendor is downgraded to STANDARD_VENDOR.
|
|
1165
|
+
* This is the opposite operation: it re-enables availability, products and
|
|
1166
|
+
* calendar from the pre-downgrade snapshot (falling back to fully enabled when
|
|
1167
|
+
* no snapshot exists), and keeps all images active.
|
|
1168
|
+
*/
|
|
1169
|
+
declare function restoreVendorProFeatures(userId: ObjectId, licenceType: EnumUserLicence): Promise<void>;
|
|
1162
1170
|
declare const vendorLicences: EnumUserLicence[];
|
|
1163
1171
|
/**
|
|
1164
1172
|
* Handles vendor licence compliance for a single user
|
|
@@ -1315,4 +1323,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
|
|
|
1315
1323
|
resourceType: EnumResourceType;
|
|
1316
1324
|
}): Promise<void>;
|
|
1317
1325
|
|
|
1318
|
-
export { ACTIVE_NOT_DELETED_FILTER, APP_SETTINGS_ID, AdModel, AffiliateModel, AppSettingModel, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, EnumPubSubEvents, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, LicenceCategory, LicenceExpiryDate, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, didRemoveAnyEventDates, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, resourceRelationsSchema, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus,
|
|
1326
|
+
export { ACTIVE_NOT_DELETED_FILTER, APP_SETTINGS_ID, AdModel, AffiliateModel, AppSettingModel, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, EnumPubSubEvents, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, LicenceCategory, LicenceExpiryDate, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, didRemoveAnyEventDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, resourceRelationsSchema, restoreVendorProFeatures, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, upgradeUserToLicence, userLicenseSchema, vendorLicences, vendorOwnerHasProLicence, vendorProductTypeSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1158,7 +1158,15 @@ declare function sendDeactivationNotification(payload: {
|
|
|
1158
1158
|
*/
|
|
1159
1159
|
declare function processUserCompliance(user: SchemaUserType, now: dayjs.Dayjs): Promise<void>;
|
|
1160
1160
|
|
|
1161
|
-
declare function
|
|
1161
|
+
declare function downgradeVendorProFeatures(userId: ObjectId, licenceType: EnumUserLicence): Promise<void>;
|
|
1162
|
+
/**
|
|
1163
|
+
* Restores the PRO vendor features that are removed by
|
|
1164
|
+
* downgradeVendorProFeatures when a vendor is downgraded to STANDARD_VENDOR.
|
|
1165
|
+
* This is the opposite operation: it re-enables availability, products and
|
|
1166
|
+
* calendar from the pre-downgrade snapshot (falling back to fully enabled when
|
|
1167
|
+
* no snapshot exists), and keeps all images active.
|
|
1168
|
+
*/
|
|
1169
|
+
declare function restoreVendorProFeatures(userId: ObjectId, licenceType: EnumUserLicence): Promise<void>;
|
|
1162
1170
|
declare const vendorLicences: EnumUserLicence[];
|
|
1163
1171
|
/**
|
|
1164
1172
|
* Handles vendor licence compliance for a single user
|
|
@@ -1315,4 +1323,4 @@ declare function checkOwnerHasLicence({ userId, resourceType, }: {
|
|
|
1315
1323
|
resourceType: EnumResourceType;
|
|
1316
1324
|
}): Promise<void>;
|
|
1317
1325
|
|
|
1318
|
-
export { ACTIVE_NOT_DELETED_FILTER, APP_SETTINGS_ID, AdModel, AffiliateModel, AppSettingModel, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, EnumPubSubEvents, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, LicenceCategory, LicenceExpiryDate, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, didRemoveAnyEventDates, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, resourceRelationsSchema, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus,
|
|
1326
|
+
export { ACTIVE_NOT_DELETED_FILTER, APP_SETTINGS_ID, AdModel, AffiliateModel, AppSettingModel, type AuthUser, type AwardAffiliateVendorSubscriptionRewardsResult, BILLING_CATALOG_COLLECTION_NAME, BillingCatalogModel, CategorySchema, ChatModel, ChatReportModel, ContactDetailsSchema, type CouponDocument, CouponModel, EnumPubSubEvents, EventInfoModel, EventModel, GameModel, GoogleImportedMarketModel, type GraphQLContext, LicenceCategory, LicenceExpiryDate, NotificationModel, type NotificationPubSub, type ObjectId, OwnerTypeSchema, PartnerModel, PostModel, PushTokenModel, REMINDER_WINDOW_MAX_HOURS, REMINDER_WINDOW_MIN_HOURS, RelationModel, RelationTypeSchema, ResourceActivityModel, ResourceImageTypeSchema, SUBSCRIPTION_REWARD_TIMEZONE, type SchemaAffiliateResourceType, type SchemaAffiliateReward, type SchemaBillingCatalogEntry, type SchemaBillingCatalogPriceHistoryEntry, type SchemaChatMessageReactionType, type SchemaChatMessageReplyPreviewType, type SchemaChatMessageSeenType, type SchemaChatMessageType, type SchemaChatReportType, type SchemaChatType, type SchemaCreateBulkNotificationInput, type SchemaEventInfoType, type SchemaEventType, type SchemaGameType, type SchemaGoogleImportedMarket, type SchemaNotificationType, type SchemaOwnerType, type SchemaParticipantType, type SchemaPartnerType, type SchemaPostType, type SchemaPushTokenType, type SchemaRelatedPostType, type SchemaRelationType, type SchemaStripeSubscription, type SchemaUnregisteredVendorInvitationType, type SchemaUnregisteredVendorType, type SchemaUserActivityEvent, type SchemaUserType, type SchemaVendorInfoType, type SchemaVendorType, SchoolModel, SocialMediaTypeSchema, StallTypeSchema, type SubscriptionPayload, UnregisteredVendorModel, UserModel, VendorInfoModel, VendorModel, VerificationTokenModel, type VerificationTokenType, activeAffiliateCodeExists, awardAffiliateVendorSubscriptionRewards, baseResourceFields, buildInitialBillingCatalogEntries, buildLicenceExpiryPipeline, checkOwnerHasLicence, connectToDatabase, convertObjectIdsToStrings, createLicenceObject, dateTimeSchema, didRemoveAnyEventDates, downgradeVendorProFeatures, ensureUserLicenseCompliance, ensureUserLicenseComplianceForUser, eventLicences, findAffiliateByPromoCode, findEventOrImportedMarketById, getBillingCatalogDefinition, getEventResourceInfo, getHighestLicenceForCategory, getLicenceCategory, getLicenceExpiryMode, getPartnerResourceInfo, getPayingEventStripeSubscriptionPlan, getPayingStripeSubscriptionPlan, getPayingVendorStripeSubscriptionPlan, getSubscriptionRewardPeriodBounds, getVendorResourceInfo, handleEventLicenceCompliance, handlePartnerLicenceCompliance, handleVendorLicenceCompliance, hasValidLicence, isStandardLicence, isValidObjectId, licenceCategoryMapping, licencePriority, locationGeoSchema, locationsSchema, mapVendorLicenceToSubscriptionRewardType, normalizeAffiliatePromoCodes, normalizePromoCode, notifyUsers, partnerLicences, processLicenseReminder, processUserCompliance, processUserLicenseReminders, publishNotificationEvents, refundPolicySchema, relatedPostSchema, relationDatesSchema, remindUsersAboutLicenseExpiration, replaceUserLicenceWithObject, resourceRelationsSchema, restoreVendorProFeatures, saveNotificationsInDb, sendDeactivationNotification, sendLicenseReminder, sendPushNotifications, sendReminderSafely, socialShareResourceSchema, syncUserLicencesAfterExpiry, termsAgreementSchema, updateAdStatuses, updateAllEventDateTimeStatuses, updateRelationDatesToUnavailable, updateSingleDateTimeStatus, upgradeUserToLicence, userLicenseSchema, vendorLicences, vendorOwnerHasProLicence, vendorProductTypeSchema };
|
package/dist/index.mjs
CHANGED
|
@@ -1417,15 +1417,27 @@ var calendarWrapperSchema = new MongooseSchema14(
|
|
|
1417
1417
|
},
|
|
1418
1418
|
{ _id: false }
|
|
1419
1419
|
);
|
|
1420
|
+
var vendorAvailabilitySchema = new MongooseSchema14(
|
|
1421
|
+
{
|
|
1422
|
+
corporate: { default: false, required: false, type: Boolean },
|
|
1423
|
+
private: { default: false, required: false, type: Boolean },
|
|
1424
|
+
school: { default: false, required: false, type: Boolean }
|
|
1425
|
+
},
|
|
1426
|
+
{ _id: false }
|
|
1427
|
+
);
|
|
1428
|
+
var downgradeSnapshotSchema = new MongooseSchema14(
|
|
1429
|
+
{
|
|
1430
|
+
availability: { required: false, type: vendorAvailabilitySchema },
|
|
1431
|
+
calendarActive: { required: false, type: Boolean },
|
|
1432
|
+
productsActive: { required: false, type: Boolean }
|
|
1433
|
+
},
|
|
1434
|
+
{ _id: false }
|
|
1435
|
+
);
|
|
1420
1436
|
var schema10 = new MongooseSchema14(
|
|
1421
1437
|
{
|
|
1422
1438
|
...baseResourceFields,
|
|
1423
1439
|
// Importing base resource fields from global.ts
|
|
1424
|
-
availability: {
|
|
1425
|
-
corporate: { default: false, required: false, type: Boolean },
|
|
1426
|
-
private: { default: false, required: false, type: Boolean },
|
|
1427
|
-
school: { default: false, required: false, type: Boolean }
|
|
1428
|
-
},
|
|
1440
|
+
availability: { required: false, type: vendorAvailabilitySchema },
|
|
1429
1441
|
calendar: {
|
|
1430
1442
|
required: false,
|
|
1431
1443
|
type: calendarWrapperSchema
|
|
@@ -1433,6 +1445,7 @@ var schema10 = new MongooseSchema14(
|
|
|
1433
1445
|
categories: { required: true, type: [CategorySchema] },
|
|
1434
1446
|
categoriesNames: { default: [], required: false, type: [String] },
|
|
1435
1447
|
claimed: { default: true, required: false, type: Boolean },
|
|
1448
|
+
downgradeSnapshot: { required: false, type: downgradeSnapshotSchema },
|
|
1436
1449
|
foodTruck: { required: true, type: Boolean },
|
|
1437
1450
|
products: { required: false, type: productWrapperSchema },
|
|
1438
1451
|
relations: {
|
|
@@ -1465,11 +1478,11 @@ schema10.index({ region: 1 });
|
|
|
1465
1478
|
schema10.index({ "categories.name": 1 });
|
|
1466
1479
|
schema10.index({ slug: 1 });
|
|
1467
1480
|
schema10.index({
|
|
1468
|
-
|
|
1481
|
+
categoriesNames: "text",
|
|
1469
1482
|
description: "text",
|
|
1470
|
-
|
|
1483
|
+
name: "text"
|
|
1471
1484
|
});
|
|
1472
|
-
schema10.index({ "owner.userId": 1
|
|
1485
|
+
schema10.index({ deletedAt: 1, "owner.userId": 1 });
|
|
1473
1486
|
schema10.plugin(searchNamePlugin);
|
|
1474
1487
|
var VendorModel = mongoose14.models.Vendor || mongoose14.model("Vendor", schema10);
|
|
1475
1488
|
|
|
@@ -3423,42 +3436,118 @@ async function checkOwnerHasLicence({
|
|
|
3423
3436
|
}
|
|
3424
3437
|
|
|
3425
3438
|
// src/service/license/compliance/vendor.ts
|
|
3426
|
-
async function
|
|
3439
|
+
async function findUserVendor(userId, logLabel) {
|
|
3440
|
+
const user = await UserModel.findById(userId).select("vendor").lean().exec();
|
|
3441
|
+
if (!user?.vendor) {
|
|
3442
|
+
console.warn(`[${logLabel}] No vendor found for userId=${userId}`);
|
|
3443
|
+
return null;
|
|
3444
|
+
}
|
|
3445
|
+
const vendor = await VendorModel.findOne({
|
|
3446
|
+
_id: user.vendor,
|
|
3447
|
+
active: true,
|
|
3448
|
+
deletedAt: null,
|
|
3449
|
+
"owner.userId": userId
|
|
3450
|
+
}).lean().exec();
|
|
3451
|
+
if (!vendor) {
|
|
3452
|
+
console.warn(`[${logLabel}] Vendor not found for id=${user.vendor}`);
|
|
3453
|
+
return null;
|
|
3454
|
+
}
|
|
3455
|
+
return vendor;
|
|
3456
|
+
}
|
|
3457
|
+
async function applyVendorDowngrade(vendor, ownerUserId) {
|
|
3458
|
+
const updateData = {};
|
|
3459
|
+
updateData.availability = {
|
|
3460
|
+
corporate: false,
|
|
3461
|
+
private: false,
|
|
3462
|
+
school: false
|
|
3463
|
+
};
|
|
3464
|
+
updateData.products = {
|
|
3465
|
+
active: false,
|
|
3466
|
+
productsList: vendor.products?.productsList ?? []
|
|
3467
|
+
};
|
|
3468
|
+
updateData.calendar = {
|
|
3469
|
+
active: false,
|
|
3470
|
+
calendarData: vendor.calendar?.calendarData ?? []
|
|
3471
|
+
};
|
|
3472
|
+
updateData.downgradeSnapshot = {
|
|
3473
|
+
availability: vendor.availability,
|
|
3474
|
+
calendarActive: vendor.calendar?.active,
|
|
3475
|
+
productsActive: vendor.products?.active
|
|
3476
|
+
};
|
|
3477
|
+
updateData.images = (vendor.images ?? []).map((image, index) => ({
|
|
3478
|
+
...image,
|
|
3479
|
+
active: index < 6
|
|
3480
|
+
}));
|
|
3481
|
+
const result = await VendorModel.updateOne(
|
|
3482
|
+
{
|
|
3483
|
+
_id: vendor._id,
|
|
3484
|
+
active: true,
|
|
3485
|
+
deletedAt: null,
|
|
3486
|
+
"owner.userId": ownerUserId
|
|
3487
|
+
},
|
|
3488
|
+
{ $set: updateData }
|
|
3489
|
+
);
|
|
3490
|
+
return (result?.matchedCount ?? 0) > 0;
|
|
3491
|
+
}
|
|
3492
|
+
async function downgradeVendorProFeatures(userId, licenceType) {
|
|
3493
|
+
const isStandardVendor = licenceType === EnumUserLicence9.STANDARD_VENDOR;
|
|
3494
|
+
if (!isStandardVendor) {
|
|
3495
|
+
return;
|
|
3496
|
+
}
|
|
3427
3497
|
try {
|
|
3428
|
-
const
|
|
3429
|
-
if (!
|
|
3430
|
-
console.warn(`[updateVendor] No vendor found for userId=${userId}`);
|
|
3498
|
+
const vendor = await findUserVendor(userId, "downgradeVendorProFeatures");
|
|
3499
|
+
if (!vendor) {
|
|
3431
3500
|
return;
|
|
3432
3501
|
}
|
|
3433
|
-
|
|
3502
|
+
await applyVendorDowngrade(vendor, userId);
|
|
3503
|
+
} catch (error) {
|
|
3504
|
+
console.error("[downgradeVendorProFeatures] Failed:", error);
|
|
3505
|
+
}
|
|
3506
|
+
}
|
|
3507
|
+
async function applyVendorRestore(vendor, ownerUserId) {
|
|
3508
|
+
const updateData = {};
|
|
3509
|
+
const snapshot = vendor.downgradeSnapshot;
|
|
3510
|
+
updateData.availability = {
|
|
3511
|
+
corporate: snapshot?.availability?.corporate ?? true,
|
|
3512
|
+
private: snapshot?.availability?.private ?? true,
|
|
3513
|
+
school: snapshot?.availability?.school ?? true
|
|
3514
|
+
};
|
|
3515
|
+
updateData.products = {
|
|
3516
|
+
active: snapshot?.productsActive ?? true,
|
|
3517
|
+
productsList: vendor.products?.productsList ?? []
|
|
3518
|
+
};
|
|
3519
|
+
updateData.calendar = {
|
|
3520
|
+
active: snapshot?.calendarActive ?? true,
|
|
3521
|
+
calendarData: vendor.calendar?.calendarData ?? []
|
|
3522
|
+
};
|
|
3523
|
+
updateData.images = (vendor.images ?? []).map((image) => ({
|
|
3524
|
+
...image,
|
|
3525
|
+
active: true
|
|
3526
|
+
}));
|
|
3527
|
+
const result = await VendorModel.updateOne(
|
|
3528
|
+
{
|
|
3529
|
+
_id: vendor._id,
|
|
3530
|
+
active: true,
|
|
3531
|
+
deletedAt: null,
|
|
3532
|
+
"owner.userId": ownerUserId
|
|
3533
|
+
},
|
|
3534
|
+
{ $set: updateData }
|
|
3535
|
+
);
|
|
3536
|
+
return (result?.matchedCount ?? 0) > 0;
|
|
3537
|
+
}
|
|
3538
|
+
async function restoreVendorProFeatures(userId, licenceType) {
|
|
3539
|
+
const isProVendor = licenceType === EnumUserLicence9.PRO_VENDOR || licenceType === EnumUserLicence9.PRO_PLUS_VENDOR;
|
|
3540
|
+
if (!isProVendor) {
|
|
3541
|
+
return;
|
|
3542
|
+
}
|
|
3543
|
+
try {
|
|
3544
|
+
const vendor = await findUserVendor(userId, "restoreVendorProFeatures");
|
|
3434
3545
|
if (!vendor) {
|
|
3435
|
-
console.warn(`[updateVendor] Vendor not found for id=${user.vendor}`);
|
|
3436
3546
|
return;
|
|
3437
3547
|
}
|
|
3438
|
-
|
|
3439
|
-
const isStandardVendor = licenceType === EnumUserLicence9.STANDARD_VENDOR;
|
|
3440
|
-
if (isStandardVendor) {
|
|
3441
|
-
updateData.availability = {
|
|
3442
|
-
corporate: false,
|
|
3443
|
-
private: false,
|
|
3444
|
-
school: false
|
|
3445
|
-
};
|
|
3446
|
-
updateData.products = {
|
|
3447
|
-
active: false,
|
|
3448
|
-
productsList: vendor.products?.productsList ?? []
|
|
3449
|
-
};
|
|
3450
|
-
updateData.calendar = {
|
|
3451
|
-
active: false,
|
|
3452
|
-
calendarData: vendor.calendar?.calendarData ?? []
|
|
3453
|
-
};
|
|
3454
|
-
}
|
|
3455
|
-
updateData.images = (vendor.images ?? []).map((image, index) => ({
|
|
3456
|
-
...image,
|
|
3457
|
-
active: isStandardVendor ? index < 6 : true
|
|
3458
|
-
}));
|
|
3459
|
-
await VendorModel.updateOne({ _id: vendor._id }, { $set: updateData });
|
|
3548
|
+
await applyVendorRestore(vendor, userId);
|
|
3460
3549
|
} catch (error) {
|
|
3461
|
-
console.error("[
|
|
3550
|
+
console.error("[restoreVendorProFeatures] Failed:", error);
|
|
3462
3551
|
}
|
|
3463
3552
|
}
|
|
3464
3553
|
var vendorLicences = [
|
|
@@ -3524,10 +3613,10 @@ async function handleVendorLicenceCompliance(user, now) {
|
|
|
3524
3613
|
if (!expiredProLicence || !vendor || hasValidProLicence) {
|
|
3525
3614
|
return;
|
|
3526
3615
|
}
|
|
3527
|
-
await
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3616
|
+
const downgraded = await applyVendorDowngrade(vendor, user._id);
|
|
3617
|
+
if (!downgraded) {
|
|
3618
|
+
return;
|
|
3619
|
+
}
|
|
3531
3620
|
const payload = {
|
|
3532
3621
|
data: {
|
|
3533
3622
|
resourceId: String(vendor._id),
|
|
@@ -4018,6 +4107,7 @@ export {
|
|
|
4018
4107
|
createLicenceObject,
|
|
4019
4108
|
dateTimeSchema2 as dateTimeSchema,
|
|
4020
4109
|
didRemoveAnyEventDates,
|
|
4110
|
+
downgradeVendorProFeatures,
|
|
4021
4111
|
ensureUserLicenseCompliance,
|
|
4022
4112
|
ensureUserLicenseComplianceForUser,
|
|
4023
4113
|
eventLicences,
|
|
@@ -4061,6 +4151,7 @@ export {
|
|
|
4061
4151
|
remindUsersAboutLicenseExpiration,
|
|
4062
4152
|
replaceUserLicenceWithObject,
|
|
4063
4153
|
resourceRelationsSchema,
|
|
4154
|
+
restoreVendorProFeatures,
|
|
4064
4155
|
saveNotificationsInDb,
|
|
4065
4156
|
sendDeactivationNotification,
|
|
4066
4157
|
sendLicenseReminder,
|
|
@@ -4073,7 +4164,6 @@ export {
|
|
|
4073
4164
|
updateAllEventDateTimeStatuses,
|
|
4074
4165
|
updateRelationDatesToUnavailable,
|
|
4075
4166
|
updateSingleDateTimeStatus,
|
|
4076
|
-
updateVendorBasedOnUserLicense,
|
|
4077
4167
|
upgradeUserToLicence,
|
|
4078
4168
|
userLicenseSchema,
|
|
4079
4169
|
vendorLicences,
|