@@ -39,6 +39,15 @@ interface tenantRequestInterface extends RequestGenericInterface {
39
39
}
40
40
}
41
41
42
+ interface tenantDBInterface {
43
+ id : string
44
+ anon_key : string
45
+ database_url : string
46
+ jwt_secret : string
47
+ service_key : string
48
+ file_size_limit ?: number
49
+ }
50
+
42
51
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
43
52
export default async function routes ( fastify : FastifyInstance ) {
44
53
fastify . register ( apiKey )
@@ -114,17 +123,20 @@ export default async function routes(fastify: FastifyInstance) {
114
123
const { anonKey, databaseUrl, fileSizeLimit, jwtSecret, serviceKey } = request . body
115
124
const { tenantId } = request . params
116
125
await runMigrations ( tenantId , databaseUrl )
117
- await knex ( 'tenants' )
118
- . insert ( {
119
- id : tenantId ,
120
- anon_key : encrypt ( anonKey ) ,
121
- database_url : encrypt ( databaseUrl ) ,
122
- file_size_limit : fileSizeLimit ,
123
- jwt_secret : encrypt ( jwtSecret ) ,
124
- service_key : encrypt ( serviceKey ) ,
125
- } )
126
- . onConflict ( 'id' )
127
- . merge ( )
126
+
127
+ const tenantInfo : tenantDBInterface = {
128
+ id : tenantId ,
129
+ anon_key : encrypt ( anonKey ) ,
130
+ database_url : encrypt ( databaseUrl ) ,
131
+ jwt_secret : encrypt ( jwtSecret ) ,
132
+ service_key : encrypt ( serviceKey ) ,
133
+ }
134
+
135
+ if ( fileSizeLimit ) {
136
+ tenantInfo . file_size_limit = fileSizeLimit
137
+ }
138
+
139
+ await knex ( 'tenants' ) . insert ( tenantInfo ) . onConflict ( 'id' ) . merge ( )
128
140
reply . code ( 204 ) . send ( )
129
141
} )
130
142
0 commit comments