From 429d2d86c964a848bc0ca7aebdca56a95fdfe2f3 Mon Sep 17 00:00:00 2001 From: Gbuntu Date: Thu, 9 Nov 2023 11:41:57 +0330 Subject: [PATCH] more automation for new children --- src/features/children/children.controller.ts | 76 ++++++++++---------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/src/features/children/children.controller.ts b/src/features/children/children.controller.ts index bbfd5ccdc..8fc7409ec 100644 --- a/src/features/children/children.controller.ts +++ b/src/features/children/children.controller.ts @@ -314,46 +314,48 @@ export class ChildrenController { if (!files) { throw new ServerError('No files were uploaded!'); } - // for local purposes - organized folders and files - const newChildFolder = `../../Docs/children${ - body.sex === SexEnum.MALE ? '/boys/' : '/girls/' - }organized/${capitalizeFirstLetter(body.sayNameEn)}-${body.sayNameFa}`; - - const originalAwakeGirl = `../../Docs/children/girls/${ - files.awakeFile[0].filename.split('-s-')[0] - }.png`; - const originalAwakeBoy = `../../Docs/children/boys/${ - files.awakeFile[0].filename.split('-s-')[0] - }.png`; - const originalSleptGirl = `../../Docs/children/girls/${ - files.sleptFile[0].filename.split('-s-')[0] - }.png`; - const originalSleptBoy = `../../Docs/children/boys/${ - files.sleptFile[0].filename.split('-s-')[0] - }.png`; - - const newAwakeName = `awake-${body.sayNameEn.toLowerCase()}.png`; - const newSleepName = `sleep-${body.sayNameEn.toLowerCase()}.png`; - if ( - checkIfFileOrDirectoryExists(originalAwakeGirl) || - checkIfFileOrDirectoryExists(originalAwakeBoy) - ) { - if (!checkIfFileOrDirectoryExists(newChildFolder)) { - fs.mkdirSync(newChildFolder); - } - if (Number(body.sex) === SexEnum.MALE) { - moveFile(originalAwakeBoy, `${newChildFolder}/${newAwakeName}`); - moveFile(originalSleptBoy, `${newChildFolder}/${newSleepName}`); - } - if (Number(body.sex) === SexEnum.FEMALE) { - moveFile(originalAwakeGirl, `${newChildFolder}/${newAwakeName}`); - moveFile(originalSleptGirl, `${newChildFolder}/${newSleepName}`); + if (process.env.NODE_ENV === 'development') { + // for local purposes - organized folders and files + const newChildFolder = `../../Docs/children${ + body.sex === SexEnum.MALE ? '/boys/' : '/girls/' + }organized/${capitalizeFirstLetter(body.sayNameEn)}-${body.sayNameFa}`; + + const originalAwakeGirl = `../../Docs/children/girls/${ + files.awakeFile[0].filename.split('-s-')[0] + }.png`; + const originalAwakeBoy = `../../Docs/children/boys/${ + files.awakeFile[0].filename.split('-s-')[0] + }.png`; + const originalSleptGirl = `../../Docs/children/girls/${ + files.sleptFile[0].filename.split('-s-')[0] + }.png`; + const originalSleptBoy = `../../Docs/children/boys/${ + files.sleptFile[0].filename.split('-s-')[0] + }.png`; + + const newAwakeName = `awake-${body.sayNameEn.toLowerCase()}.png`; + const newSleepName = `sleep-${body.sayNameEn.toLowerCase()}.png`; + + if ( + checkIfFileOrDirectoryExists(originalAwakeGirl) || + checkIfFileOrDirectoryExists(originalAwakeBoy) + ) { + if (!checkIfFileOrDirectoryExists(newChildFolder)) { + fs.mkdirSync(newChildFolder); + } + if (Number(body.sex) === SexEnum.MALE) { + moveFile(originalAwakeBoy, `${newChildFolder}/${newAwakeName}`); + moveFile(originalSleptBoy, `${newChildFolder}/${newSleepName}`); + } + if (Number(body.sex) === SexEnum.FEMALE) { + moveFile(originalAwakeGirl, `${newChildFolder}/${newAwakeName}`); + moveFile(originalSleptGirl, `${newChildFolder}/${newSleepName}`); + } + } else { + throw new ServerError('could not find the file'); } - } else { - throw new ServerError('could not find the file'); } - return await this.childrenService.createPreRegisterChild( files.awakeFile[0].filename, files.sleptFile[0].filename,