diff --git a/src/example-def.ts b/src/example-def.ts index f663d36..9110f6f 100644 --- a/src/example-def.ts +++ b/src/example-def.ts @@ -222,7 +222,100 @@ let def: SystemDef = { param: 'completed' } ], - } + }, + { + component: 'task', + table: 'task', + type: 'update', + columns: [ + { + name: 'name', + table: 'task', + param: 'name', + }, + { + name: 'description', + table: 'task', + param: 'description' + }, + { + name: 'completed', + table: 'task', + param: 'completed' + }, + { + name: 'completed_date', + table: 'task', + param: 'completedDate' + }, + ], + filters: [ + { + column: { + name: 'task_id', + table: 'task' + }, + comparison: '=', + param: 'task', + required: true + }, + ] + }, + { + component: 'task', + table: 'task', + type: 'delete', + columns:[], + filters: [ + { + column: { + name: 'task_id', + table: 'task' + }, + comparison: '=', + param: 'task', + required: true + }, + ] + }, + { + component: 'task', + table: 'task', + type: 'item', + columns: [ + { + name: 'task_id', + table: 'task' + }, + { + name: 'name', + table: 'task' + }, + { + name: 'description', + table: 'task' + }, + { + name: 'completed', + table: 'task' + }, + { + name: 'completed_date', + table: 'task' + }, + ], + filters: [ + { + column: { + name: 'task_id', + table: 'task' + }, + comparison: '=', + param: 'task', + required: true + }, + ] + }, ] }, { diff --git a/src/views/views-creator.ts b/src/views/views-creator.ts index c59e8a7..400280c 100644 --- a/src/views/views-creator.ts +++ b/src/views/views-creator.ts @@ -1,9 +1,14 @@ import { BelongsToDef, ColumnDef, - Filter, JoinDef, Order, - SystemDef, TableDef, - EndpointDef, ComponentDef, ColumnRef + ColumnRef, + ComponentDef, + EndpointDef, + Filter, + JoinDef, + Order, + SystemDef, + TableDef } from '../systemGenService'; import * as path from 'path'; import * as fs from 'fs'; @@ -21,7 +26,7 @@ export function createViews(systemDef: SystemDef) { } function createComponent(component: ComponentDef, systemDef: SystemDef) { - let componentPromise = new Promise((componentResolve, componentReject) => { + return new Promise((componentResolve, componentReject) => { ncp(path.join(process.cwd(), 'frame', 'src', 'components', '{{component}}'), path.join(process.cwd(), systemDef.name, 'src', 'components', component.component), (err: any) => { if (err) { console.log(err); @@ -44,11 +49,10 @@ function createComponent(component: ComponentDef, systemDef: SystemDef) { } }); }); - return componentPromise; } function initializeComponentFile(sourceFile: string, destinationFile: string, component: string, outDir: string) { - let filePromise = new Promise((resolve, reject) => { + return new Promise((resolve, reject) => { fs.rename(sourceFile, destinationFile, (err: any) => { let fileContents = fs.readFileSync(destinationFile, 'utf8'); var uppercaseFirstLetterComponentName = uppercaseFirstLetter(component); @@ -58,8 +62,7 @@ function initializeComponentFile(sourceFile: string, destinationFile: string, co fs.writeFileSync(destinationFile, newFileContents, 'utf8'); resolve(); }); - }); - return filePromise + }) } function addInitializeServiceCode(component: string, outDir: string) { @@ -91,7 +94,7 @@ function addInitializeRoutesCode(component: string, outDir: string) { } function insertMapperCode(view: EndpointDef, outDir: string): Promise { - const filePromise: Promise = new Promise((resolve) => { + return new Promise((resolve) => { const separator: string = `// SYSTEM-BUILDER-${view.component}-mapper`; let fileLocation = path.join(process.cwd(), outDir, 'src', 'components', view.component, `${view.component}Mapper.ts`); let initMapperFile: string = fs.readFileSync(fileLocation, 'utf8'); @@ -102,7 +105,6 @@ function insertMapperCode(view: EndpointDef, outDir: string): Promise { fs.writeFileSync(fileLocation, newMapperFile, 'utf8'); resolve(); }); - return filePromise; } function createMapperFunc(view: EndpointDef): string { @@ -116,6 +118,8 @@ function createMapperFunc(view: EndpointDef): string { funcName = `update${uppercaseFirstLetter(view.component)}`; } else if (view.type.indexOf('create') !== -1) { func = buildCreateFunc(view); + } else if (view.type.indexOf('delete') !== -1) { + funcName = `delete${uppercaseFirstLetter(view.component)}`; } return func; }