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.
|
||||
/// Validates permissions, document type, entity existence, tags, and uploads to S3.
|
||||
/// </summary>
|
||||
|
||||
[HttpPost("upload")]
|
||||
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}")]
|
||||
public async Task<IActionResult> UpdateDocumentAsync(Guid id, [FromBody] UpdateDocumentAttachmentDto model)
|
||||
{
|
||||
@ -696,6 +708,8 @@ namespace Marco.Pms.Services.Controllers
|
||||
|
||||
dbContext.Documents.Add(document);
|
||||
|
||||
if (oldAttachment.IsVerified == true)
|
||||
{
|
||||
// Record new document attachment as the current version
|
||||
var attachment = new DocumentAttachment
|
||||
{
|
||||
@ -745,6 +759,19 @@ namespace Marco.Pms.Services.Controllers
|
||||
_logger.LogInfo("Created new current version for AttachmentId: {AttachmentId}", attachment.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
oldAttachment.Name = model.Name;
|
||||
oldAttachment.DocumentId = model.DocumentId;
|
||||
oldAttachment.Description = model.Description;
|
||||
oldAttachment.DocumentDataId = document.Id;
|
||||
|
||||
newAttachment = oldAttachment;
|
||||
newVersionMapping = oldVersionMapping ?? new AttachmentVersionMapping();
|
||||
_logger.LogInfo("Attachment metadata updated for AttachmentId: {AttachmentId}", oldAttachment.Id);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Update attachment metadata only (no file upload)
|
||||
oldAttachment.Name = model.Name;
|
||||
@ -752,7 +779,7 @@ namespace Marco.Pms.Services.Controllers
|
||||
oldAttachment.Description = model.Description;
|
||||
if (oldAttachment.IsVerified == true)
|
||||
{
|
||||
oldAttachment.IsVerified = false;
|
||||
oldAttachment.IsVerified = null;
|
||||
_logger.LogInfo("Reset verification flag for AttachmentId: {AttachmentId}", oldAttachment.Id);
|
||||
}
|
||||
oldAttachment.UpdatedAt = DateTime.UtcNow;
|
||||
|
Loading…
x
Reference in New Issue
Block a user