Skip to content

Commit 16ebaea

Browse files
committed
refactor(generators/with-postgres-typeorm/templates): rename component model.ts to schema.ts
1 parent e979f99 commit 16ebaea

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

generators/with-postgres-typeorm/templates/<%= compNameParamCasePlural %>/repository.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@ import { getRepository } from 'typeorm';
22
import { MyError } from '@boringcodes/utils/error';
33

44
import { <%= compNamePascalCase %> } from './types';
5-
import Model from './model';
5+
import Schema from './schema';
66

77
const list = async (): Promise<<%= compNamePascalCase %>[]> => {
88
// list documents
9-
const documents = await getRepository(Model).find();
9+
const documents = await getRepository(Schema).find();
1010

1111
return documents.map(transform);
1212
};
1313

1414
const create = async (object: Omit<<%= compNamePascalCase %>, 'id'>): Promise<<%= compNamePascalCase %>> => {
1515
// create document
16-
const document = getRepository(Model).create(object);
17-
await getRepository(Model).save(document);
16+
const document = getRepository(Schema).create(object);
17+
await getRepository(Schema).save(document);
1818

1919
return transform(document);
2020
};
2121

2222
const get = async (id: number): Promise<<%= compNamePascalCase %>> => {
2323
// get document
24-
const document = await getRepository(Model).findOne(id);
24+
const document = await getRepository(Schema).findOne(id);
2525
if (document === undefined) {
2626
throw new MyError('Document not found');
2727
}
@@ -34,33 +34,33 @@ const update = async (
3434
object: Omit<<%= compNamePascalCase %>, 'id'>,
3535
): Promise<<%= compNamePascalCase %>> => {
3636
// get document
37-
const document = await getRepository(Model).findOne(id);
37+
const document = await getRepository(Schema).findOne(id);
3838
if (document === undefined) {
3939
throw new MyError('Document not found');
4040
}
4141

4242
// update document
43-
getRepository(Model).merge(document, object);
44-
await getRepository(Model).save(document);
43+
getRepository(Schema).merge(document, object);
44+
await getRepository(Schema).save(document);
4545

4646
return transform(document);
4747
};
4848

4949
const del = async (id: number): Promise<<%= compNamePascalCase %>> => {
5050
// get document
51-
const document = await getRepository(Model).findOne(id);
51+
const document = await getRepository(Schema).findOne(id);
5252
if (document === undefined) {
5353
throw new MyError('Document not found');
5454
}
5555

5656
// delete document
57-
await getRepository(Model).remove(document);
57+
await getRepository(Schema).remove(document);
5858

5959
return transform(document);
6060
};
6161

6262
// transform document to <%= compNamePascalCase %>
63-
const transform = (document: Model): <%= compNamePascalCase %> => {
63+
const transform = (document: Schema): <%= compNamePascalCase %> => {
6464
return document;
6565
};
6666

generators/with-postgres-typeorm/templates/<%= compNameParamCasePlural %>/model.ts renamed to generators/with-postgres-typeorm/templates/<%= compNameParamCasePlural %>/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { <%= compNamePascalCase %> } from './types';
44
import { ENTITY } from './constants';
55

66
@Entity(ENTITY)
7-
class Model implements <%= compNamePascalCase %> {
7+
class Schema implements <%= compNamePascalCase %> {
88
@PrimaryGeneratedColumn()
99
id!: number;
1010

@@ -14,4 +14,4 @@ class Model implements <%= compNamePascalCase %> {
1414
// TODO: add more fields
1515
}
1616

17-
export default Model;
17+
export default Schema;

0 commit comments

Comments
 (0)