Skip to content

Commit

Permalink
more automation for new children
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-g committed Nov 9, 2023
1 parent ac1840b commit 429d2d8
Showing 1 changed file with 39 additions and 37 deletions.
76 changes: 39 additions & 37 deletions src/features/children/children.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 429d2d8

Please sign in to comment.