Skip to content

Commit

Permalink
get updated date and total file in mom
Browse files Browse the repository at this point in the history
  • Loading branch information
arvind9140 committed May 1, 2024
1 parent 07142c7 commit 0e04ad9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import leadModel from "../../../models/adminModels/leadModel.js";
try {
const data = await fileuploadModel.find({});
if (data.length > 0) {
data.reverse()
let projectData =[]
let leadData = []
let templateData =[]
Expand Down
26 changes: 20 additions & 6 deletions controllers/adminControllers/momControllers/mom.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const saveFileUploadData = async (
files: [
{
folder_name: existingFileUploadData.folder_name,
updated_date: existingFileUploadData.updated_date,
files: existingFileUploadData.files,
},
],
Expand All @@ -63,6 +64,7 @@ const saveFileUploadData = async (
},
{
$push: {
"files.update_date": existingFileUploadData.updated_date,
"files.$.files": { $each: existingFileUploadData.files },
},
},
Expand All @@ -83,6 +85,7 @@ const saveFileUploadData = async (
$push: {
files: {
folder_name: existingFileUploadData.folder_name,
updated_date: existingFileUploadData.updated_date,
files: existingFileUploadData.files,
},
},
Expand Down Expand Up @@ -200,14 +203,18 @@ export const createmom = async (req, res) => {
const files = req.files?.files;
const fileUploadPromises = [];
let successfullyUploadedFiles = [];
let fileSize= [];

if (files) {
const filesToUpload = Array.isArray(files)
? files.slice(0, 5)
: [files];


for (const file of filesToUpload) {
const fileName = file.name;
const fileSizeInBytes = file.size;
fileSize.push(fileSizeInBytes / 1024)
fileUploadPromises.push(
uploadFile(file, fileName, project_id, mom_id)
);
Expand All @@ -226,14 +233,19 @@ export const createmom = async (req, res) => {
}
let file = [];

let fileUrls
if (successfullyUploadedFiles.length > 0) {
let fileUrls = successfullyUploadedFiles.map((result) => ({
fileUrl: result.data.Location,
fileName: result.data.Location.split('/').pop(),
fileId: `FL-${generateSixDigitNumber()}`,
date: new Date()
for (let i = 0; i < fileSize.length; i++) {
fileUrls = successfullyUploadedFiles.map((result) => ({
fileUrl: result.data.Location,
fileName: result.data.Location.split('/').pop(),
fileId: `FL-${generateSixDigitNumber()}`,
fileSize: `${fileSize[i]} KB`,
date: new Date()

}));
}));

}

const update_mom = await projectModel.findOneAndUpdate(
{ project_id: project_id },
Expand Down Expand Up @@ -272,6 +284,7 @@ export const createmom = async (req, res) => {
project_id,
project_Name,
folder_name,
updated_date : new Date(),
files: fileUrls,
});
} else {
Expand All @@ -281,6 +294,7 @@ export const createmom = async (req, res) => {
project_id,
project_Name,
folder_name,
updated_date: new Date(),
files: fileUrls,
},
true
Expand Down

0 comments on commit 0e04ad9

Please sign in to comment.