diff --git a/src/features/children/children.controller.ts b/src/features/children/children.controller.ts index c3ff83554..9dbef9194 100644 --- a/src/features/children/children.controller.ts +++ b/src/features/children/children.controller.ts @@ -70,6 +70,7 @@ import { CampaignService } from '../campaign/campaign.service'; import { File } from '@web-std/file'; import { ChildrenPreRegisterEntity } from 'src/entities/childrenPreRegister.entity'; import { ObjectNotFound } from 'src/filters/notFound-expectation.filter'; +import { forEach } from 'mathjs'; @ApiTags('Children') @ApiSecurity('flask-access-token') @@ -478,6 +479,7 @@ export class ChildrenController { const boysFiles = fs.readdirSync(`../../Docs/children/boys/organized`); const girlsFiles = fs.readdirSync(`../../Docs/children/girls/organized`); const filesDir = boysFiles.concat(girlsFiles); + const separateFilesDir = { boysFiles, girlsFiles } for (const p of allPreRegisters) { path = filesDir.find( @@ -495,6 +497,47 @@ export class ChildrenController { throw new ServerError('The arrays are different'); } + const girlPathList = [] + const boyPathList = [] + + filesDir.forEach((dir) => { + const girlPath = separateFilesDir.girlsFiles.find( + (d) => dir === d + ); + const boyPath = separateFilesDir.boysFiles.find( + (d) => dir === d + ); + + if (girlPath) { + girlPathList.push(girlPath) + } + if (boyPath) { + boyPathList.push(boyPath) + } + + }) + + + + if (boyPathList[0]) { + console.log("boy"); + boyPathList.forEach((p) => { + const targetDirectory = `../../Docs/children/boys/organized/${p}` + const files = fs.readdirSync(targetDirectory); + files.forEach(async (f) => await moveFile(`${targetDirectory}/${f}`, `../../Docs/children/to-be-restored/${f}`)) + fs.promises.rmdir(targetDirectory, { recursive: false }); + }) + } + if (girlPathList[0]) { + console.log("girl"); + girlPathList.forEach((p) => { + const targetDirectory = `../../Docs/children/girls/organized/${p}` + const files = fs.readdirSync(targetDirectory); + files.forEach(async (f) => await moveFile(`${targetDirectory}/${f}`, `../../Docs/children/to-be-restored/${f}`)) + fs.promises.rmdir(targetDirectory, { recursive: false }); + + }) + } return { "FoldersToBeManaged": filesDir }; } catch (e) { console.log(e); diff --git a/src/features/need/need.service.ts b/src/features/need/need.service.ts index 36ee39b9f..e0c687ff6 100644 --- a/src/features/need/need.service.ts +++ b/src/features/need/need.service.ts @@ -649,6 +649,7 @@ export class NeedService { 'need.img', 'need.purchase_cost', 'need._cost', + 'need.deliveryCode', 'need.isConfirmed', 'need.created', 'need.updated', diff --git a/src/utils/file.ts b/src/utils/file.ts index 1f78d274f..7ba881e76 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -80,7 +80,10 @@ export const deleteFile = async (path: string): Promise => { }; export const moveFile = async (oldPath: string, newPath: string) => { - fs.rename(oldPath, newPath, () => console.log('Moved a file...')); + fs.rename(oldPath, newPath, (err) => { + if (err) throw err; + console.log('Rename complete!'); + }); };