refactor and add some new endpoint defs

This commit is contained in:
2021-01-18 01:10:10 -07:00
parent 1e81c0ff85
commit 242e83f9b0
2 changed files with 108 additions and 11 deletions

View File

@ -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
},
]
},
]
},
{

View File

@ -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<void>((componentResolve, componentReject) => {
return new Promise<void>((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<void>((resolve, reject) => {
return new Promise<void>((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<void> {
const filePromise: Promise<void> = new Promise<void>((resolve) => {
return new Promise<void>((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<void> {
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;
}