-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathAiModelConfig.utility.ts
More file actions
38 lines (31 loc) · 1.2 KB
/
AiModelConfig.utility.ts
File metadata and controls
38 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import AiModelConfig from './AiModelConfig.model'
import { IAiModelConfig } from './AiModelConfig.type'
class AiModelConfigUtility {
public async findAllAiModelConfigs(): Promise<IAiModelConfig[]> {
return await AiModelConfig.find().exec()
}
public async findAiModelConfigById_And_ModelName(
userId: string,
modelName: string
): Promise<IAiModelConfig | null> {
return await AiModelConfig.findOne({ userId, 'agents.model': modelName }).exec()
}
public async findAiModelConfigByUserId(userId: string): Promise<IAiModelConfig | null> {
return await AiModelConfig.findOne({ userId }).select('-agents.key').exec()
}
public async findAiModelConfigsByUserId(userId: string): Promise<IAiModelConfig[]> {
return await AiModelConfig.find({ userId }).exec()
}
public async doesAiModelConfigExist(id: string): Promise<boolean> {
const count = await AiModelConfig.countDocuments({ _id: id }).exec()
return count > 0
}
public async isUserOwnerOfAiModelConfig(userId: string, configId: string): Promise<boolean> {
const config = await AiModelConfig.findOne({
_id: configId,
userId,
}).exec()
return !!config
}
}
export default new AiModelConfigUtility()