@@ -44,12 +44,12 @@ const updateBaseModel = <T extends BaseModel> (model: T) => {
44
44
model . updatedBy = auth . currentUser ?. uid
45
45
}
46
46
47
- const set = async < T extends BaseModel > ( collection : string , model : T ) => {
47
+ const set = < T extends BaseModel > ( collection : string , model : T ) => {
48
48
updateBaseModel ( model )
49
49
50
50
const docRef = firestore . collection ( collection ) . doc ( model . id )
51
51
52
- return await docRef . set ( model , {
52
+ return docRef . set ( model , {
53
53
merge : true
54
54
} )
55
55
. then ( ( ) => {
@@ -63,65 +63,65 @@ const set = async <T extends BaseModel> (collection: string, model: T) => {
63
63
} )
64
64
}
65
65
66
- const add = async < T extends BaseModel > ( collection : string , model : T ) => {
66
+ const add = < T extends BaseModel > ( collection : string , model : T ) => {
67
67
const docRef = firestore . collection ( collection ) . doc ( )
68
68
model . id = docRef . id
69
69
70
- return await set ( collection , model )
70
+ return set ( collection , model )
71
71
}
72
72
73
- export const saveModel = async < T extends BaseModel > ( collection : string , model : T ) => {
73
+ export const saveModel = < T extends BaseModel > ( collection : string , model : T ) => {
74
74
return model . id
75
- ? await set ( collection , model )
76
- : await add ( collection , model )
75
+ ? set ( collection , model )
76
+ : add ( collection , model )
77
77
}
78
78
79
- export const deleteModel = async ( collection : string , model : BaseModel ) => {
80
- return await firestore . collection ( collection ) . doc ( model . id ) . delete ( )
79
+ export const deleteModel = ( collection : string , model : BaseModel ) => {
80
+ return firestore . collection ( collection ) . doc ( model . id ) . delete ( )
81
81
}
82
82
83
- export const getCount = async ( collection : string ) : Promise < number > => {
84
- return await firestore . collection ( collection )
83
+ export const getCount = ( collection : string ) : Promise < number > => {
84
+ return firestore . collection ( collection )
85
85
. get ( )
86
86
. then ( ( querySnapshot ) => {
87
87
return querySnapshot . size
88
88
} )
89
89
}
90
90
91
- export const getCountByWhereClauses = async (
91
+ export const getCountByWhereClauses = (
92
92
collection : string ,
93
93
whereClause : WhereClause ,
94
94
...whereClauses : WhereClause [ ] ) : Promise < number > => {
95
95
const query = getQueryByWhereClauses ( collection , whereClause , ...whereClauses )
96
96
97
- return await query . get ( )
97
+ return query . get ( )
98
98
. then ( ( querySnapshot ) => {
99
99
return querySnapshot . size
100
100
} )
101
101
}
102
102
103
- export const getModelById = async ( collection : string , id : string ) : Promise < BaseModel > => {
104
- return await firestore . collection ( collection ) . doc ( id ) . get ( ) . then ( ( doc ) => {
103
+ export const getModelById = ( collection : string , id : string ) : Promise < BaseModel > => {
104
+ return firestore . collection ( collection ) . doc ( id ) . get ( ) . then ( ( doc ) => {
105
105
return doc . data ( ) as BaseModel
106
106
} )
107
107
}
108
108
109
- export const getModels = async < T extends BaseModel > ( collection : string ) : Promise < T [ ] > => {
110
- return await firestore . collection ( collection ) . get ( )
109
+ export const getModels = < T extends BaseModel > ( collection : string ) : Promise < T [ ] > => {
110
+ return firestore . collection ( collection ) . get ( )
111
111
. then ( querySnapshot => toBaseModelArray ( querySnapshot ) )
112
112
}
113
113
114
- export const getModelsByWhereClauses = async < T extends BaseModel > (
114
+ export const getModelsByWhereClauses = < T extends BaseModel > (
115
115
collection : string ,
116
116
whereClause : WhereClause ,
117
117
...whereClauses : WhereClause [ ] ) : Promise < T [ ] > => {
118
118
const query = getQueryByWhereClauses ( collection , whereClause , ...whereClauses )
119
119
120
- return await query . get ( )
120
+ return query . get ( )
121
121
. then ( querySnapshot => toBaseModelArray ( querySnapshot ) )
122
122
}
123
123
124
- export const getModelsByWhereClausesAndOrderBy = async < T extends BaseModel > (
124
+ export const getModelsByWhereClausesAndOrderBy = < T extends BaseModel > (
125
125
collection : string ,
126
126
orderBy : OrderBy ,
127
127
whereClause : WhereClause ,
@@ -132,11 +132,11 @@ export const getModelsByWhereClausesAndOrderBy = async <T extends BaseModel> (
132
132
query = query . orderBy ( orderBy . field , orderBy . direction )
133
133
}
134
134
135
- return await query . get ( )
135
+ return query . get ( )
136
136
. then ( querySnapshot => toBaseModelArray ( querySnapshot ) )
137
137
}
138
138
139
- export const getModelsByWhereClausesAndLimitAndOrderBy = async < T extends BaseModel > (
139
+ export const getModelsByWhereClausesAndLimitAndOrderBy = < T extends BaseModel > (
140
140
collection : string ,
141
141
lastVisible : any ,
142
142
limit : number ,
@@ -156,14 +156,14 @@ export const getModelsByWhereClausesAndLimitAndOrderBy = async <T extends BaseMo
156
156
157
157
query = query . limit ( limit )
158
158
159
- return await query . get ( )
159
+ return query . get ( )
160
160
. then ( querySnapshot => toBaseModelArray ( querySnapshot ) )
161
161
}
162
162
163
- export const getModelsByFieldAndPaging = async (
163
+ export const getModelsByFieldAndPaging = (
164
164
collection : string , field : string , value : any , page : number , limit : number
165
165
) : Promise < PagingResponse < BaseModel > > => {
166
- return await firestore . collection ( collection ) . get ( )
166
+ return firestore . collection ( collection ) . get ( )
167
167
. then ( ( querySnapshot ) => {
168
168
const docs : BaseModel [ ] = [ ]
169
169
0 commit comments