feat: refactoring middlewares to typescript.

This commit is contained in:
Ahmed Bouhuolia
2020-09-06 23:36:37 +02:00
parent df0f842681
commit d3870974c0
17 changed files with 97 additions and 56 deletions

View File

@@ -3,7 +3,6 @@ import TenancyService from '@/services/Tenancy/TenancyService';
import { ServiceError } from '@/exceptions';
import { IAccountDTO, IAccount } from '@/interfaces';
import { difference } from 'lodash';
import { tenant } from 'config/config';
@Service()
export default class AccountsService {
@@ -137,6 +136,7 @@ export default class AccountsService {
public async newAccount(tenantId: number, accountDTO: IAccountDTO) {
const { Account } = this.tenancy.models(tenantId);
// Validate the account code uniquiness.
if (accountDTO.code) {
await this.isAccountCodeUniqueOrThrowError(tenantId, accountDTO.code);
}

View File

@@ -126,7 +126,7 @@ export default class AuthenticationService {
this.logger.info('[register] Someone trying to register.');
await this.validateEmailAndPhoneUniqiness(registerDTO);
this.logger.info('[register] Creating a new tenant org.')
this.logger.info('[register] Creating a new tenant organization.')
const tenant = await this.newTenantOrganization();
this.logger.info('[register] Trying hashing the password.')

View File

@@ -3,7 +3,6 @@ import TenancyService from '@/services/Tenancy/TenancyService';
import { SystemUser } from "@/system/models";
import { ServiceError, ServiceErrors } from "@/exceptions";
import { ISystemUser, ISystemUserDTO } from "@/interfaces";
import { ISystemUser } from "src/interfaces";
@Service()
export default class UsersService {
@@ -20,9 +19,9 @@ export default class UsersService {
async editUser(tenantId: number, userId: number, userDTO: ISystemUserDTO): Promise<ISystemUser> {
const foundUsers = await SystemUser.query()
.whereNot('id', userId)
.andWhere((q) => {
q.where('email', userDTO.email);
q.orWhere('phone_number', userDTO.phoneNumber);
.andWhere((query) => {
query.where('email', userDTO.email);
query.orWhere('phone_number', userDTO.phoneNumber);
})
.where('tenant_id', tenantId);