Skip to content

Commit 99713da

Browse files
committed
code refactor
1 parent 49527d0 commit 99713da

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

api/src/services/migration.service.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -428,17 +428,14 @@ export const createSourceLocales = async (req: Request) => {
428428
console.error(`project.json not found at ${projectFilePath}`);
429429
throw new Error(`project.json not found.`);
430430
}
431-
432431
// Find the project with the specified projectId
433-
const project: any = ProjectModelLowdb?.chain?.get?.("projects")?.find?.({ id: projectId })?.value?.();
434-
if (project) {
435-
const index = ProjectModelLowdb?.chain?.get?.("projects")?.findIndex?.({ id: projectId })?.value();
436-
if (index > -1) {
437-
438-
ProjectModelLowdb?.update((data: any) => {
439-
data.projects[index].source_locales = locales;
440-
});
441-
} // Write back the updated projects
432+
await ProjectModelLowdb?.read?.();
433+
const index = ProjectModelLowdb?.chain?.get?.("projects")?.findIndex?.({ id: projectId })?.value?.();
434+
if (index > -1) {
435+
ProjectModelLowdb?.update?.((data: any) => {
436+
data.projects[index].source_locales = locales;
437+
});
438+
// Write back the updated projects
442439
} else {
443440
logger.error(`Project with ID: ${projectId} not found`, {
444441
status: HTTP_CODES?.NOT_FOUND,
@@ -477,16 +474,14 @@ export const updateLocaleMapper = async (req: Request) => {
477474
throw new Error(`project.json not found.`);
478475
}
479476
// Find the project with the specified projectId
480-
await ProjectModelLowdb.read();
481-
const project: any = ProjectModelLowdb?.chain?.get?.("projects")?.find?.({ id: projectId })?.value();
482-
if (project) {
483-
const index = ProjectModelLowdb?.chain?.get("projects")?.findIndex?.({ id: projectId })?.value();
484-
if (index > -1) {
485-
ProjectModelLowdb?.update((data: any) => {
486-
data.projects[index].master_locale = mapperObject?.master_locale;
487-
data.projects[index].locales = mapperObject?.locales;
488-
});
489-
} // Write back the updated projects
477+
await ProjectModelLowdb?.read?.();
478+
const index = ProjectModelLowdb?.chain?.get?.("projects")?.findIndex?.({ id: projectId })?.value?.();
479+
if (index > -1) {
480+
ProjectModelLowdb?.update?.((data: any) => {
481+
data.projects[index].master_locale = mapperObject?.master_locale;
482+
data.projects[index].locales = mapperObject?.locales;
483+
});
484+
// Write back the updated projects
490485
} else {
491486
logger.error(`Project with ID: ${projectId} not found`, {
492487
status: HTTP_CODES?.NOT_FOUND,

0 commit comments

Comments
 (0)