working and no errors on front or back ends
This commit is contained in:
@ -1,5 +1,14 @@
|
||||
import fs from "fs";
|
||||
import {ColumnDef, ColumnRef, EndpointDef, Filter, SystemDef, TableDef} from "./systemGenService";
|
||||
import {
|
||||
BelongsToDef,
|
||||
ColumnDef,
|
||||
ColumnRef,
|
||||
EndpointDef,
|
||||
Filter,
|
||||
ManyToManyDef,
|
||||
SystemDef,
|
||||
TableDef
|
||||
} from "./systemGenService";
|
||||
import path from "path";
|
||||
import {createServiceFunc} from "./views/service-creator";
|
||||
import pluralize from "pluralize";
|
||||
@ -48,11 +57,11 @@ function initializeComponentFile(sourceFile: string, destinationFile: string, co
|
||||
})
|
||||
}
|
||||
|
||||
function removeTemplateFiles(destinationFolder: string) {
|
||||
function removeTemplateFolder(destinationFolder: string) {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
fs.rmdir(destinationFolder, (err) => {
|
||||
fs.rmdir(destinationFolder, { recursive: true }, (err) => {
|
||||
if (err) {
|
||||
reject();
|
||||
reject(err);
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
@ -60,6 +69,14 @@ function removeTemplateFiles(destinationFolder: string) {
|
||||
});
|
||||
}
|
||||
|
||||
function removeTemplateFiles(destinationFolder: string) {
|
||||
let regex = /\{\{component\}\}.*$/
|
||||
fs.readdirSync(destinationFolder)
|
||||
.filter(f => regex.test(f))
|
||||
.map(f => fs.unlinkSync(path.join(destinationFolder, f)));
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
function insertServiceCode(view: EndpointDef, outDir: string): Promise<void> {
|
||||
return new Promise<void>((resolve) => {
|
||||
const separator: string = `// SYSTEM-BUILDER-${view.component}-service`;
|
||||
@ -111,6 +128,26 @@ function createDetailsInitValues(view: EndpointDef, systemDef: SystemDef) {
|
||||
`;
|
||||
}
|
||||
});
|
||||
// TODO: get relations to add as properties
|
||||
let storageTable: TableDef | undefined = systemDef.storage.tables.find((table: TableDef) => {
|
||||
return table.name === view.component;
|
||||
});
|
||||
if (storageTable) {
|
||||
storageTable.relations.forEach((rel: BelongsToDef) => {
|
||||
out = out + `${rel.table}_id: '',
|
||||
`;
|
||||
});
|
||||
}
|
||||
systemDef.storage.relations.forEach((rel:ManyToManyDef) => {
|
||||
if (rel.right === view.component) {
|
||||
out = out + `${rel.left}_id: '',
|
||||
`;
|
||||
}
|
||||
if (rel.left === view.component) {
|
||||
out = out + `${rel.right}_id: '',
|
||||
`;
|
||||
}
|
||||
});
|
||||
|
||||
return out;
|
||||
}
|
||||
@ -118,6 +155,26 @@ function createDetailsInitValues(view: EndpointDef, systemDef: SystemDef) {
|
||||
function createDetailsTypeValues(view: EndpointDef, systemDef: SystemDef) {
|
||||
let out = ``;
|
||||
|
||||
let storageTable = systemDef.storage.tables.find((table: TableDef) => {
|
||||
return table.name === view.component;
|
||||
});
|
||||
let relations: string[] = [];
|
||||
if (storageTable) {
|
||||
storageTable.relations.map((rel: BelongsToDef) => {
|
||||
relations.push(rel.table);
|
||||
});
|
||||
systemDef.storage.relations.forEach((rel: ManyToManyDef) => {
|
||||
// @ts-ignore
|
||||
if (rel.left === storageTable.name) {
|
||||
relations.push(rel.right);
|
||||
}
|
||||
// @ts-ignore
|
||||
if (rel.right === storageTable.name) {
|
||||
relations.push(rel.left);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
view.columns.forEach((column: ColumnRef) => {
|
||||
let colDef: ColumnDef | undefined = findColumn(column, systemDef);
|
||||
if (colDef) {
|
||||
@ -125,6 +182,10 @@ function createDetailsTypeValues(view: EndpointDef, systemDef: SystemDef) {
|
||||
`;
|
||||
}
|
||||
});
|
||||
relations.forEach((rel: string) => {
|
||||
out = out + `${rel}_id: string
|
||||
`;
|
||||
});
|
||||
|
||||
return out;
|
||||
}
|
||||
@ -138,5 +199,6 @@ export {
|
||||
lowercaseFirstLetter,
|
||||
makeSet,
|
||||
removeTemplateFiles,
|
||||
removeTemplateFolder,
|
||||
uppercaseFirstLetter,
|
||||
}
|
Reference in New Issue
Block a user