mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
refactor: settings to nestjs
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||
import { Body, Controller, Get, Post, Put } from '@nestjs/common';
|
||||
import { SettingsApplicationService } from './SettingsApplication.service';
|
||||
import { ISettingsDTO } from './Settings.types';
|
||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
||||
@@ -10,11 +10,13 @@ export class SettingsController {
|
||||
private readonly settingsApplicationService: SettingsApplicationService,
|
||||
) {}
|
||||
|
||||
@Post('')
|
||||
@Put('')
|
||||
async saveSettings(@Body() settingsDTO: ISettingsDTO) {
|
||||
return this.settingsApplicationService.saveSettings(settingsDTO);
|
||||
}
|
||||
|
||||
@Get('')
|
||||
async getSettings() {}
|
||||
async getSettings() {
|
||||
return this.settingsApplicationService.getSettings();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,17 +5,24 @@ import { SettingsApplicationService } from './SettingsApplication.service';
|
||||
import { SaveSettingsService } from './commands/SaveSettings.service';
|
||||
import { SettingsController } from './Settings.controller';
|
||||
import { SETTINGS_PROVIDER } from './Settings.types';
|
||||
import { GetSettingsService } from './queries/GetSettings.service';
|
||||
|
||||
@Module({
|
||||
providers: [
|
||||
SettingRepository,
|
||||
{
|
||||
provide: SETTINGS_PROVIDER,
|
||||
useFactory: (settingRepository: SettingRepository) => {
|
||||
return new SettingsStore(settingRepository);
|
||||
useFactory: async (settingRepository: SettingRepository) => {
|
||||
const settings = new SettingsStore(settingRepository);
|
||||
|
||||
// Load settings from database.
|
||||
await settings.load();
|
||||
|
||||
return settings;
|
||||
},
|
||||
inject: [SettingRepository],
|
||||
},
|
||||
GetSettingsService,
|
||||
SettingsApplicationService,
|
||||
SaveSettingsService,
|
||||
],
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { SaveSettingsService } from './commands/SaveSettings.service';
|
||||
import { ISettingsDTO } from './Settings.types';
|
||||
import { GetSettingsService } from './queries/GetSettings.service';
|
||||
|
||||
@Injectable()
|
||||
export class SettingsApplicationService {
|
||||
constructor(private readonly saveSettingsService: SaveSettingsService) {}
|
||||
constructor(
|
||||
private readonly saveSettingsService: SaveSettingsService,
|
||||
private readonly getSettingsService: GetSettingsService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Saves the given settings.
|
||||
@@ -13,4 +17,8 @@ export class SettingsApplicationService {
|
||||
public async saveSettings(settingsDTO: ISettingsDTO) {
|
||||
return this.saveSettingsService.saveSettings(settingsDTO);
|
||||
}
|
||||
|
||||
public async getSettings() {
|
||||
return this.getSettingsService.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { SettingsStore } from '../SettingsStore';
|
||||
import { SETTINGS_PROVIDER } from '../Settings.types';
|
||||
|
||||
@Injectable()
|
||||
export class GetSettingsService {
|
||||
constructor(
|
||||
@Inject(SETTINGS_PROVIDER) private readonly settingsStore: SettingsStore,
|
||||
) {}
|
||||
|
||||
public async execute() {
|
||||
return this.settingsStore.all();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user