Skip to content

Commit db3e0d9

Browse files
authored
fix: tenant update prefer existing value, not default (#200)
1 parent a14d627 commit db3e0d9

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/routes/tenant/index.ts

+23-11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ interface tenantRequestInterface extends RequestGenericInterface {
3939
}
4040
}
4141

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+
4251
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
4352
export default async function routes(fastify: FastifyInstance) {
4453
fastify.register(apiKey)
@@ -114,17 +123,20 @@ export default async function routes(fastify: FastifyInstance) {
114123
const { anonKey, databaseUrl, fileSizeLimit, jwtSecret, serviceKey } = request.body
115124
const { tenantId } = request.params
116125
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()
128140
reply.code(204).send()
129141
})
130142

0 commit comments

Comments
 (0)