Skip to content

Commit

Permalink
added a hack to force columns to be required
Browse files Browse the repository at this point in the history
  • Loading branch information
egandro committed Sep 6, 2017
1 parent d324514 commit c255449
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
36 changes: 35 additions & 1 deletion lib/generator/sequelize.ts.dal/sequelize.ts.dal.generator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Filter } from 'nicassa-parser-db';

import { GeneratorConfigBasic } from '../../persistance/generatorconfig.basic';
import { GeneratorConfigSequelizeTSDal } from '../../persistance/generatorconfig.sequelize.ts.dal';
import { GeneratorConfigSequelizeTSDal, CustomJSDocDecorator } from '../../persistance/generatorconfig.sequelize.ts.dal';

import { ModelNaming } from '../../persistance/naming/modelnaming';
import { CaseEnum } from '../../persistance/naming/case.enum';
Expand Down Expand Up @@ -90,8 +90,42 @@ export class SequelizeTSDalGenerator extends BaseGenerator {
}


protected async updateSymbolTableForJSDecorators(): Promise<boolean> {
if (this.generatorConfig.createJSDocDecorators == null ||
this.generatorConfig.createJSDocDecorators === undefined ||
this.generatorConfig.createJSDocDecorators == false ||
this.generatorConfig.customDJSDocDecorators == null ||
this.generatorConfig.customDJSDocDecorators === undefined ||
this.generatorConfig.customDJSDocDecorators.length == 0) {
return await false;
}

const customDecoratorsMap: { [key: string]: CustomJSDocDecorator } = {};
for (let item of this.generatorConfig.customDJSDocDecorators) {
const key = item.entity.toLowerCase();
customDecoratorsMap[key] = item;
}

for (let item of this.dbSymbolTable.columns) {
const key = item.table.name.toLowerCase() + '.' + item.name.toLowerCase();
if (customDecoratorsMap.hasOwnProperty(key)) {
const decorator = customDecoratorsMap[key];
if (decorator.required == null ||
decorator.required === undefined ||
!decorator.required) {
continue;
}
// set to not nullable
item.nullable = false;
}
}

return await true;
}

protected async generateCode(): Promise<boolean> {
this.dbSymbolTable = DBSymbolTableReader.readFromJsonString(this.nicassaJson, <any>this.generatorConfig.filter, this.typeMapper);
await this.updateSymbolTableForJSDecorators();

let createPackageJson: boolean = false;
let createIndex: boolean = false;
Expand Down
1 change: 1 addition & 0 deletions lib/persistance/generatorconfig.sequelize.ts.dal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GeneratorConfigBasic } from './generatorconfig.basic';

export interface CustomJSDocDecorator {
entity: string;
required?: boolean;
enabled?: boolean;
decorator: string[];
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nicassa-generator",
"description": "CLI based code generator for Sequelize, Node, Typescript, Angular 2, Android, Swagger, ORM Lite",
"version": "0.0.39",
"version": "0.0.40",
"author": "Harald Fielker <[email protected]>",
"repository": {
"type": "git",
Expand Down

0 comments on commit c255449

Please sign in to comment.