Skip to content

Commit

Permalink
Merge branch 'feat/oidc-integration' into feat/get-tenant-of-authenti…
Browse files Browse the repository at this point in the history
…cated-user
  • Loading branch information
er-santosh committed Mar 28, 2024
2 parents be546b2 + 086c27a commit d4ef1e5
Show file tree
Hide file tree
Showing 111 changed files with 4,304 additions and 254 deletions.
2 changes: 1 addition & 1 deletion packages/server/resources/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@
"account.field.normal.credit": "دائن",
"account.field.normal.debit": "مدين",
"account.field.type": "نوع الحساب",
"account.field.active": "Activity",
"account.field.active": "Active",
"account.field.balance": "الرصيد",
"account.field.created_at": "أنشئت في",
"item.field.type": "نوع الصنف",
Expand Down
15 changes: 8 additions & 7 deletions packages/server/resources/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@
"account.field.normal.credit": "Credit",
"account.field.normal.debit": "Debit",
"account.field.type": "Type",
"account.field.active": "Activity",
"account.field.active": "Active",
"account.field.currency": "Currency",
"account.field.balance": "Balance",
"account.field.created_at": "Created at",
"item.field.type": "Item type",
Expand Down Expand Up @@ -376,16 +377,16 @@
"customer.field.last_name": "Last name",
"customer.field.display_name": "Display name",
"customer.field.email": "Email",
"customer.field.work_phone": "Work phone",
"customer.field.personal_phone": "Personal phone",
"customer.field.work_phone": "Work Phone Number",
"customer.field.personal_phone": "Personal Phone Number",
"customer.field.company_name": "Company name",
"customer.field.website": "Website",
"customer.field.opening_balance_at": "Opening balance at",
"customer.field.opening_balance": "Opening balance",
"customer.field.created_at": "Created at",
"customer.field.balance": "Balance",
"customer.field.status": "Status",
"customer.field.currency": "Curreny",
"customer.field.currency": "Currency",
"customer.field.status.active": "Active",
"customer.field.status.inactive": "Inactive",
"customer.field.status.overdue": "Overdue",
Expand All @@ -394,16 +395,16 @@
"vendor.field.last_name": "Last name",
"vendor.field.display_name": "Display name",
"vendor.field.email": "Email",
"vendor.field.work_phone": "Work phone",
"vendor.field.personal_phone": "Personal phone",
"vendor.field.work_phone": "Work Phone Number",
"vendor.field.personal_phone": "Personal Phone Number",
"vendor.field.company_name": "Company name",
"vendor.field.website": "Website",
"vendor.field.opening_balance_at": "Opening balance at",
"vendor.field.opening_balance": "Opening balance",
"vendor.field.created_at": "Created at",
"vendor.field.balance": "Balance",
"vendor.field.status": "Status",
"vendor.field.currency": "Curreny",
"vendor.field.currency": "Currency",
"vendor.field.status.active": "Active",
"vendor.field.status.inactive": "Inactive",
"vendor.field.status.overdue": "Overdue",
Expand Down
12 changes: 6 additions & 6 deletions packages/server/src/api/controllers/Accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class AccountsController extends BaseController {
/**
* Router constructor method.
*/
router() {
public router() {
const router = Router();

router.get(
Expand Down Expand Up @@ -98,7 +98,7 @@ export default class AccountsController extends BaseController {
/**
* Create account DTO Schema validation.
*/
get createAccountDTOSchema() {
private get createAccountDTOSchema() {
return [
check('name')
.exists()
Expand Down Expand Up @@ -131,7 +131,7 @@ export default class AccountsController extends BaseController {
/**
* Account DTO Schema validation.
*/
get editAccountDTOSchema() {
private get editAccountDTOSchema() {
return [
check('name')
.exists()
Expand Down Expand Up @@ -160,14 +160,14 @@ export default class AccountsController extends BaseController {
];
}

get accountParamSchema() {
private get accountParamSchema() {
return [param('id').exists().isNumeric().toInt()];
}

/**
* Accounts list validation schema.
*/
get accountsListSchema() {
private get accountsListSchema() {
return [
query('view_slug').optional({ nullable: true }).isString().trim(),
query('stringified_filter_roles').optional().isJSON(),
Expand Down Expand Up @@ -349,7 +349,7 @@ export default class AccountsController extends BaseController {
// Filter query.
const filter = {
sortOrder: 'desc',
columnSortBy: 'created_at',
columnSortBy: 'createdAt',
inactiveMode: false,
structure: IAccountsStructureType.Tree,
...this.matchedQueryData(req),
Expand Down
6 changes: 2 additions & 4 deletions packages/server/src/api/controllers/Contacts/Customers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ export default class CustomersController extends ContactsController {
try {
const contact = await this.customersApplication.createCustomer(
tenantId,
contactDTO,
user
contactDTO
);

return res.status(200).send({
id: contact.id,
message: 'The customer has been created successfully.',
Expand Down Expand Up @@ -291,7 +289,7 @@ export default class CustomersController extends ContactsController {
const filter = {
inactiveMode: false,
sortOrder: 'desc',
columnSortBy: 'created_at',
columnSortBy: 'createdAt',
page: 1,
pageSize: 12,
...this.matchedQueryData(req),
Expand Down
2 changes: 1 addition & 1 deletion packages/server/src/api/controllers/Contacts/Vendors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ export default class VendorsController extends ContactsController {
const vendorsFilter: IVendorsFilter = {
inactiveMode: false,
sortOrder: 'desc',
columnSortBy: 'created_at',
columnSortBy: 'createdAt',
page: 1,
pageSize: 12,
...this.matchedQueryData(req),
Expand Down
78 changes: 73 additions & 5 deletions packages/server/src/api/controllers/Import/ImportController.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Inject, Service } from 'typedi';
import { Router, Request, Response, NextFunction } from 'express';
import { body, param } from 'express-validator';
import { body, param, query } from 'express-validator';
import { defaultTo } from 'lodash';
import BaseController from '@/api/controllers/BaseController';
import { ServiceError } from '@/exceptions';
import { ImportResourceApplication } from '@/services/Import/ImportResourceApplication';
import { uploadImportFile } from './_utils';
import { parseJsonSafe } from '@/utils/parse-json-safe';

@Service()
export class ImportController extends BaseController {
Expand Down Expand Up @@ -42,7 +44,18 @@ export class ImportController extends BaseController {
this.asyncMiddleware(this.mapping.bind(this)),
this.catchServiceErrors
);
router.post(
router.get(
'/sample',
[query('resource').exists(), query('format').optional()],
this.downloadImportSample.bind(this),
this.catchServiceErrors
);
router.get(
'/:import_id',
this.asyncMiddleware(this.getImportFileMeta.bind(this)),
this.catchServiceErrors
);
router.get(
'/:import_id/preview',
this.asyncMiddleware(this.preview.bind(this)),
this.catchServiceErrors
Expand All @@ -55,7 +68,7 @@ export class ImportController extends BaseController {
* @returns {ValidationSchema[]}
*/
private get importValidationSchema() {
return [body('resource').exists()];
return [body('resource').exists(), body('params').optional()];
}

/**
Expand All @@ -66,12 +79,15 @@ export class ImportController extends BaseController {
*/
private async fileUpload(req: Request, res: Response, next: NextFunction) {
const { tenantId } = req;
const body = this.matchedBodyData(req);
const params = defaultTo(parseJsonSafe(body.params), {});

try {
const data = await this.importResourceApp.import(
tenantId,
req.body.resource,
req.file.filename
body.resource,
req.file.filename,
params
);
return res.status(200).send(data);
} catch (error) {
Expand Down Expand Up @@ -140,6 +156,54 @@ export class ImportController extends BaseController {
}
}

/**
* Retrieves the csv/xlsx sample sheet of the given resource name.
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
*/
private async downloadImportSample(
req: Request,
res: Response,
next: NextFunction
) {
const { tenantId } = req;
const { format, resource } = this.matchedQueryData(req);

try {
const result = this.importResourceApp.sample(tenantId, resource, format);

return res.status(200).send(result);
} catch (error) {
next(error);
}
}

/**
* Retrieves the import file meta.
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
*/
private async getImportFileMeta(
req: Request,
res: Response,
next: NextFunction
) {
const { tenantId } = req;
const { import_id: importId } = req.params;

try {
const result = await this.importResourceApp.importMeta(
tenantId,
importId
);
return res.status(200).send(result);
} catch (error) {
next(error);
}
}

/**
* Transforms service errors to response.
* @param {Error}
Expand Down Expand Up @@ -174,7 +238,11 @@ export class ImportController extends BaseController {
errors: [{ type: 'IMPORTED_FILE_EXTENSION_INVALID' }],
});
}
return res.status(400).send({
errors: [{ type: error.errorType }],
});
}

next(error);
}
}
3 changes: 2 additions & 1 deletion packages/server/src/api/controllers/Import/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { ServiceError } from '@/exceptions';
export function allowSheetExtensions(req, file, cb) {
if (
file.mimetype !== 'text/csv' &&
file.mimetype !== 'application/vnd.ms-excel'
file.mimetype !== 'application/vnd.ms-excel' &&
file.mimetype !== 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
) {
cb(new ServiceError('IMPORTED_FILE_EXTENSION_INVALID'));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exports.up = function (knex) {
table.string('resource');
table.json('columns');
table.json('mapping');
table.json('params');
table.timestamps();
});
};
Expand Down
39 changes: 29 additions & 10 deletions packages/server/src/interfaces/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,40 @@ export interface IModelMetaFieldCommon {
fieldType: IModelColumnType;
customQuery?: Function;
required?: boolean;
importHint?: string;
order?: number;
unique?: number;
}

export interface IModelMetaFieldNumber {
fieldType: 'number';
export interface IModelMetaFieldText {
fieldType: 'text';
minLength?: number;
maxLength?: number;
}

export interface IModelMetaFieldOther {
fieldType: 'text' | 'boolean';
export interface IModelMetaFieldBoolean {
fieldType: 'boolean';
}
export interface IModelMetaFieldNumber {
fieldType: 'number';
min?: number;
max?: number;
}
export interface IModelMetaFieldDate {
fieldType: 'date';
}
export interface IModelMetaFieldUrl {
fieldType: 'url';
}

export type IModelMetaField = IModelMetaFieldCommon &
(IModelMetaFieldOther | IModelMetaEnumerationField | IModelMetaRelationField);
(
| IModelMetaFieldText
| IModelMetaFieldNumber
| IModelMetaFieldBoolean
| IModelMetaFieldDate
| IModelMetaFieldUrl
| IModelMetaEnumerationField
| IModelMetaRelationField
);

export interface IModelMetaEnumerationOption {
key: string;
Expand All @@ -71,9 +91,8 @@ export interface IModelMetaRelationEnumerationField {
relationEntityKey: string;
}

export type IModelMetaRelationField = IModelMetaRelationFieldCommon & (
IModelMetaRelationEnumerationField
);
export type IModelMetaRelationField = IModelMetaRelationFieldCommon &
IModelMetaRelationEnumerationField;

export interface IModelMeta {
defaultFilterField: string;
Expand Down
Loading

0 comments on commit d4ef1e5

Please sign in to comment.