Saving the tenant subscription modification logs in mongo DB

This commit is contained in:
ashutosh.nehete 2025-08-11 11:43:46 +05:30
parent ac0843ffe7
commit 21e1a7322c
3 changed files with 13 additions and 3 deletions

View File

@ -3,7 +3,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using MongoDB.Driver; using MongoDB.Driver;
namespace Marco.Pms.CacheHelper namespace Marco.Pms.Helpers.Utility
{ {
public class FeatureDetailsHelper public class FeatureDetailsHelper
{ {

View File

@ -1,9 +1,10 @@
using AutoMapper; using AutoMapper;
using Marco.Pms.CacheHelper;
using Marco.Pms.DataAccess.Data; using Marco.Pms.DataAccess.Data;
using Marco.Pms.Helpers.Utility;
using Marco.Pms.Model.Dtos.Tenant; using Marco.Pms.Model.Dtos.Tenant;
using Marco.Pms.Model.Employees; using Marco.Pms.Model.Employees;
using Marco.Pms.Model.Entitlements; using Marco.Pms.Model.Entitlements;
using Marco.Pms.Model.MongoDBModels.Utility;
using Marco.Pms.Model.Projects; using Marco.Pms.Model.Projects;
using Marco.Pms.Model.Roles; using Marco.Pms.Model.Roles;
using Marco.Pms.Model.TenantModels; using Marco.Pms.Model.TenantModels;
@ -922,6 +923,7 @@ namespace Marco.Pms.Services.Controllers
// 3. Get PermissionServices from DI inside a fresh scope (rarely needed, but retained for your design). // 3. Get PermissionServices from DI inside a fresh scope (rarely needed, but retained for your design).
using var scope = _serviceScopeFactory.CreateScope(); using var scope = _serviceScopeFactory.CreateScope();
var permissionService = scope.ServiceProvider.GetRequiredService<PermissionServices>(); var permissionService = scope.ServiceProvider.GetRequiredService<PermissionServices>();
var _updateLogHelper = scope.ServiceProvider.GetRequiredService<UtilityMongoDBHelper>();
// 4. Check user permissions: must be both Root user and have ManageTenants permission. // 4. Check user permissions: must be both Root user and have ManageTenants permission.
var isRootUser = loggedInEmployee.ApplicationUser?.IsRootUser ?? false; var isRootUser = loggedInEmployee.ApplicationUser?.IsRootUser ?? false;
@ -967,6 +969,7 @@ namespace Marco.Pms.Services.Controllers
// 6. If the tenant already has this plan, extend/renew it. // 6. If the tenant already has this plan, extend/renew it.
if (currentSubscription != null && currentSubscription.PlanId == subscriptionPlan.Id) if (currentSubscription != null && currentSubscription.PlanId == subscriptionPlan.Id)
{ {
var existingEntityBson = _updateLogHelper.EntityToBsonDocument(currentSubscription);
DateTime newEndDate; DateTime newEndDate;
// 6a. If the subscription is still active, extend from current EndDate; else start from now. // 6a. If the subscription is still active, extend from current EndDate; else start from now.
if (currentSubscription.EndDate.Date >= utcNow.Date) if (currentSubscription.EndDate.Date >= utcNow.Date)
@ -1009,6 +1012,14 @@ namespace Marco.Pms.Services.Controllers
_logger.LogInfo("Subscription renewed: Tenant={TenantId}, Plan={PlanId}, NewEnd={EndDate}", _logger.LogInfo("Subscription renewed: Tenant={TenantId}, Plan={PlanId}, NewEnd={EndDate}",
model.TenantId, model.PlanId, newEndDate); model.TenantId, model.PlanId, newEndDate);
await _updateLogHelper.PushToUpdateLogsAsync(new UpdateLogsObject
{
EntityId = currentSubscription.Id.ToString(),
UpdatedById = loggedInEmployee.Id.ToString(),
OldObject = existingEntityBson,
UpdatedAt = DateTime.UtcNow
}, "SubscriptionPlanModificationLog");
return Ok(ApiResponse<object>.SuccessResponse(currentSubscription, "Subscription renewed/extended", 200)); return Ok(ApiResponse<object>.SuccessResponse(currentSubscription, "Subscription renewed/extended", 200));
} }

View File

@ -1,4 +1,3 @@
using Marco.Pms.CacheHelper;
using Marco.Pms.DataAccess.Data; using Marco.Pms.DataAccess.Data;
using Marco.Pms.Helpers; using Marco.Pms.Helpers;
using Marco.Pms.Helpers.CacheHelper; using Marco.Pms.Helpers.CacheHelper;