Skip to content

Commit

Permalink
small chnges
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Oct 27, 2024
1 parent 789bf58 commit 95120a5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/features/children/children.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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(
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/features/need/need.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ export class NeedService {
'need.img',
'need.purchase_cost',
'need._cost',
'need.deliveryCode',
'need.isConfirmed',
'need.created',
'need.updated',
Expand Down
5 changes: 4 additions & 1 deletion src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ export const deleteFile = async (path: string): Promise<void> => {
};

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!');
});
};


Expand Down

0 comments on commit 95120a5

Please sign in to comment.