Skip to content

Commit

Permalink
fix: add enum values to MySQL object of property decorator
Browse files Browse the repository at this point in the history
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
  • Loading branch information
aaqilniz committed Aug 25, 2024
1 parent 7a1083e commit 375178c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
8 changes: 7 additions & 1 deletion packages/cli/generators/discover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,10 +426,16 @@ module.exports = class DiscoveryGenerator extends ArtifactGenerator {
enumValuesArray.forEach(item => {
enumItems += `'${item}',`;
});
const enumItemString = enumItems.toString().replace(/,\s*$/, '');
templateData.properties[key]['type'] = 'String';
templateData.properties[key]['tsType'] = 'string';
templateData.properties[key]['jsonSchema'] =
`{enum: [${enumItems.toString()}]}`;
`{enum: [${enumItemString}]}`;
const mysqlString = templateData.properties[key]['mysql'];
templateData.properties[key]['mysql'] = mysqlString.replace(
"'enum',",
`'enum', value: "${enumItemString}",`,
);
}
});
this.copyTemplatedFiles(
Expand Down
16 changes: 12 additions & 4 deletions packages/cli/test/unit/discover/import-discovered-model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,25 @@ describe('importDiscoveredModel', () => {
patient: {
type: 'String',
jsonSchema: {enum: ['INPATIENT', 'OUTPATIENT']},
required: false,
length: null,
precision: null,
scale: null,
mysql: {
columnName: 'type',
dataType: 'enum',
value: "'INPATIENT','OUTPATIENT'",
dataLength: 10,
dataPrecision: null,
dataScale: null,
nullable: 'Y',
generated: false,
},
},
},
};

const modelData = importDiscoveredModel(discoveredModel);
expect(modelData.properties).to.have.property('patient').deepEqual({
jsonSchema: "{enum: ['INPATIENT', 'OUTPATIENT']}",
mysql:
"{columnName: 'type', dataType: 'enum', value: '\\'INPATIENT\\',\\'OUTPATIENT\\'', dataLength: 10, dataPrecision: null, dataScale: null, nullable: 'Y', generated: false}",
type: `'string'`,
tsType: 'string',
});
Expand Down

0 comments on commit 375178c

Please sign in to comment.