5
5
NotFoundException ,
6
6
} from "@nestjs/common" ;
7
7
import { Config } from "@prisma/client" ;
8
- import { PrismaService } from "src/prisma/prisma.service" ;
9
8
import { EventEmitter } from "events" ;
9
+ import { PrismaService } from "src/prisma/prisma.service" ;
10
10
11
11
/**
12
12
* ConfigService extends EventEmitter to allow listening for config updates,
@@ -100,6 +100,8 @@ export class ConfigService extends EventEmitter {
100
100
) ;
101
101
}
102
102
103
+ this . validateConfigVariable ( key , value ) ;
104
+
103
105
const updatedVariable = await this . prisma . config . update ( {
104
106
where : {
105
107
name_category : {
@@ -116,4 +118,24 @@ export class ConfigService extends EventEmitter {
116
118
117
119
return updatedVariable ;
118
120
}
121
+
122
+ validateConfigVariable ( key : string , value : string | number | boolean ) {
123
+ const validations = [
124
+ {
125
+ key : "share.shareIdLength" ,
126
+ condition : ( value : number ) => value >= 2 && value <= 50 ,
127
+ message : "Share ID length must be between 2 and 50" ,
128
+ } ,
129
+ {
130
+ key : "share.zipCompressionLevel" ,
131
+ condition : ( value : number ) => value >= 0 && value <= 9 ,
132
+ message : "Zip compression level must be between 0 and 9" ,
133
+ } ,
134
+ ] ;
135
+
136
+ const validation = validations . find ( ( validation ) => validation . key == key ) ;
137
+ if ( validation && ! validation . condition ( value as any ) ) {
138
+ throw new BadRequestException ( validation . message ) ;
139
+ }
140
+ }
119
141
}
0 commit comments