-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature:FUR-55 [BE]Config GenAI API key in setting DB
- Loading branch information
Showing
13 changed files
with
136 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export enum SettingKey { | ||
EDEN_AI = 'EDEN_AI', | ||
TRIPO_3D_AI= 'TRIPO_3D_AI' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PaginateModel } from 'mongoose' | ||
import { Injectable } from '@nestjs/common' | ||
import { InjectModel } from '@nestjs/mongoose' | ||
import { AbstractRepository } from '@common/repositories' | ||
import { Setting, SettingDocument } from '@setting/schemas/setting.schema' | ||
|
||
@Injectable() | ||
export class SettingRepository extends AbstractRepository<SettingDocument> { | ||
constructor(@InjectModel(Setting.name) model: PaginateModel<SettingDocument>) { | ||
super(model) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose' | ||
import { HydratedDocument } from 'mongoose' | ||
import { Transform } from 'class-transformer' | ||
import { SettingKey } from '@setting/contracts/constant'; | ||
|
||
export type SettingDocument = HydratedDocument<Setting>; | ||
|
||
@Schema({ | ||
collection: 'settings', | ||
timestamps: true, | ||
toJSON: { | ||
transform(doc, ret) { | ||
delete ret.__v | ||
} | ||
} | ||
}) | ||
export class Setting { | ||
constructor(id?: string) { | ||
this._id = id; | ||
} | ||
@Transform(({ value }) => value?.toString()) | ||
_id?: string; | ||
|
||
@Prop({ enum: SettingKey, required: true }) | ||
key: SettingKey; | ||
|
||
@Prop({ type: Object, required: true }) | ||
value: object; | ||
|
||
@Prop({ type: Boolean, default: true }) | ||
enabled: boolean; | ||
} | ||
|
||
export const SettingSchema = SchemaFactory.createForClass(Setting); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { SettingRepository } from '@setting/repositories/setting.repository'; | ||
import { SettingKey } from '@setting/contracts/constant'; | ||
|
||
@Injectable() | ||
export class SettingService { | ||
constructor(readonly settingRepository: SettingRepository) {} | ||
|
||
async getValue(key: SettingKey) { | ||
return ( | ||
await this.settingRepository.findOne({ | ||
conditions: { | ||
key: key.toString(), | ||
enabled: true, | ||
}, | ||
}) | ||
)?.value; | ||
} | ||
|
||
async updateValue(key: SettingKey, value: any) { | ||
return await this.settingRepository.findOneAndUpdate( | ||
{ | ||
key: key.toString(), | ||
enabled: true, | ||
}, | ||
{ value }, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Global, Module } from '@nestjs/common'; | ||
import { MongooseModule } from '@nestjs/mongoose'; | ||
import { Setting, SettingSchema } from '@setting/schemas/setting.schema'; | ||
import { SettingService } from '@setting/services/setting.service'; | ||
import { SettingRepository } from '@setting/repositories/setting.repository'; | ||
|
||
@Global() | ||
@Module({ | ||
imports: [ | ||
MongooseModule.forFeature([{ name: Setting.name, schema: SettingSchema }]), | ||
], | ||
providers: [SettingService, SettingRepository], | ||
exports: [SettingService], | ||
}) | ||
export class SettingModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters