mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 15:50:32 +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 { SettingsApplicationService } from './SettingsApplication.service';
|
||||||
import { ISettingsDTO } from './Settings.types';
|
import { ISettingsDTO } from './Settings.types';
|
||||||
import { PublicRoute } from '../Auth/Jwt.guard';
|
import { PublicRoute } from '../Auth/Jwt.guard';
|
||||||
@@ -10,11 +10,13 @@ export class SettingsController {
|
|||||||
private readonly settingsApplicationService: SettingsApplicationService,
|
private readonly settingsApplicationService: SettingsApplicationService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Post('')
|
@Put('')
|
||||||
async saveSettings(@Body() settingsDTO: ISettingsDTO) {
|
async saveSettings(@Body() settingsDTO: ISettingsDTO) {
|
||||||
return this.settingsApplicationService.saveSettings(settingsDTO);
|
return this.settingsApplicationService.saveSettings(settingsDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('')
|
@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 { SaveSettingsService } from './commands/SaveSettings.service';
|
||||||
import { SettingsController } from './Settings.controller';
|
import { SettingsController } from './Settings.controller';
|
||||||
import { SETTINGS_PROVIDER } from './Settings.types';
|
import { SETTINGS_PROVIDER } from './Settings.types';
|
||||||
|
import { GetSettingsService } from './queries/GetSettings.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
providers: [
|
providers: [
|
||||||
SettingRepository,
|
SettingRepository,
|
||||||
{
|
{
|
||||||
provide: SETTINGS_PROVIDER,
|
provide: SETTINGS_PROVIDER,
|
||||||
useFactory: (settingRepository: SettingRepository) => {
|
useFactory: async (settingRepository: SettingRepository) => {
|
||||||
return new SettingsStore(settingRepository);
|
const settings = new SettingsStore(settingRepository);
|
||||||
|
|
||||||
|
// Load settings from database.
|
||||||
|
await settings.load();
|
||||||
|
|
||||||
|
return settings;
|
||||||
},
|
},
|
||||||
inject: [SettingRepository],
|
inject: [SettingRepository],
|
||||||
},
|
},
|
||||||
|
GetSettingsService,
|
||||||
SettingsApplicationService,
|
SettingsApplicationService,
|
||||||
SaveSettingsService,
|
SaveSettingsService,
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { SaveSettingsService } from './commands/SaveSettings.service';
|
import { SaveSettingsService } from './commands/SaveSettings.service';
|
||||||
import { ISettingsDTO } from './Settings.types';
|
import { ISettingsDTO } from './Settings.types';
|
||||||
|
import { GetSettingsService } from './queries/GetSettings.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SettingsApplicationService {
|
export class SettingsApplicationService {
|
||||||
constructor(private readonly saveSettingsService: SaveSettingsService) {}
|
constructor(
|
||||||
|
private readonly saveSettingsService: SaveSettingsService,
|
||||||
|
private readonly getSettingsService: GetSettingsService,
|
||||||
|
) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the given settings.
|
* Saves the given settings.
|
||||||
@@ -13,4 +17,8 @@ export class SettingsApplicationService {
|
|||||||
public async saveSettings(settingsDTO: ISettingsDTO) {
|
public async saveSettings(settingsDTO: ISettingsDTO) {
|
||||||
return this.saveSettingsService.saveSettings(settingsDTO);
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
export const isBlank = (value) => {
|
export const isBlank = (value) => {
|
||||||
return (_.isEmpty(value) && !_.isNumber(value)) || _.isNaN(value);
|
return (_.isEmpty(value) && !_.isNumber(value)) || _.isNaN(value);
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import * as request from 'supertest';
|
||||||
|
import { app } from './init-app-test';
|
||||||
|
|
||||||
|
const makeSettingsRequest = () => ({
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
group: 'credit_note',
|
||||||
|
key: 'customer_notes',
|
||||||
|
value: 'Customer Notes...',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
group: 'credit_note',
|
||||||
|
key: 'terms_conditions',
|
||||||
|
value: 'Terms & Conditions...',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Settings (e2e)', () => {
|
||||||
|
it('/settings (PUT)', () => {
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.put('/settings')
|
||||||
|
.set('organization-id', '4064541lv40nhca')
|
||||||
|
.send(makeSettingsRequest())
|
||||||
|
.expect(200);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('/settings (GET)', () => {
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.get('/settings')
|
||||||
|
.set('organization-id', '4064541lv40nhca')
|
||||||
|
.expect(200);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
import * as request from 'supertest';
|
||||||
|
import { app } from './init-app-test';
|
||||||
|
|
||||||
|
describe('Transactions Locking (e2e)', () => {
|
||||||
|
it('/transactions-locking (PUT)', () => {
|
||||||
|
return request(app.getHttpServer())
|
||||||
|
.put('/transactions-locking')
|
||||||
|
.set('organization-id', '4064541lv40nhca')
|
||||||
|
.send({
|
||||||
|
module: 'all',
|
||||||
|
lock_to_date: '2025-01-01',
|
||||||
|
reason: 'test',
|
||||||
|
})
|
||||||
|
.expect(200);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user