mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
BC-5 fix: general tab of preferences form submitting.
This commit is contained in:
41
server/src/api/controllers/Miscellaneous/index.ts
Normal file
41
server/src/api/controllers/Miscellaneous/index.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { Router, Request, Response, NextFunction } from 'express';
|
||||
import BaseController from 'api/controllers/BaseController';
|
||||
import MiscService from 'services/Miscellaneous/MiscService';
|
||||
import DateFormatsService from 'services/Miscellaneous/DateFormats';
|
||||
|
||||
@Service()
|
||||
export default class MiscController extends BaseController {
|
||||
@Inject()
|
||||
dateFormatsService: DateFormatsService;
|
||||
|
||||
/**
|
||||
* Express router.
|
||||
*/
|
||||
router() {
|
||||
const router = Router();
|
||||
|
||||
router.get(
|
||||
'/date_formats',
|
||||
this.validationResult,
|
||||
this.asyncMiddleware(this.dateFormats.bind(this))
|
||||
);
|
||||
return router;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve date formats options.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {NextFunction} next
|
||||
*/
|
||||
dateFormats(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
const dateFormats = this.dateFormatsService.getDateFormats();
|
||||
|
||||
return res.status(200).send({ data: dateFormats });
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,8 @@ import {
|
||||
ACCEPTED_CURRENCIES,
|
||||
MONTHS,
|
||||
ACCEPTED_LOCALES,
|
||||
DATE_FORMATS,
|
||||
} from 'services/Organization/constants';
|
||||
import { DATE_FORMATS } from 'services/Miscellaneous/DateFormats/constants';
|
||||
|
||||
import { ServiceError } from 'exceptions';
|
||||
import BaseController from 'api/controllers/BaseController';
|
||||
@@ -64,7 +64,7 @@ export default class OrganizationController extends BaseController {
|
||||
*/
|
||||
private get buildValidationSchema(): ValidationChain[] {
|
||||
return [
|
||||
check('organization_name').exists().trim(),
|
||||
check('name').exists().trim(),
|
||||
check('base_currency').exists().isIn(ACCEPTED_CURRENCIES),
|
||||
check('timezone').exists().isIn(moment.tz.names()),
|
||||
check('fiscal_year').exists().isIn(MONTHS),
|
||||
|
||||
@@ -42,6 +42,7 @@ import Licenses from 'api/controllers/Subscription/Licenses';
|
||||
import InventoryAdjustments from 'api/controllers/Inventory/InventoryAdjustments';
|
||||
import asyncRenderMiddleware from './middleware/AsyncRenderMiddleware';
|
||||
import Jobs from './controllers/Jobs';
|
||||
import Miscellaneous from 'api/controllers/Miscellaneous';
|
||||
|
||||
export default () => {
|
||||
const app = Router();
|
||||
@@ -95,6 +96,8 @@ export default () => {
|
||||
dashboard.use('/media', Container.get(Media).router());
|
||||
dashboard.use('/inventory_adjustments', Container.get(InventoryAdjustments).router());
|
||||
|
||||
dashboard.use('/', Container.get(Miscellaneous).router());
|
||||
|
||||
app.use('/', dashboard);
|
||||
|
||||
return app;
|
||||
|
||||
11
server/src/services/Miscellaneous/DateFormats/constants.ts
Normal file
11
server/src/services/Miscellaneous/DateFormats/constants.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export const DATE_FORMATS = [
|
||||
'MM/DD/YY',
|
||||
'DD/MM/YY',
|
||||
'YY/MM/DD',
|
||||
'MM/DD/yyyy',
|
||||
'DD/MM/yyyy',
|
||||
'yyyy/MM/DD',
|
||||
'DD MMM YYYY',
|
||||
'DD MMMM YYYY',
|
||||
'MMMM DD, YYYY',
|
||||
];
|
||||
15
server/src/services/Miscellaneous/DateFormats/index.ts
Normal file
15
server/src/services/Miscellaneous/DateFormats/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import moment from 'moment-timezone';
|
||||
import { Service } from 'typedi';
|
||||
import { DATE_FORMATS } from './constants';
|
||||
|
||||
@Service()
|
||||
export default class DateFormatsService {
|
||||
getDateFormats() {
|
||||
return DATE_FORMATS.map((dateFormat) => {
|
||||
return {
|
||||
label: `${moment().format(dateFormat)} [${dateFormat}]`,
|
||||
key: dateFormat,
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
8
server/src/services/Miscellaneous/MiscService.ts
Normal file
8
server/src/services/Miscellaneous/MiscService.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Service } from 'typedi';
|
||||
|
||||
@Service()
|
||||
export default class MiscService {
|
||||
getDateFormats() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import { ObjectId } from 'mongodb';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import {
|
||||
IOrganizationBuildDTO,
|
||||
@@ -12,7 +13,6 @@ import {
|
||||
import events from 'subscribers/events';
|
||||
import TenantsManager from 'services/Tenancy/TenantsManager';
|
||||
import { Tenant } from 'system/models';
|
||||
import { ObjectId } from 'mongodb';
|
||||
|
||||
const ERRORS = {
|
||||
TENANT_NOT_FOUND: 'tenant_not_found',
|
||||
@@ -137,8 +137,8 @@ export default class OrganizationService {
|
||||
|
||||
/**
|
||||
* Updates organization information.
|
||||
* @param {ITenant} tenantId
|
||||
* @param {IOrganizationUpdateDTO} organizationDTO
|
||||
* @param {ITenant} tenantId
|
||||
* @param {IOrganizationUpdateDTO} organizationDTO
|
||||
*/
|
||||
public async updateOrganization(
|
||||
tenantId: number,
|
||||
|
||||
@@ -3,8 +3,9 @@ exports.up = function (knex) {
|
||||
table.bigIncrements();
|
||||
table.integer('tenant_id').unsigned();
|
||||
|
||||
table.string('organization_name');
|
||||
table.string('name');
|
||||
table.string('industry');
|
||||
table.string('location');
|
||||
|
||||
table.string('base_currency');
|
||||
table.string('language');
|
||||
@@ -13,7 +14,6 @@ exports.up = function (knex) {
|
||||
table.string('date_format');
|
||||
|
||||
table.string('fiscal_year');
|
||||
table.string('financial_start_date');
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user