Skip to content

Commit

Permalink
feat(generators/with-postgres-typeorm): add pluralize module, plurali…
Browse files Browse the repository at this point in the history
…ze model name
  • Loading branch information
phatpham9 committed Feb 15, 2021
1 parent fe87de7 commit ff389c5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
13 changes: 11 additions & 2 deletions generators/with-postgres-typeorm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ module.exports = class extends Generator {
return this.prompt(prompts).then((props) => {
const compNameParamCase = changeCase.paramCase(props.compName);
const compNamePascalCase = changeCase.pascalCase(props.compName);
const compNameCamelCase = changeCase.camelCase(props.compName);

this.props = {
...props,
// param-case
compNameParamCase,
compNamePascalCase,
// param-cases
compNameParamCasePlural: pluralize(compNameParamCase),
// PascalCase
compNamePascalCase,
// PasCalCases
compNamePascalCasePlural: pluralize(compNamePascalCase),
// camelCase
compNameCamelCase,
// camelCases
compNameCamelCasePlural: pluralize(compNameCamelCase),
};
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pluralize from 'pluralize';

const ENTITY = '<%= compNameParamCase %>';
const RESOURCE = '<%= compNameParamCasePlural %>';
const RESOURCE = pluralize(ENTITY);

export { ENTITY, RESOURCE };
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
import pluralize from 'pluralize';

import { <%= compNamePascalCase %> } from './types';
import { ENTITY } from './constants';

@Entity(ENTITY)
@Entity(pluralize(ENTITY))
class Model implements <%= compNamePascalCase %> {
@PrimaryGeneratedColumn()
id!: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ const get = async (id: number): Promise<<%= compNamePascalCase %>> => {
return document;
};

const update = async (
id: number,
data: Omit<<%= compNamePascalCase %>, 'id'>,
): Promise<<%= compNamePascalCase %>> => {
const update = async (id: number, data: Omit<<%= compNamePascalCase %>, 'id'>): Promise<<%= compNamePascalCase %>> => {
// get document
const document = await getRepository(Model).findOne(id);
if (document === undefined) {
Expand Down

0 comments on commit ff389c5

Please sign in to comment.