1
1
import { models } from 'models' ;
2
2
3
- import { AbstactBuilder } from './abstact.builder ' ;
3
+ import { AbstactModel } from './abstact.model ' ;
4
4
5
5
6
- export class BookBuilder implements AbstactBuilder < models . book . Attributes , models . book . RawAttributes > {
6
+ export class BookModel implements AbstactModel < models . book . Attributes , models . book . RawAttributes > {
7
7
8
8
private id ?: number ;
9
9
private title ?: string ;
@@ -17,9 +17,9 @@ export class BookBuilder implements AbstactBuilder<models.book.Attributes, model
17
17
constructor ( attributes ?: models . book . Attributes | models . book . RawAttributes , isRaw = true ) {
18
18
if ( attributes ) {
19
19
if ( isRaw ) {
20
- this . mapRaw ( attributes ) ;
20
+ this . mapDatabaseObject ( attributes ) ;
21
21
} else {
22
- this . map ( attributes ) ;
22
+ this . mapJson ( attributes ) ;
23
23
}
24
24
}
25
25
}
@@ -56,47 +56,47 @@ export class BookBuilder implements AbstactBuilder<models.book.Attributes, model
56
56
return this . createdAt ;
57
57
} ;
58
58
59
- public setId ( id : number ) : BookBuilder {
59
+ public setId ( id : number ) : BookModel {
60
60
this . id = id ;
61
61
return this ;
62
62
} ;
63
63
64
- public setTitle ( title : string ) : BookBuilder {
64
+ public setTitle ( title : string ) : BookModel {
65
65
this . title = title ;
66
66
return this ;
67
67
} ;
68
68
69
- public setDescription ( description : string ) : BookBuilder {
69
+ public setDescription ( description : string ) : BookModel {
70
70
this . description = description ;
71
71
return this ;
72
72
} ;
73
73
74
- public setPrice ( price : number ) : BookBuilder {
74
+ public setPrice ( price : number ) : BookModel {
75
75
this . price = price ;
76
76
return this ;
77
77
} ;
78
78
79
- public setAuthorId ( authorId : number ) : BookBuilder {
79
+ public setAuthorId ( authorId : number ) : BookModel {
80
80
this . authorId = authorId ;
81
81
return this ;
82
82
} ;
83
83
84
- public setPublishedAt ( publishedAt : Date ) : BookBuilder {
84
+ public setPublishedAt ( publishedAt : Date ) : BookModel {
85
85
this . publishedAt = publishedAt ;
86
86
return this ;
87
87
} ;
88
88
89
- public setUpdatedAt ( updatedAt : Date ) : BookBuilder {
89
+ public setUpdatedAt ( updatedAt : Date ) : BookModel {
90
90
this . updatedAt = updatedAt ;
91
91
return this ;
92
92
} ;
93
93
94
- public setCreatedAt ( createdAt : Date ) : BookBuilder {
94
+ public setCreatedAt ( createdAt : Date ) : BookModel {
95
95
this . createdAt = createdAt ;
96
96
return this ;
97
97
} ;
98
98
99
- public map ( attributes : models . book . Attributes ) : BookBuilder {
99
+ public mapJson ( attributes : models . book . Attributes ) : BookModel {
100
100
if ( attributes !== undefined ) {
101
101
this . setId ( attributes . id ) ;
102
102
this . setTitle ( attributes . title ) ;
@@ -110,7 +110,7 @@ export class BookBuilder implements AbstactBuilder<models.book.Attributes, model
110
110
return this ;
111
111
}
112
112
113
- public mapRaw ( attributes : models . book . RawAttributes ) : BookBuilder {
113
+ public mapDatabaseObject ( attributes : models . book . RawAttributes ) : BookModel {
114
114
if ( attributes !== undefined ) {
115
115
this . setId ( attributes . id ) ;
116
116
this . setTitle ( attributes . title ) ;
@@ -128,11 +128,11 @@ export class BookBuilder implements AbstactBuilder<models.book.Attributes, model
128
128
// TODO Check id all required attributes ar given
129
129
}
130
130
131
- public build ( ) {
131
+ public toJson ( ) {
132
132
return new Book ( this ) ;
133
133
}
134
134
135
- public buildRaw ( ) {
135
+ public toDatabaseObject ( ) {
136
136
return new RawBook ( this ) ;
137
137
}
138
138
@@ -148,7 +148,7 @@ export class Book implements models.book.Attributes {
148
148
public updatedAt ?: Date ;
149
149
public createdAt ?: Date ;
150
150
151
- constructor ( builder : BookBuilder ) {
151
+ constructor ( builder : BookModel ) {
152
152
this . id = builder . Id ;
153
153
this . title = builder . Title ;
154
154
this . description = builder . Description ;
@@ -170,7 +170,7 @@ export class RawBook implements models.book.RawAttributes {
170
170
public updated_at ?: Date ;
171
171
public created_at ?: Date ;
172
172
173
- constructor ( builder : BookBuilder ) {
173
+ constructor ( builder : BookModel ) {
174
174
this . id = builder . Id ;
175
175
this . title = builder . Title ;
176
176
this . description = builder . Description ;
0 commit comments