changing the documentDataId if attachment is not verified
This commit is contained in:
parent
72765fd491
commit
0cdbd574db
@ -327,6 +327,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
/// Uploads a document attachment for an Employee or Project.
|
/// Uploads a document attachment for an Employee or Project.
|
||||||
/// Validates permissions, document type, entity existence, tags, and uploads to S3.
|
/// Validates permissions, document type, entity existence, tags, and uploads to S3.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
[HttpPost("upload")]
|
[HttpPost("upload")]
|
||||||
public async Task<IActionResult> UploadDocumentAsync([FromBody] DocumentAttachmentDto model)
|
public async Task<IActionResult> UploadDocumentAsync([FromBody] DocumentAttachmentDto model)
|
||||||
{
|
{
|
||||||
@ -535,6 +536,17 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("verify/{id}")]
|
||||||
|
public async Task<IActionResult> VerifyDocumentAsync(Guid id)
|
||||||
|
{
|
||||||
|
await using var dbContext = await _dbContextFactory.CreateDbContextAsync();
|
||||||
|
using var scope = _serviceScope.CreateScope();
|
||||||
|
|
||||||
|
var loggedInEmployee = await _userHelper.GetCurrentEmployeeAsync();
|
||||||
|
|
||||||
|
return Ok(ApiResponse<object>.SuccessResponse(new { }, "Document is verified successfully", 200));
|
||||||
|
}
|
||||||
|
|
||||||
[HttpPut("edit/{id}")]
|
[HttpPut("edit/{id}")]
|
||||||
public async Task<IActionResult> UpdateDocumentAsync(Guid id, [FromBody] UpdateDocumentAttachmentDto model)
|
public async Task<IActionResult> UpdateDocumentAsync(Guid id, [FromBody] UpdateDocumentAttachmentDto model)
|
||||||
{
|
{
|
||||||
@ -696,53 +708,68 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
|
|
||||||
dbContext.Documents.Add(document);
|
dbContext.Documents.Add(document);
|
||||||
|
|
||||||
// Record new document attachment as the current version
|
if (oldAttachment.IsVerified == true)
|
||||||
var attachment = new DocumentAttachment
|
|
||||||
{
|
{
|
||||||
Name = model.Name,
|
// Record new document attachment as the current version
|
||||||
DocumentId = model.DocumentId,
|
var attachment = new DocumentAttachment
|
||||||
Description = model.Description,
|
|
||||||
IsCurrentVersion = true,
|
|
||||||
EntityId = oldAttachment.EntityId,
|
|
||||||
DocumentDataId = document.Id,
|
|
||||||
UploadedAt = DateTime.UtcNow,
|
|
||||||
UploadedById = loggedInEmployee.Id,
|
|
||||||
DocumentTypeId = oldAttachment.DocumentTypeId,
|
|
||||||
TenantId = oldAttachment.TenantId
|
|
||||||
};
|
|
||||||
|
|
||||||
dbContext.DocumentAttachments.Add(attachment);
|
|
||||||
|
|
||||||
// Mark old version as not current
|
|
||||||
oldAttachment.IsCurrentVersion = false;
|
|
||||||
|
|
||||||
// Version mapping
|
|
||||||
AttachmentVersionMapping versionMapping;
|
|
||||||
if (oldVersionMapping != null)
|
|
||||||
{
|
|
||||||
versionMapping = new AttachmentVersionMapping
|
|
||||||
{
|
{
|
||||||
ParentAttachmentId = oldVersionMapping.ParentAttachmentId,
|
Name = model.Name,
|
||||||
ChildAttachmentId = attachment.Id,
|
DocumentId = model.DocumentId,
|
||||||
Version = (oldVersionMapping.Version + 1),
|
Description = model.Description,
|
||||||
TenantId = tenantId
|
IsCurrentVersion = true,
|
||||||
|
EntityId = oldAttachment.EntityId,
|
||||||
|
DocumentDataId = document.Id,
|
||||||
|
UploadedAt = DateTime.UtcNow,
|
||||||
|
UploadedById = loggedInEmployee.Id,
|
||||||
|
DocumentTypeId = oldAttachment.DocumentTypeId,
|
||||||
|
TenantId = oldAttachment.TenantId
|
||||||
};
|
};
|
||||||
|
|
||||||
|
dbContext.DocumentAttachments.Add(attachment);
|
||||||
|
|
||||||
|
// Mark old version as not current
|
||||||
|
oldAttachment.IsCurrentVersion = false;
|
||||||
|
|
||||||
|
// Version mapping
|
||||||
|
AttachmentVersionMapping versionMapping;
|
||||||
|
if (oldVersionMapping != null)
|
||||||
|
{
|
||||||
|
versionMapping = new AttachmentVersionMapping
|
||||||
|
{
|
||||||
|
ParentAttachmentId = oldVersionMapping.ParentAttachmentId,
|
||||||
|
ChildAttachmentId = attachment.Id,
|
||||||
|
Version = (oldVersionMapping.Version + 1),
|
||||||
|
TenantId = tenantId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
versionMapping = new AttachmentVersionMapping
|
||||||
|
{
|
||||||
|
ParentAttachmentId = attachment.Id,
|
||||||
|
ChildAttachmentId = attachment.Id,
|
||||||
|
Version = 1,
|
||||||
|
TenantId = tenantId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
dbContext.AttachmentVersionMappings.Add(versionMapping);
|
||||||
|
|
||||||
|
newAttachment = attachment;
|
||||||
|
newVersionMapping = versionMapping;
|
||||||
|
_logger.LogInfo("Created new current version for AttachmentId: {AttachmentId}", attachment.Id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
versionMapping = new AttachmentVersionMapping
|
oldAttachment.Name = model.Name;
|
||||||
{
|
oldAttachment.DocumentId = model.DocumentId;
|
||||||
ParentAttachmentId = attachment.Id,
|
oldAttachment.Description = model.Description;
|
||||||
ChildAttachmentId = attachment.Id,
|
oldAttachment.DocumentDataId = document.Id;
|
||||||
Version = 1,
|
|
||||||
TenantId = tenantId
|
newAttachment = oldAttachment;
|
||||||
};
|
newVersionMapping = oldVersionMapping ?? new AttachmentVersionMapping();
|
||||||
}
|
_logger.LogInfo("Attachment metadata updated for AttachmentId: {AttachmentId}", oldAttachment.Id);
|
||||||
dbContext.AttachmentVersionMappings.Add(versionMapping);
|
}
|
||||||
|
|
||||||
newAttachment = attachment;
|
|
||||||
newVersionMapping = versionMapping;
|
|
||||||
_logger.LogInfo("Created new current version for AttachmentId: {AttachmentId}", attachment.Id);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -752,7 +779,7 @@ namespace Marco.Pms.Services.Controllers
|
|||||||
oldAttachment.Description = model.Description;
|
oldAttachment.Description = model.Description;
|
||||||
if (oldAttachment.IsVerified == true)
|
if (oldAttachment.IsVerified == true)
|
||||||
{
|
{
|
||||||
oldAttachment.IsVerified = false;
|
oldAttachment.IsVerified = null;
|
||||||
_logger.LogInfo("Reset verification flag for AttachmentId: {AttachmentId}", oldAttachment.Id);
|
_logger.LogInfo("Reset verification flag for AttachmentId: {AttachmentId}", oldAttachment.Id);
|
||||||
}
|
}
|
||||||
oldAttachment.UpdatedAt = DateTime.UtcNow;
|
oldAttachment.UpdatedAt = DateTime.UtcNow;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user